Skip to content

Compiler: Place-based ownership & LSP move/copy inlays - #20

Merged
CierCier merged 23 commits into
mainfrom
move-semantics
Aug 28, 2026
Merged

CierCier merged 23 commits into
mainfrom
move-semantics

Conversation

@CierCier

@CierCier CierCier commented Aug 28, 2026 •

Copy link
Copy Markdown
Owner

Compiler: Place-based ownership & LSP move/copy inlays

Stack for deterministic Rust-like ownership with Silver-natural syntax. Keeps move x + i32 → copy / String → move implicit Copy (per grilling) and hybrid verbosity.

Pipeline (AGENTS.md §4)

TypeCheck → Ownership (Place/MovePath/Init/TypeProperties/Borrow/Drop) → Monomorph

  • Place {local, projections} (semantic/place.rs) with is_prefix_of/overlaps (field x.a vs x.b disjoint, v overlaps v[i], v[i] vs v[j] conservative for Index)
  • MovePathTree + InitState (move_path.rs / init.rs) — read/move_out/initialize/copy_from primitives for definite initialization
  • TypeProperties {is_copy, needs_drop} (type_properties.rs) — primitives/T*/all-Copy struct = Copy, String/Vec/HashMap/HashSet/Deque = Move; single source of truth for typeck/move_check/codegen
  • Borrow {place, kind} (borrow_check.rs) via places_overlap
  • Drop elaboration (drop_elaborate.rs) — hybrid flags: Init→direct, Uninit→elided, Partial→guard

Language & stdlib

  • True field-granular String b = move x.a leaves x.b live; x.a = make() reinits (Place overlap, MovePathTree)
  • Index places for move v[i] (conservative) + Deref
  • Containers (Vec/Deque/HashMap/HashSet) growth/rehash/pop/remove/drain/into_iter via move tmp workaround for typeck move-on-Index restriction; Copy → bitwise copy, Move → transfer
  • Diagnostics: note_value_moved_here/use_of_moved_field with Place paths; iterator iter (borrow) vs into_iter (consume) ownership contract

LSP

symbol_index::MoveHint + inlay_hints: implicit move/copy before every place let/assign/return/call-arg (String a = b → move before b, i64 y = x → copy before x; explicit move excluded). Updated to let T i style (T before i, not : T) to match native T i definitions (let p = &z → let i32* p).

