Skip to content

@[no_alloc] misses an allocating callee declared after the caller (Sema reads fn_may_alloc before the callee's body is checked) #1941

Closed

Description

@ehartford

Spec: §(no_alloc context) — an @[no_alloc] function may not call an allocating function.

Repro (compiles ok; expected error: allocating callee allocates here):

@[no_alloc]
fn main:
    let msg = make_message()
    msg.len()

fn make_message -> str:
    f"value={1}"

test/compile_errors/err_no_alloc_allocating_callee.w passes only because the callee is declared first.

Cause: fn_may_alloc is written at the end of each body check (SemaCheck.w ~3910) and read by note_allocating_callee (~5800) while later bodies are checked. A caller checked before its callee reads "does not allocate". The callee-first scheduling in prepare_body_order covers only unannotated / view-returning callees.

Evidence of the wider class: with a debug switch that checks top-level bodies in reverse order (WITH_SEMA_BODY_ORDER=reverse, branch parallel-sema), 122 of 1560 test/compile_errors fixtures change their diagnostics. Most are one spurious std error, but 16 differ in substance: this missed no_alloc error; an inferred type that changes (fn(i32) -> i32 vs fn(i32) -> Unit, err_1564_debug_no_form_rc); may-suspend/generator-pull results; and spans attributed to the wrong file.

Fix direction: consume the summary after all bodies are checked (a post-body pass over recorded calls, like untyped_callee_calls), not during the caller's body.

Activity

  1. ehartford commented on Oct 2, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 45cc685 (#1945): @[no_alloc] judges calls to allocating functions after every body is checked (a fixpoint over recorded calls), so a callee declared after the caller is no longer missed; two fixtures that compiled ok before the fix now fail as they should. Battery green.

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