Skip to content

Implicit Result wrapping drops an owned tail payload before returning it #1169

Closed

Description

@ehartford

Implicit Ok wrapping frees an owned tail-expression payload while returning it. This was exposed while implementing the source-manifest parser for #1166.

Spec §4.9 requires a Result[T, E] function's successful final T to become Ok(T); ownership must transfer with that value.

Reduced by with reduce --contains 'assertion failed':

fn scalar(text: &str) -> Result[str, str]:
    let value = text.trim()
    if value[0] != 34:
        value.slice(0, value.len()).trim().clone()
    else:
        value.clone()
fn main:
    let first = scalar("sources").unwrap()
    let second = scalar("changed").unwrap()
    assert(first == "sources")

Current release compiler at 5dc78b6: run --debug-alloc exits 134 on the assertion. With allocator reuse disabled, the full source-manifest parser's assertions pass, confirming stale returned storage; this is diagnostic evidence, not an adopted workaround.

Instruction-level proof: the original parser's allocator trap on payload 4295426960, free hit 1, stops in source_yaml_scalar at its with_str_free_drop_origin call (0x100000be0). The function retains that same payload in return registers and writes it into Ok after the free. The reduced MIR likewise moves _9 into Ok, then drops _9.

LLDB on the compiler stops in lower_fn_with_sig + 6224 (0x100705d90), the MirBody.push_stmt call building the implicit Ok: span=176, the reduced scalar function's end. src/MirLower.w's implicit wrapping branch appends the aggregate assignment and replaces result without calling consume_moved_operand for its payload. The body-level temporary frame then drops the still-registered join temporary. Other aggregate construction paths already register this ownership transfer.

The fix is to consume the wrapped operand using the existing transfer mechanism before overwriting result, preserving resets, cancellation, and moved-state bookkeeping for every owned payload type. No parser clone workaround or spec change.

Evidence under out/with-get-investigation/: conan-source-data-first-free-lldb.log, conan-source-data-scalar-disassembly.log, result-branch-mir.log, result-tail-wrap-live-lldb.log, result-branch-reduce.log. Before-change audits: 15 move cells pass, 136 drop cells pass.

Activity

  1. added 3 commits that reference this issue on Sep 18, 2026
    3d5de2c
    0a8c291
    d90d104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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