Skip to content

MIR / Codegen (§14.6): consuming an owned resource inside an async: block double-drops it in the enclosing frame #3044

Closed

Description

@ehartford

Found via --debug-alloc and --dump-drop-plan while verifying #3038.

Minimal reproduction

use std.channel.chan

fn main:
    let (tx, rx) = chan[str](4)
    async scope s =>
        s.track(async:
            tx.send("hello")
            drop(tx)
        )
        s.track(async:
            for msg in rx:
                print(msg)
        )

Actual (--debug-alloc + --dump-drop-plan)

drop(tx) inside the async: block releases the Sender[str] ($anonymous$...: drop(_1) @ std.drop _1), and main still drops _3 (tx) at scope exit (main: state_before=Init action=drop text="drop(_3)"), panicking with invalid free in with_channel_release_sender.

Root cause

Spec §14.6 states: "async: blocks follow the same capture rules as closures." In src/MirLower.w:16815-16837, closures (!is_async) capture non-Copy locals by place (MIR_CAPTURE_PLACE_REF) and mark consumed locals with mark_local_ever_moved (16813) so reset-on-move blanks the outer binding through the capture pointer and keeps the null guard on the outer scope-exit drop. async: blocks (is_async, 16827-16835) instead copy raw bits (MIR_CAPTURE_LOCAL) into the heap env struct without MIR_CAPTURE_PLACE_REF or blanking the outer local when consumed.

Activity

  1. added
    bug
    spec-gap
    on Nov 5, 2026
  2. added a commit that references this issue on Nov 6, 2026
  3. ehartford commented on Nov 6, 2026

    @ehartford
    ContributorAuthor

    Fixed in #3054 (merged as 12489f1).

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

    bugspec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions