agentleFS
christopherkaranichristopherkarani/rv/.claude/skills/swift-value-semantics/SKILL.md

swift-value-semantics

Skill8 starsChanged 5 days agoApache-2.0View on GitHub

Use when Swift code has copying, mutation, identity, copy-on-write, large aggregates, or a struct-versus-class decision. Do not infer that every struct is cheap or every class is shared mutable state by accident.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep mutation APIs explicit.

    line 16
  2. Distinctive:

    Test aliasing, independent mutation, equality/hash behavior, and performance at realistic sizes.

    line 17
  3. Distinctive:

    Read references/value-semantics-guide.md for the aliasing matrix.

    line 19
  4. Distinctive:

    Do not add a class solely to share a cache or avoid a copy without measuring and documenting identity.

    line 25
  5. Very specific:

    If duplication is illegal rather than merely expensive, use swift-ownership and model noncopyability.

    line 26

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Swift value semantics

Choose semantics first, representation second. A value type should be substitutable by its value; a reference type should make identity and shared mutation intentional.

Procedure

  1. State whether callers expect independent values, shared identity, stable identity, or unique ownership. Check equality, hashing, caching, and mutation expectations.
  2. Inspect stored members and their semantics. A struct containing references may still share mutable state; a class can expose a value-like façade but must enforce it.
  3. Choose struct/enum, class, actor, or noncopyable value based on the invariant—not on a blanket style rule.
  4. For large copyable values, measure before changing representation. Use copy-on-write only when aliasing and mutation frequency justify its storage and synchronization complexity.
  5. Keep mutation APIs explicit. Check exclusivity, nested mutation, thread safety, and whether a getter unexpectedly copies or aliases data.
  6. Test aliasing, independent mutation, equality/hash behavior, and performance at realistic sizes.

Read references/value-semantics-guide.md for the aliasing matrix.

Guardrails

  • let prevents reassignment of a value binding; it does not make referenced objects immutable.
  • Copy-on-write is a semantic promise plus an optimization, not a substitute for synchronization.
  • Do not add a class solely to share a cache or avoid a copy without measuring and documenting identity.
  • If duplication is illegal rather than merely expensive, use swift-ownership and model noncopyability. On Swift 6.4, unique growable storage is UniqueArray (Swift module), not a COW Array of boxes. RigidArray did not ship. Load swift-64-span-inlinearray.

Completion contract

Report the intended aliasing/identity semantics, representation tradeoff, measured or reasoned copy cost, and tests that prove independent or shared mutation as intended.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.