Skip to content

Collection literals free moved element temporaries before their collection #1122

Closed

Description

@ehartford

Owned elements of collection literals remain registered for temporary cleanup
after their storage transfers to the collection.

Minimal reproduction:

fn main:
    let word = "compiler".clone()
    let arguments: Vec[str] = [word.clone(), "build"]
    let other = "overwritten".clone()
    assert(arguments[0] == "compiler")

Expected: the literal owns its cloned element until the Vec is dropped.
Actual: the assertion fails with allocator reuse enabled. With
WITH_ALLOC_NO_REUSE=1 it passes, and --debug-alloc reports zero leaks. This is
a use-after-free, not a leak. It blocked the new stdlib-complexity build action:
argv[0]'s compiler path was reused for compile.stdout; exec returned 127.

Exact evidence:

  • Native LLDB stops in rt_free_with_drop_origin via
    with_str_free_drop_origin at rt_core.w:2731, from the literal's source line.
  • MIR bb2 transfers move _7 to __collection_literal, but bb3 still emits
    drop(_7) @ drop#9 scope-exit _7 before the next allocation.
  • LLDB MirBuilder.lower_collection_literal_call+124 enters new_call_args with
    operand IDs 7 and 8, without consume_moved_operand. Source
    src/MirLower.w:5302 omits the ownership handling used by ordinary calls.
  • The same helper constructs Vec/HashSet/HashMap literals, so the fix belongs
    there, not in the build action or allocator.

Spec basis: §4.3c collection literals and §2.5.1 reset-on-move.
Fix in progress: consume moved operands in the shared literal call helper;
native/debug-allocator coverage for dynamic strings and Drop-bearing elements.

The audit also silently accepts this repro (facts=11452, violations=0).
That missing intrinsic-ownership coverage needs a separate audit regression.
Local proof logs are under out/fnabi-validation/vec-literal-lowering-proof.txt,
vec-clone-free-site.txt, vec-clone-mir.txt, and complexity-action-proof.txt.
No workaround is being committed: the build action keeps collection literals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions