Repository navigation
validate-ownership rejects vacated payloads and moves through references; variant-payload moves are reset-on-move; a downcast place has no type (#1394, #1381, #1415) - #1425
Conversation
7adefe8 to
ee4e2e4
Compare
|
Batch battery X2 (seed-driven, NEW seed, with :drop-audit/:move-audit) on main 977e667 + #1404 → #1418 → #1419 → #1425 (head ee4e2e4, including the #1404/#1418 join-arm merge resolution): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. #1424's four repros run clean on this build. Branches hold exactly the tested chain; merge in order #1404, #1418, #1419, #1425 — then batch Y (#1405 … #1360), then #1428. |
ee4e2e4 to
5259626
Compare
|
Main moved (#1397 merged, 04e4934) after X2's green and conflicted in MirLower (both added a lowering-state field next to each other: pattern_bind_mut / pattern_move_log). Rebased the X2 chain onto main keeping both; because #1397 changes let-else pattern lowering and this PR changes pattern move tracking, re-battery with audits now (with #1428's fixture on top). Draft until green. |
5259626 to
ace3b38
Compare
|
Battery (seed-driven, new seed, with :drop-audit/:move-audit) on main 05b674e (incl. batch Y) + #1418 → #1419 → #1425 → #1428 (head eea9017): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds — including #1422's da_option_filter_observes_payload, so this clears main's #1424 red), :test-green ok, :last-green ok. Merges cleanly into main 1c76062. Now GitHub stack #1437 (gh stack link); merge the whole stack: |
… reset is rejected (#1394) The ownership validator passed #1363's MIR: `_8 = move _6<as v0>.f0` on the success arm, then `drop(_6)` at the join, where the enum drop glue freed the payload the result owned. Two causes: - mark_place joined Moved into the base on a sub-place move, so the base read Maybe and the vacated payload read the same Maybe as its parent; nothing distinguished a partial move from a conditional whole move. A sub-place move now leaves the base's state alone. - validate_ownership_body checked a Drop only for Uninit/MaybeGarbage. It now rejects a drop of a place with a drop-bearing sub-place more moved than the place itself (Moved under Init/Maybe, Maybe under Init): a path reaching the drop vacated it and nothing reset it (§2.5.1). MirCore has no Sema, so lowering records in the module every type a body moves out of a sub-place that has drop glue (sema_moved_drop_types); the validator looks the vacated sub-place up by the typed validator's own place type.
…places (#1394) Two producers lowered an observation as a move. The stricter validate-ownership rejected both, each where an owner drops whole after the "move" of its field: - `v.text == s` with `s: &str` fell outside the str-vs-str observer path and lowered the owned side as a value: `binop(eq, move _2.text, copy _6)` (ComptimeEvaluator.match_pattern in the compiler itself). An owned side compared with a `&str` now observes too. - An f-string interpolant `{u.name}` lowered as `move _1.name` into fmt_buf_write_str, which (like fmt_to_str and every FmtBuffer writer) reads the value and leaves it to its owner (#761). A moved place operand becomes a copy: formatting observes. Nothing reset either "moved" field, so the MIR claimed the owner's drop freed a value it no longer owned. validate-all: 11 corpus files (idiomatic, service x3, email, ephemerality x2, issue65 x2, named arguments, dump_typed_top_level_string_sidecar_key) and src/main.w now pass.
…h LLVM types (#1381) `with analyze audit:all` failed on every `??`/`unwrap_or`: violation: place 6 in main: projection lowers to LLVM type kind 10 but its MIR type 339 (Option[i32]) is kind 10; ... lower_double_question, lower_unwrap_or_method and most Option/Result combinators built new_downcast_place(value_place, idx, value_ty), typing the downcast place as the whole enum, while codegen (mir_place_projected_type) projects PK_DOWNCAST to the variant's payload struct; match lowering passed 0. One rule now: a downcast place has no type. It is only ever the base of a payload field place, which carries the payload's type. new_downcast_place takes no type (every producer gets the rule), and the typed validator's place walk yields none for a place that ends in a downcast, so a downcast used as a value is reported instead of read as the enum. The audit message compared type identity while printing only kinds; it now prints both LLVM types (wl_print_type, LLVMPrintTypeToString).
…match guard gives its bindings back (#1394) consume_moved_operand registered a move only for a whole local or a pure field path: place_field_projection_count is -1 through PK_DOWNCAST, so a move out of a variant payload registered no reset-on-move (§2.5.1). Every carrier eliminator had to hand-roll the subject's ownership, and the ones that did not left the enum's drop glue to free the payload the result owned. The stricter validate-ownership found them across the corpus: unwrap_or (#1363), Result.map/map_err/or_else's passthrough arm, .context/.with_context, ?., custom Try, sequence/traverse. Under WITH_DEBUG_ALLOC=1 (origin/main stage2) `bad().map((x) => x + 1)` on an Err(Vec) reports DOUBLE FREE first_drop=__drop_enum second_drop= __drop_struct_96. A payload move now queues its blank with the block it happened in. A payload slot overlaps the other variants' payloads, so the blank has to land on the moving path while the enum still holds that variant, never at a statement flush that may sit after a join: it is emitted before the moving block's terminator (carried across a call into the call's continuation), and before an earlier drop or overwrite of the same base in that block. ok()/err() drop their hand-rolled blank for it; lower_context_error_operand now consumes the moved source. A failed match guard dropped the arm's bindings, freeing the payload the next arm then bound again (Some(v) if .. => .., Some(v) => ..: DOUBLE FREE on origin/main). With payloads blanked the next arm would bind the blank instead. Pattern bindings now log what they move out of the subject, and the guard-fail path moves it back and blanks the binding. Evidence (stage2 from this branch): - #1363 repro: validate-all ok; `_8 = move _6<as v0>.f0; _6<as v0>.f0 = const zst` on the success arm, then drop(_6) frees only an Err payload. - validate-all over test/, examples/, lib/std (2138 files): all 24 files the new rule flagged pass; no file newly fails; src/main.w ok. - test/debug_alloc/da_variant_payload_move_blanked.w: map, err(), ?., guarded payload and whole bindings — DOUBLE FREE on origin/main for map, ?., both guards; leak count=0 here. - build.w deep-debug-tool-tests: audit:all on a ??/unwrap_or/map fixture must report violations=0.
`r.context(msg)` lowered the message as a statement temp and, on the Err arm, moved it into the ContextError; the statement flush then dropped the temp as well. With #1398's debug-allocator fix (the str free path asks the ledger), `root().context(heap_message())?` on an Err reports DOUBLE FREE addr=... size=64 first_drop=drop#struct __drop_struct_16 second_drop=drop#struct __drop_struct_434 The call now takes the message into its own local before the branch: the Err arm moves it into the ContextError, the Ok arm drops it (`context-message-unused`). with_context is unchanged (its message is built inside the Err arm). test/debug_alloc/da_variant_payload_move_blanked.w covers both arms: the Ok arm leaks if the drop is missing (leak count), the Err arm double-frees under a runtime that reports str double frees.
…ce is rejected (#1415) Before #1395's Sema fix, `let v = if c: self.p else: Vec.new()` in a `&self` method lowered the join arm as `_4 = move _1.*.p`, a move out of the shared receiver's pointee; `--validate-all` said ok and the debug allocator reported the double free (rc=134). A reference never owns its pointee: the frame can neither own the moved value nor reset its source, so the referent's owner and the destination both free it (§2.2 D32: a field vacates only through a `var` base or a `mut fn` receiver, whose place carries no deref — `_2 = move _1.p`; D22: a view never becomes an owner). validate_ownership_body now rejects an OK_MOVE, in any statement or terminator, of a drop-bearing place whose projections dereference a TY_REF. A raw pointer's pointee (the unsafe tier) and a Box's are owned through the pointer and stay legal. Evidence (stage2 from this branch, repro from #1415, origin/main lowering): error: validate-ownership failed: fn sym770 stmt3 span=72: moves out of _1.*.f769 through a reference, which does not own it (§2.2 D32, D22) The parent commit's stage2 says `validate-all: ok` on the same MIR; `run --debug-alloc` on it: DOUBLE FREE ... second_drop=drop#struct __drop_struct_135. src/main.w: validate-all ok. test/internals/mir_move_through_reference_test.w pins the rule (move through &T rejected; copy through &T, move through *T, and a type with no drop glue accepted).
ace3b38 to
d3ceefc
Compare
|
Stack #1466 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 1c76062 + #1418 → #1419 → #1425 → #1428 → #1449 → #1377 → #1459 → #1460 → #1461 → #1462 (head cf36211, including the #1449/#1462 Codegen resolution and the fixed #1460): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Each branch holds exactly its tested commits on the layer below. Merge the whole stack: |
…1424) (#1428) Fails (DOUBLE FREE) on #1398's build, passes on #1425's reset-on-move (batch X2). Lands after X2. Co-authored-by: Eric Hartford <[email protected]>
Fixes #1394, Fixes #1381, Fixes #1415.
Two tools stayed silent over real double frees, and one audit failed on every
??/unwrap_orbecause MIR and codegen disagreed about a place's type. This PR makes the tools report the defects, then fixes the defects they report.Root causes
#1394, tool.
validate_ownership_body(src/MirCore.w) checked aDroponly forUninit/MaybeGarbage. It also could not have seen #1363's shape:MirDropStateMap.mark_placejoinedMovedinto the base local on a sub-place move. After_8 = move _6<as v0>.f0on one arm, both_6and_6<as v0>.f0readMaybeat the join, and nothing told a partial move apart from a conditional whole move.MovedunderInitorMaybe, orMaybeunderInit.MirModule.sema_moved_drop_types).#1394, lowering.
consume_moved_operand(src/MirLower.w) registered moves only for a whole local or a pure field path.place_field_projection_countreturns -1 throughPK_DOWNCAST, so a payload move registered no reset-on-move (§2.5.1). A payload move now queues its blank, tagged with its block. The blank lands before the moving block's terminator (it is carried across a call into the call's continuation), and before any earlier drop or overwrite of the same base. It never lands at a statement flush that may sit after a join: a payload slot overlaps the other variants' payloads.#1381. Most producers typed a downcast place as the whole enum (
new_downcast_place(value_place, idx, value_ty)). Match passed 0, and codegen projectsPK_DOWNCASTto the variant's payload struct. The one rule now: a downcast place has no type.new_downcast_place(base, idx)takes none, and the typed walk yields none for a place that ends in a downcast. The audit message printed only kinds ("kind 10 but ... kind 10"). It now prints both LLVM types.#1415. Nothing rejected
_4 = move _1.*.pthrough&self. The validator now rejects anOK_MOVE, in any statement or terminator, of a drop-bearing place whose projections dereference aTY_REF. A reference never owns its pointee. Amut fnreceiver's vacate is_1.p, with no deref, and stays legal. So do a raw pointer's pointee and a Box's.What the stricter validator found (corpus: test/, examples/, lib/std; origin/main lowering)
It flagged 24 files, and each one is a real defect.
unwrap_or(Result[str, E].unwrap_or returns a str with the payload's length and a bad data pointer (segfault / garbage) #1363) and the d22 default eliminatorsResult.map/map_err/or_elsepassthrough arms.context/.with_context?.optional chainingTrybad().map((x) => x + 1)onErr(Vec)under the debug allocator:DOUBLE FREE ... first_drop=__drop_enum second_drop=__drop_struct_96v.text == swiths: &strlowered asbinop(eq, move _2.text, ...), in the compiler's ownComptimeEvaluator.match_pattern.{u.name}lowered asmove _1.nameintofmt_buf_write_str, which only reads it (D30 implementation: retire the internal runtime ABI — runtime compiles in-unit; rt objects only a keyed cache; boundaries speak C #761).Two more defects in the same class turned up while fixing these. The validator cannot see either one: the drop lattice cannot yet tell maybe-moved from maybe-uninit (#1414).
Some(v) if .. => .., Some(v) => ..gives DOUBLE FREE on origin/main. With payloads now blanked, the next arm would have bound the blank. Pattern bindings now log their moves, and the guard-fail path moves them back.Result.context(msg)moved the message into the ContextError on the Err arm, and the statement flush dropped it too. With unwrap_or / unwrap_or_else / flatten no longer free the payload they return; closures drop owned params; debug allocator sees str double frees (#1363) #1398's runtime this is a DOUBLE FREE, size=64. The call now owns the message: the Err arm moves it and the Ok arm drops it.Validator verdicts
validate-all: okdrop of _6 frees _6<as v0>.f0, which a path reaching it moved out (Maybe) and nothing reset (§2.5.1)fix-1363-unwrap-or-strmerged on the validator commit)validate-all: okvalidate-all: ok; MIR_8 = move _6<as v0>.f0; _6<as v0>.f0 = const zston the success armvalidate-all: ok(debug allocator: DOUBLE FREE)moves out of _1.*.f769 through a reference, which does not own it (§2.2 D32, D22)cannot take ownership of a non-Copy field through a borrow)o ?? 0,analyze audit:allviolation: place 6 ... kind 10 but ... kind 10violations=0 okEvidence (iterate tier; stage2 built from this branch, rebased on f008ef3)
src/main.w: ok.analyze audit:allover the corpus (pre-rebase build): "projection lowers" violations dropped from 75 to 3. The 3 left are Range's bool field, i8 against i1, filed as audit:codegen: Range's bool field projects as i8 but MIR types it bool (i1) #1413.?., guarded payload and whole bindings, context on both arms. On origin/main, map,?.and both guards report DOUBLE FREE.audit:allon a??/unwrap_or/mapfixture must reportviolations=0.new_downcast_placeloses its type argument on 5 lines inside unwrap_or / unwrap_or_else / flatten no longer free the payload they return; closures drop owned params; debug allocator sees str double frees (#1363) #1398's functions; git merges them cleanly.da_str_double_free_reportedstill reports its intended DOUBLE FREE), and so do D32: a field reaching an owned if/match/?? join, block tail or break value is an implicit field move (#1395) #1416's behavior tests.This is an ownership and drop-scheduling change, so batch it alone, with
:drop-auditand:move-audit. Full battery not run: this PR stays a draft until it is.Filed along the way