Repository navigation
Compiler: Place-based ownership & LSP move/copy inlays - #20
Conversation
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.
| /// 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) { |
There was a problem hiding this comment.
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:
| // 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; |
There was a problem hiding this comment.
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
Compiler: Place-based ownership & LSP move/copy inlays
Stack for deterministic Rust-like ownership with Silver-natural syntax. Keeps
move x+i32 → copy/String → moveimplicit Copy (per grilling) and hybrid verbosity.Pipeline (AGENTS.md §4)
TypeCheck → Ownership (Place/MovePath/Init/TypeProperties/Borrow/Drop) → Monomorph{local, projections}(semantic/place.rs) withis_prefix_of/overlaps(fieldx.avsx.bdisjoint,voverlapsv[i],v[i]vsv[j]conservative forIndex)move_path.rs/init.rs) —read/move_out/initialize/copy_fromprimitives for definite initialization{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{place, kind}(borrow_check.rs) viaplaces_overlapdrop_elaborate.rs) — hybrid flags:Init→direct,Uninit→elided,Partial→guardLanguage & stdlib
String b = move x.aleavesx.blive;x.a = make()reinits (Place overlap,MovePathTree)Indexplaces formove v[i](conservative) +DerefVec/Deque/HashMap/HashSet) growth/rehash/pop/remove/drain/into_iter viamove tmpworkaround fortypeckmove-on-Indexrestriction;Copy→ bitwise copy,Move→ transfernote_value_moved_here/use_of_moved_fieldwithPlacepaths; iteratoriter(borrow) vsinto_iter(consume) ownership contractLSP
symbol_index::MoveHint+inlay_hints: implicitmove/copybefore every placelet/assign/return/call-arg (String a = b→movebeforeb,i64 y = x→copybeforex; explicitmoveexcluded). Updated tolet T istyle (Tbeforei, not: T) to match nativeT idefinitions (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 examplesdocs/borrow-checker/*+docs/runtime-migration.md+plan/runtime-migration.md/TODO.mdplan files (already pushed as separate cleanup3909664)Verification
cargo check -p agc -p aglspclean;cargo test -p agc --lib478 passed,cargo test -p aglsp17 passed (including newimplicit_move_and_copy_hints).Commits
13 on
move-semanticsfromb2dcb44:T iGreptile Summary
The PR introduces place-based move and initialization tracking, ownership-aware collection operations, and LSP move/copy inlays.
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
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]Reviews (8): Last reviewed commit: "remove old plan files" | Re-trigger Greptile
Context used: