Repository navigation
Closed
Description
Add ArenaScope guard type with @[no_await_guard] (§7.9, §8.3a)
Summary
§7.9 names ArenaScope as one of the four stdlib types that carry @[no_await_guard], and its rule table lists "Arena scope across await" as a compile error. No ArenaScope type exists in std.alloc today, so the rule is unimplementable. The enforcement machinery itself (NLL-based E0701) is already built and tested — this issue adds the missing stdlib type, annotates it, and locks the rule in with tests.
Spec
§7.9 (docs/with-specification.md:2770-2862), §8.3a (docs/with-specification.md:2928-2960).
- §7.9 table (docs/with-specification.md:2840-2846):
Arena scope | Yes (@[no_await_guard]) | .await in with → **Error**. - §7.9 (docs/with-specification.md:2849-2852): "Standard library types that carry
@[no_await_guard]:MutexGuard,ReadGuard,WriteGuard, andArenaScope." - §7.9 (docs/with-specification.md:2789-2792): the compiler rejects any same-fiber operation that may suspend while a
@[no_await_guard]value is live in the NLL sense — whether created viawithor a plainlet. - §20b.1 (docs/with-specification.md:10354-10362): same rule restated; diagnostic code E0701.
- §8.3a context:
Arenais the long-lived, user-controlled-reset region allocator; a scope of an arena is a lexically-bounded allocation region.
Current state
- Enforcement exists and is NLL-based:
@[no_await_guard]parses intoAstPool.mark_no_await_guard_type(src/Ast.w:1221-1226), sema tracks annotated types inno_await_guard_types(src/Sema.w:355) and checks liveness across may-suspend operations (type_is_no_await_guardsrc/SemaCheck.w:1934-1955,fn_symbol_may_suspend/expr_may_suspend:2058+, guard-scope depth :1959). Diagnostic code E0701. Tested by test/spec/spec_ss07_9_nll_based_no_await_guard.w, test/compile_errors/err_may_suspend_call_under_no_await_guard.w, err_suspend_guard_derived_ref*.w. - The stdlib annotates its lock guards:
MutexGuard,MutexGuardMut,RwReadGuard,RwWriteGuard(lib/std/sync.w:11-37). - lib/std/alloc.w (66 lines) has
Arena(a block_size-only malloc passthrough),TempArena(real: records allocations, frees on reset/drop), andPool. NoArenaScopetype exists anywhere (grep -rn ArenaScope lib/ src/→ only spec hits). So requirement 7.9.1.10 has nothing to attach to, and 7.9.1.14's stdlib set is missing one of its four members. - Requirements campaign verdicts:
7.9.1.10absent ("no ArenaScope guard type");7.9.1.14partial ("ArenaScope missing from set").
Implementation plan
- Add
ArenaScopeto lib/std/alloc.w, modeled onTempArena's real semantics so it is not a stub:With methods/// Scoped allocation region over an Arena. All allocations made /// through the scope are released when the scope ends. @[no_await_guard] pub type ArenaScope { allocations: Vec[i64], }ArenaScope.alloc(mut self, size: i32) -> *i8,ArenaScope.alloc_zeroed(mut self, count: i32, size: i32) -> *i8(record pointers like TempArena does), andArenaScope.drop(mut self)freeing recorded allocations. Until First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 lands a real regionArena, the scope's release mechanism is per-allocation free (same honest interim semantics TempArena already uses); First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 replaces the internals with a watermark (mark/reset_to(mark)) without changing the type's surface or annotation. - Constructor:
pub fn Arena.scope(self: &Arena) -> ArenaScopein lib/std/alloc.w. The guard is produced from the arena and used either as a plain binding (let s = arena.scope()) or viawith arena.scope() as mut s:(Form 2 binding — the NLL check covers both per §7.9; noScopedimpl is required for E0701 to apply, and lib/std/sync.w shows the optionalScoped/ScopedMutpattern if guarded-with ergonomics are wanted later). - No compiler changes are needed: the annotation machinery is data-driven off
@[no_await_guard]in the type decl. Verifytype_is_no_await_guardresolves the stdlib type through the prelude/module path the same wayMutexGuarddoes (it keys off the type symbol; sync.w proves the pattern). - Bootstrap note: this only touches lib/std (embedded into the compiler binary at build time). No rt/Link.w hazard; normal
with build+:fixpointchain applies. - Spec cross-check: §7.9 calls the lock guard types
ReadGuard/WriteGuardwhile lib/std/sync.w spells themRwReadGuard/RwWriteGuard— out of scope here (Make stdlib guards and borrowed-data iterators canonically ephemeral (§5.3) #477/Real generic Mutex[T]/RwLock[T] with fiber-aware blocking (§14.17) #471 territory), but keepArenaScopespelled exactly as the spec names it.
Test plan
- test/compile_errors/err_arena_scope_across_await.w —
//! expect-error: E0701(match the existing fixture style of err_may_suspend_call_under_no_await_guard.w): createlet s = arena.scope(), keep it live (use it after) across atask.await→ error. - test/compile_errors/err_arena_scope_may_suspend_call.w — calling a may-suspend helper (a fn containing
.awaitinternally) while an ArenaScope is live → E0701. - test/spec/spec_ss07_9_arena_scope_guard.w —
//! expect-stdout: ok, positive cases mirroring spec_ss07_9_nll_based_no_await_guard.w: (a) last use of the scope before the await → OK; (b) explicitdrop(s)before await → OK; (c)with arena.scope() as mut s:block ends before the await → OK; (d) allocations through the scope actually work (s.alloc(64)non-null, write/read through it). - test/behavior/behav_arena_scope.w —
//! expect-stdout: ok: scope releases its allocations at end of scope (smoke: allocate, drop scope, allocate again; with First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437's watermark this upgrades to a reuse assertion).
Acceptance criteria
-
ArenaScopeexists in lib/std/alloc.w, carries@[no_await_guard], and is constructible viaArena.scope(). - Holding an ArenaScope across
.awaitor a may-suspend call is rejected with E0701 (both plain-binding andwithforms). - Dropping/ending the scope before the suspension point compiles and runs.
- The stdlib
@[no_await_guard]set now includes all four spec'd members (modulo the guard renames tracked in Make stdlib guards and borrowed-data iterators canonically ephemeral (§5.3) #477/Real generic Mutex[T]/RwLock[T] with fiber-aware blocking (§14.17) #471). -
with build && with build :fixpoint && with build :testpass (andwith build :test-greenrecorded).
Dependencies
- First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 (first-class allocators) replaces ArenaScope's internals with real region semantics — this issue deliberately lands the type + annotation + enforcement first with TempArena-style semantics so First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 is not a blocker.
- Make stdlib guards and borrowed-data iterators canonically ephemeral (§5.3) #477 (stdlib canonically-ephemeral guards) and Real generic Mutex[T]/RwLock[T] with fiber-aware blocking (§14.17) #471 (real generic Mutex/RwLock) touch the same §5.3/§7.9 guard set.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 7.9.1.10, 7.9.1.14.
Metadata
Metadata
Assignees
Labels
No labels
Activity
Requirements triage campaign: checkbox, verdict, and issue-link every…
ehartford commentedon Jun 12, 2026
Implemented in 89f4905.
Summary:
Arenaand@[no_await_guard]ephemeralArenaScopetostd.alloc.Arena.scope()plusArenaScope.alloc,alloc_zeroed,reset,drop, andallocation_countusing the existing TempArena-style allocation tracking until First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 replaces the internals.with arena.scope() as mutending before await.withblocks held across suspension.Verification passed:
with buildwith build :fixpointwith build :testwith build :test-green