You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
validate-ownership: str as []u8 lowers as a move of the str, so a second cast is "two owners free one value" (runtime drops once, leak count=0) #1719
Spec: §2.5.1 (one owner), §3.8 (a view observes; a cast to []u8 does not transfer the str).
Repro (any current compiler; also the seed v0.15.2.1, so pre-existing):
fn main:
let input = "abc".clone()
let a = input as []u8
let b = input as []u8
print(a.len() + b.len())
$ with check cast2.w --validate-all
error: validate-all failed: ownership MIR: fn sym803 stmt10 span=77: move of _1, which a path reaching it already moved out (Moved) and nothing re-initialized: two owners free one value (§2.5.1)
$ with run --debug-alloc cast2.w
6
debug-alloc: leak count=0
Expected: the cast produces a view of input; MIR records no move, --validate-all passes. The program itself is right at runtime (one drop, no leak), so the MIR move record disagrees with what codegen does: the ownership validator reports a double move that the drop schedule does not act on. One of the two is wrong, and the validator is the one that stayed silent-in-reverse: it would flag every program that casts a str to bytes twice.
Where: MirLower.lower_cast (the str as []u8 deref path) emits a move operand for the str source. It should be a place/view read.
Found by the --validate-all sweep over test/behavior on PR #1718: test/behavior/behav_bzip2_facade_roundtrip.w (span 1421, input as []u8 twice) is the in-tree instance.
Activity
MIR: a cast reads its source — `s as []u8` twice is not a double move (…
Ownership: D72 liveness byte, D73 assignment-as-read, validator leak/…
MirLower: a cast through a reference reads what it names, through a d…
MirLower: a cast through a reference reads what it names, through a d…
MirLower: a cast through a reference reads what it names, through a d…
Language fixes: discarded results dropped, indentation, casts through…
Sema/MirLower/Codegen: a cast into or out of a distinct type moves an…
Distinct casts move or borrow (§4.5) and once parameters across bundl…