Docs

  • AGENTS.md (§2, §4, §6 invariants 8-9, §7 inlay hints) kept agent-only short (~305 lines, <400)
  • SYNTAX.md §8.1 implicit Copy vs Move + Place granularity with verified examples
  • Removed superseded docs/borrow-checker/* + docs/runtime-migration.md + plan/runtime-migration.md/TODO.md plan files (already pushed as separate cleanup 3909664)

Verification

cargo check -p agc -p aglsp clean; cargo test -p agc --lib 478 passed, cargo test -p aglsp 17 passed (including new implicit_move_and_copy_hints).

Commits

13 on move-semantics from b2dcb44:

  • docs: freeze ownership/move/borrow/drop semantics (Phase 0)
  • compiler: introduce Place (Phase 1)
  • compiler: add Place overlap (Phase 2)
  • compiler: add MovePath/MovePathTree (Phase 3)
  • compiler: add definite-init primitives (Phase 4)
  • compiler: centralize Copy/needs_drop (Phase 5)
  • compiler: pipeline split + hybrid drop + Place Borrow (Phase 6-8)
  • compiler: true move-out via Place+MovePathTree (Phase 9)
  • compiler+stdlib: Index places + ownership-aware containers (Phase 10-11)
  • stdlib+compiler: polish diagnostics/iterator (Phase 12)
  • lsp: implicit move/copy inlays
  • docs: update AGENTS/SYNTAX, remove plan docs
  • lsp: let inlay as T i

Greptile Summary

The PR introduces place-based move and initialization tracking, ownership-aware collection operations, and LSP move/copy inlays.

  • Adds structural Place, MovePathTree, initialization, type-property, borrow, and drop-elaboration components.
  • Extends move checking to fields, indexes, dereferences, consuming receivers, and reinitialization.
  • Updates collection transfer operations, ownership documentation, diagnostics, and editor inlay hints.

Confidence Score: 4/5

The PR is not yet safe to merge because partial reinitialization can make a moved aggregate sibling appear live.

Reinitializing the only tracked child of an invalidated subtree promotes the parent to Initialized, after which absent sibling nodes are treated as live and stale owned storage can pass move checking.

Files Needing Attention: bin/agc/src/semantic/init.rs and bin/agc/src/semantic/move_check.rs

Important Files Changed

Filename Overview
bin/agc/src/semantic/init.rs Adds definite-initialization transitions, but child reinitialization can incorrectly revive an entire moved subtree.
bin/agc/src/semantic/move_check.rs Integrates Place and MovePathTree tracking for field, index, dereference, call, and assignment ownership flows.
bin/agc/src/semantic/place.rs Defines structural places and conservative projection overlap semantics.
bin/agc/src/semantic/type_properties.rs Adds currently non-authoritative Copy and drop-property query scaffolding.
bin/agc/src/symbol_index.rs Records implicit move and copy locations for editor tooling.
bin/aglsp/src/inlay_hints.rs Renders compiler-derived move/copy and updated declaration-type inlays.
std/mem/vec.ag Updates owned-element transfers and consuming iteration to use explicit move workarounds.
SYNTAX.md Documents implicit Copy/Move behavior and conservative indexed-place semantics.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Typed AST] --> B[Place extraction]
  B --> C[MovePathTree transitions]
  C --> D{Initialized?}
  D -->|Yes| E[Borrow and move checks pass]
  D -->|No| F[Move diagnostic]
  E --> G[Code generation and runtime drop flags]
  B --> H[Symbol index]
  H --> I[LSP move/copy inlays]
Loading

Reviews (8): Last reviewed commit: "remove old plan files" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

Document baseline without behavior change:
- ownership-and-moves.md updated with drop-flag stack, explicit move, string-path tracking
- borrow-checking.md new: origins, Shared/Mut, NLL, overlap via root+path
- drop-semantics.md new: per-var/per-field flags, defer stack, field/enum cascade, Bug C
- initialization.md new: move→uninit, assign→init, partial moves, control-flow
- copy-semantics.md new: is_copy/needs_drop split, POD vs owned
- move-semantics-roadmap.md new: 16 phases + PR1-6 + DoD User example
Baseline: cargo test -p agc 420 passed.
Place {local, projections} with Field/TupleField/Index/Deref,
helpers root/field/deref/parent/push_projection/from_slice and
tests. No semantic change — adds parallel infrastructure, marks
migration TODOs in move_check/borrow_check string-path tracking.
is_prefix_of / overlaps / places_overlap with truth table,
shared infrastructure for borrow/move/init/drop.
Tree for x { a { b, c }, d } with InitState,
prepares replacement of string-based moved_fields.
init.rs with read/move_out/initialize/copy_from on MovePathTree
using Place overlap; wiring sketch in move_check transition helper.
TypeProperties {is_copy, needs_drop} for bool/int/float/ptr
and all-Copy structs vs String/Vec/HashMap etc, with TODOs to
centralize per-subsystem heuristics. Keep implicit Copy.
DropElaborate skeleton (MovePathTree -> Vec<PlaceToDrop>),
hybrid flag elimination plan, Borrow {place, kind} with
places_overlap helpers. No semantic change yet.
Field-granular move tracking using Place overlap:
String y = move x.a leaves x.b live, move x.a then x.a = make()
reinitializes, Copy types via copy_from, Double-move errors.
…0-11)

Place::Index with conservative overlap (v vs v[i], v[i] vs v[j]),
borrow/move wired for Index/Deref. Vec/Deque/HashMap/HashSet
growth/rehash/pop/remove/drain/into_iter now move via tmp
workaround for typeck Index restriction; old POD memcpy kept as
correct fallback. Fixes parse and dwarf gen.
…e 12)

note_value_moved_here / use_of_moved_field / note_previous_borrow_of
with Place paths, iter vs into_iter ownership contract.
Extend SymbolIndex with MoveHint (span + Move/Copy) populated by
Walker via type_of + is_copy_type_str heuristic (Copy primitives/ptr
vs String/Vec/HashMap/HashSet/Deque/Box/Rc/File etc) for let
initializers, assignments, returns and call args where source is a
place (Identifier/FieldAccess/Index) and not explicit move. Render as
'move'/'copy' inlay hints before the source expression.
Copilot AI lite review requested due to automatic review settings August 28, 2026 14:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread std/mem/vec.ag
/// Consumes the Vec, moving its buffer into the iterator.
/// `Self self` (by value) — not `&Self` — so `move self.data` drains and
/// leaves `self` moved-from (null/0). Iterator owns and frees the buffer.
VecIter<T> into_iter(Vec<T> self) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Field receivers remain live

When a consuming iterator is called on an owned collection field such as holder.items.into_iter(), codegen transfers the field and clears its drop flag, but the move checker recognizes value receivers only when the receiver is a bare identifier. It therefore accepts subsequent access to the consumed field, allowing stale or freed backing storage to be read.

Knowledge Base Used:

Comment thread SYNTAX.md Resolved
Comment thread bin/agc/src/semantic/move_check.rs Resolved
@CierCier
CierCier merged commit 4db2c03 into main Aug 28, 2026
2 checks passed
Comment on lines +163 to +168
// But tests expect parent with single child that was moved then
// reinit to become Initialized again, so handle that:
if !node.children.is_empty() {
// single-child case: after reinit of that sole child, parent
// should return to Initialized (no other uninit siblings).
node.state = InitState::Initialized;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Sibling state revived after move

When a nested owned aggregate is moved and then its only tracked child is reassigned, this branch marks the entire parent initialized. An untracked sibling is consequently treated as live, allowing stale or freed owned storage to pass move checking and reach code generation.

Knowledge Base Used: Semantic analysis and ownership safety

@CierCier
CierCier deleted the move-semantics branch September 6, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants