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
Moving a Vec out of a global and reassigning it double-frees: safe code, no diagnostic #1242
Silent unsoundness in safe code. Sema accepts the program; the debug allocator reports a double free.
var g_items: Vec[str] = Vec.new()
fn note(s: &str): g_items.push(s.clone())
fn take -> Vec[str]:
let taken = g_items // moves out of a global?
g_items = Vec.new() // reassigns it
taken
fn main:
note("a")
note("b")
let got = take()
print(f"{got.len()} {g_items.len()}")
note("c")
let again = take()
print(f"{again.len()} {g_items.len()}")
$ with run --debug-alloc gmove.w
2 0
1 0
debug-alloc: DOUBLE FREE addr=… size=128 origin=Vec first_drop=drop#struct __drop_struct_193 second_drop=drop#struct __drop_struct_193
let taken = g_items byte-copies the Vec header out of the global instead of moving it (or being rejected): the global keeps the old buffer, the reassignment drops it, and taken drops it again. §2.3: transport is not duplication; a non-Copy value never gets a second live owner.
Expected: either reject moving out of a global ("a global always holds a value; clone it, or swap in a replacement") or lower it as a true move that leaves the global uninitialized until the reassignment, with the flow check that it is reassigned before any read. The first is the conservative reading.
Found writing ci_print_take_unknowns in src/CiPrint.w (the drain now copies out and clears). Ownership analysis: fix alone in its batch with the drop audit.
Activity
The migrator refuses a function it cannot render instead of writing a…
Specification §9.1c: a global always holds a value, never moved out o…
A global is never moved out of: transfer out of a non-const global is…
`let s: &T = place` borrows the place instead of moving it (#1244, §3…