Skip to content

Vec accepts ephemeral element types; escaping Vec[ephemeral] reads freed memory (§5.2 virality unenforced) #625

Closed

Description

@ehartford

Summary

let v = Vec.new(); v.push(StrView{ s: local }); return v compiles and the caller reads FREED memory (verified: prints stale contents). §5.2's virality rule — a container of ephemeral T is itself ephemeral ("If T is ephemeral … any generic F[T] is ephemeral") — is only enforced SYNTACTICALLY for ref-typed args (Vec[&str] via type_expr_is_collection_with_ref, SemaCheck.w:7395), not for named ephemeral structs and not through inference.

Spec

§5.1 (no heap storage of ephemerals), §5.2 (virality through generic args). type_is_ephemeral_value (SemaCheck.w:18710) already recurses through TY_GENERIC_INST args — enforcement should key off the SEMANTIC predicate at container-elem establishment (push/insert/collect inference), making the container binding ephemeral (locals fine, returns need §5.2 propagation, stores rejected).

Note

Sibling of #600 (heap-boxing constructors gated 2026-07-03). Repro from that investigation: scratchpad p600/p4c shape above.

Blocker discovered alongside

Explicit Vec[StrView]/Box[StrView] ANNOTATIONS misresolve the generic arg (push 'expects &str'; as_ref yields str) — an accidental type-arg erasure that any virality fix must not rely on; probably its own bug.

Activity

  1. added a commit that references this issue on Jul 4, 2026
  2. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    BDFL ruling (2026-07-04): heap containers of ephemeral element types are BANNED outright — §5.1 governs; §5.2 amended to propagate through value constructors only (Option/Result/tuple/ephemeral-marked structs). The idiom for batch references is indices/ranges into the owning collection (the compiler's own pool pattern). Rationale: one sema gate, safe by construction, zero runtime cost, no migrate/c_import impact; static virality is machinery whose every missed gate is a soundness hole (this bug WAS a missed gate); revisit only on demonstrated library need. Implementation: reject ephemeral element types at container-element establishment (type formation, push/insert, collect inference) with a loud error naming the idiom. The generic-arg misresolution noted as this issue's blocker is a separate substrate bug shared with #627 — investigate as one.

  3. ehartford commented on Jul 5, 2026

    @ehartford
    ContributorAuthor

    Fixed in ea2030d via viral-ESCAPE (not an annotation ban). The original repro (v.push(StrView{s: local}); return v) is now a compile error (returned ephemeral value may outlive its origin), including in tail position and through inference; Box.new(ephemeral) is caught by the #600 gate. Memory-safe batches of owned handles (the stdlib's Vec[Workspace]) and containers that borrow a parameter remain unrestricted — the model of Rust lifetimes / Vale regions. Ruling revised after reference review; full rationale in docs/decisions.md D2. §5.2 restored to full virality; fixpoint + full suite green.

  4. added 2 commits that reference this issue on Jul 5, 2026
    ea2030d
    5b1d74c
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