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.
In this repository18 other files it gives its agents.
- codebase-designSkill
- principle-type-system-disciplineSkill
- swift-64-concurrencySkill
- swift-adversarial-pr-reviewSkill
- swift-api-design-guidelinesSkill
- swift-concurrencySkill
- swift-evaluate-paritySkill
- swift-functional-architectureSkill
- swift-functional-coreSkill
- swift-hexagonal-spmSkill
- swift-hook-xpcSkill
- swift-pr-orchestrationSkill
- swift-protocol-boundariesSkill
- swift-pr-reviewSkill
- swift-systems-safetySkill
- swift-testing-proSkill
- swift-thermo-nuclear-reviewSkill
- swift-type-system-architectureSkill
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
- Distinctive: line 16
Keep mutation APIs explicit.
- Distinctive: line 17
Test aliasing, independent mutation, equality/hash behavior, and performance at realistic sizes.
- Distinctive: line 19
Read references/value-semantics-guide.md for the aliasing matrix.
- Distinctive: line 25
Do not add a class solely to share a cache or avoid a copy without measuring and documenting identity.
- Very specific: line 26
If duplication is illegal rather than merely expensive, use swift-ownership and model noncopyability.
≈ “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.
Files
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
- State whether callers expect independent values, shared identity, stable identity, or unique ownership. Check equality, hashing, caching, and mutation expectations.
- 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.
- Choose
struct/enum,class, actor, or noncopyable value based on the invariant—not on a blanket style rule. - For large copyable values, measure before changing representation. Use copy-on-write only when aliasing and mutation frequency justify its storage and synchronization complexity.
- Keep mutation APIs explicit. Check exclusivity, nested mutation, thread safety, and whether a getter unexpectedly copies or aliases data.
- Test aliasing, independent mutation, equality/hash behavior, and performance at realistic sizes.
Read references/value-semantics-guide.md for the aliasing matrix.
Guardrails
letprevents 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-ownershipand model noncopyability. On Swift 6.4, unique growable storage isUniqueArray(Swift module), not a COWArrayof boxes.RigidArraydid not ship. Loadswift-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.
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
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.

