Section 6: References, Ownership, and Borrowing¶
TECHSPEC-06 — Section 6 · Version 0.1 · Status: Initial Draft
Status: draft. This section is an Initial Draft (Section 57 is a Working Register). It describes intended or proposed behavior, not a finalized, implemented language rule. Do not treat examples here as normative.
1. Ownership Philosophy¶
Every mutable resource must have a clearly defined owner.
The language must prevent invalid memory access, conflicting modifications, and resource lifetime violations.
2. Ownership Rules¶
- Every owned value has one owner.
- Ownership transfers must be explicit.
- The previous owner cannot access a value after transferring ownership.
- Values must not be accessed after their lifetime ends.
- Resources must be released when their ownership ends.
3. References¶
References allow code to access values without transferring ownership.
The language supports:
- READ REF: Read-only reference.
- MUT REF: Mutable reference.
Examples:
LET accountRef: READ REF<Account> = BORROW account
LET accountMut: MUT REF<Account> = BORROW MUT account
4. Borrowing Rules¶
- Multiple read-only references may exist simultaneously.
- Only one mutable reference may exist at a time.
- Read-only and mutable references cannot conflict.
- References cannot outlive their original values.
- References cannot be used after their owner releases or transfers the value.
5. Resource Management¶
Resources include: - Memory allocations. - Files. - Database connections. - Network connections. - Locks. - Other externally managed resources.
Rules: - Resources must have defined lifetimes. - Resources must be released exactly once. - Cleanup must occur on normal returns and supported failure paths. - Resource ownership transfers must be explicit. - Failed operations must not leave resources in an invalid ownership state.
6. Compiler Responsibilities¶
The compiler must: - Track ownership. - Validate ownership transfers. - Track reference lifetimes. - Detect conflicting mutable access. - Reject dangling references. - Detect use-after-release. - Enforce resource cleanup requirements.
7. Design Goal¶
AI agents must not be able to introduce common memory-safety and resource-management errors through careless sharing, modification, or lifetime handling.
Source and related sections¶
Source file: TECHSPEC-6.md (preserved in source-original/LANG/). See the specification index, the glossary, and the cross-reference index.