You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
comptime allocator: let comptime-callable functions use Vec/HashMap under the evaluator's allocator (D104 follow-up) #2220
D104 (2026-10-07) forbids the runtime heap allocator in comptime-callable code, so any plain function touching a Vec or HashMap is not comptime-callable: correct as the initial ruling, and a smaller set than it sounds. The next request is a comptime allocator (Zig has one): the evaluator's own allocator backs the std containers during compile-time evaluation, with values embedded as static data at the boundary as §17.1 already allows ("It may allocate inside the compiler evaluator and produce static program data"). Filed now, per the ruling, rather than awaited as a complaint.
Scoping 2026-10-07 (after D104 landed in b03a8ab): the first wall is before the allocator. A plain fn that builds a Vec[i32] and is called under comptime fails with collection.new() requires a concrete generic type; reached through total although var v: Vec[i32] = Vec.new() gives the type — the evaluator has no generic-instance resolution for a collection constructor inside a called body. Order of work: (1) the evaluator resolves Vec.new/push/iteration for a concrete instance reached through a call; (2) the evaluator's allocator backs them; (3) the result embeds as static data (§17.1). Repro: fn total(n: i32) -> i32: var v: Vec[i32] = Vec.new(); for i in 0..n: v.push(i); ... with let k = comptime total(4).
Step 1 on PR (branch comptime-vec): the evaluator carries a demand stack; a let annotation (var v: Vec[i32] = Vec.new()) binds the constructor's instance before Sema has typed the node, in a comptime block and through any function called under comptime; push, index, len and for x in v then run. HashMap new/insert bind the same way. Found with WITH_TRACE_COMPTIME=1, which now prints [ct] static_new … from=sema|demand|receiver at each static constructor. Remaining in step 1: for (k, v) in m at comptime ("comptime for requires an array, tuple, vec, or range"), a map-iteration gap in the evaluator separate from the demand. Steps 2 (the evaluator's allocator behind the containers) and 3 (embedding as static data) unchanged.
Second half of step 1 on the same PR (#2259, 409ae30): for (k, v) in m over a comptime map and for (a, b) in v over a Vec of tuples evaluate (the map's entries iterate as (key, value) tuples; a pattern binding goes through match_pattern). Fixture test/behavior/behav_2220_comptime_map_iteration.w. Step 1 is complete pending the battery; steps 2 and 3 remain.
Step 1 merged in cab3b48 (PR #2259): a let annotation binds a collection constructor's instance at comptime, through calls and in blocks; Vec push/index/len/iteration and HashMap new/insert/iteration evaluate; WITH_TRACE_COMPTIME=1 prints the type's source at each static constructor. Remaining: step 2 (the evaluator's allocator behind the containers, so a plain fn touching a Vec is comptime-callable without the annotation ceremony where D93's use-demand would type it at runtime) and step 3 (embedding the result as static data, §17.1).
Probe matrix on main (cab3b48), each a plain fn called under comptime: Vec new/push/pop/contains/index/len/for x in v ok; comptime fn with a Vec ok (D104's gate admits it); a struct holding a Vec[str] built at comptime embeds and reads at runtime ok (step 3 holds already: the evaluator's CV_VEC/CV_MAP are the static data); HashMap new/insert/len/iteration ok. Not yet: v.enumerate() ("Vec method is not comptime-evaluable yet") and v |> map(it * 2) |> filter(..) |> collect[Vec]() ("pipeline rhs is not comptime-evaluable" inside a called body). Both are the shape of step 2: the evaluator models each container method by hand, so every unmodeled method is a wall. The sustainable step 2 is running lib/std's own Vec/HashMap bodies under the evaluator with its allocator behind the raw-pointer intrinsics, which is a design in its own right; the alternative of modeling methods one at a time is endless. Leaving this open for that design; the two misses above are its first fixtures.
Ruling (Eric, 2026-10-20): go, in this order — (1) the ceremony fix: var v = List.new() in a body called under comptime must type without the annotation (the const fold runs before D93's use-demand types the body; type the body on demand when the evaluator first enters it); (2) step 2 as the addressed arena: the std adapters (iter, enumerate, the pipeline stages, MapIter) run as the With bodies they are, with the evaluator's arena behind the declared builtin methods and the ITER_* intrinsics — one source of truth, as Zig runs the same code at compile time. Delegated under D98 (compiler-internal, reversible, 85%).
Three requirements:
Checked addresses. An arena address carries its allocation and offset; every load and store checks bounds against that allocation. A bug in comptime code is a compile error naming the line, never an evaluator crash or a silently wrong constant.
No address escapes as a number.data_ptr: i64 is indistinguishable from an integer at embedding time, so a List or HashMap result is relocated into static data as a whole through its known type, and any other value carrying an arena-derived integer out of comptime is refused — provenance tracked through arithmetic on addresses makes the refusal possible.
Target layout. Since D114 isize and element sizes are the target's: arena data is built with the target's layout. A wasm32 comptime test embeds a List of structs.
Fixtures: v.enumerate() in a called body; v |> map(it * 2) |> collect[List]() in a called body; a struct holding a HashMap built at comptime and read at runtime; the wasm32 List-of-structs embed.
After it lands, its own issue: why std's ListIter holds a raw data_ptr: i64 instead of a view of the list — the i64 is what forces unsafe into the adapters and makes provenance hard; a typed view would make the iterator safe and give the evaluator provenance for free.
Ruling (Eric, 2026-10-20), refining the delegated decision — approved with one change:
Provenance travels with the value, never a lookup. Every evaluator integer carries an optional allocation tag through every operation: adding or subtracting an offset keeps the tag (what ListIter does); any other operation on a tagged value (multiply, xor, mask, shift) yields a value that can be neither dereferenced nor embedded, refused with an error naming the operation; an untagged integer can never be dereferenced, so no integer becomes an address after the fact. Rust's const evaluator is the reference (integer-to-pointer is unsupported there); the correction on Zig (it has no comptime allocator) is recorded.
Refusal wording with a fix-it. An escaping address reports the chain of calls to the value and names the field that carries it; the common case is an iterator or view returned where the collection was meant: "this value holds an address into a list built at compile time; return the List itself to embed it."
Fixtures with a negative case per requirement. Beside the shapes that must work (enumerate in a called body; a pipeline in a called body; a struct holding a comptime-built HashMap read at runtime; a wasm32 List-of-structs embed, also in every-target-check's program), each safety requirement has a test that fails the right way: an out-of-bounds comptime access that errors with its line; an escaping address refused with its call chain; laundered arithmetic on an address refused. A requirement without a failing fixture is a requirement nothing checks.
Ruling (Eric, 2026-10-20), on the finding that every adapter constructor and next is a codegen intrinsic (SemaCheck dispatch near line 8131, CodegenDispatchITER_*/*ITER_NEXT), so there are no std bodies for the evaluator to run: Option 2 — give the adapters real With bodies first; never a third copy of iterator semantics in the evaluator. Order:
Why are the adapters intrinsics? History (they predate generics/traits expressing them) → moving them is a pure win. Performance (codegen fusing map |> filter |> collect into one loop) → the std bodies must reach the same code before an intrinsic is deleted. Gate per move: the intrinsic and the std body produce the same IR, or a pipeline benchmark stays within 2%. Measure each family; do not assume monomorphization and inlining get there.
ListIter becomes a view, not a raw i64, before anything moves (the follow-up issue promoted to step one). Std iterators read through a checked view, so adapter bodies are safe With code with no unsafe and no pointer arithmetic; the evaluator then needs only what safe code needs: lists in the arena, the declared builtin methods (push, pop, index, len) over them, and views into them. Provenance-tagged integers stay only for whatever unsafe std code remains — or simpler, comptime refuses raw-address unsafe code entirely, naming the function.
Move the adapters one family at a time (iter/enumerate; map/filter; collect/sum/fold). Each move deletes the intrinsic from SemaCheck dispatch and CodegenDispatch; the campaign is measured partly in lines removed. Every moved family is comptime-callable with no evaluator work.
The evaluator arena comes last and is small: storage, the builtin methods, views and bounds checks. The hand model stays until the arena passes the fixtures.
Cost accepted: the comptime fixtures arrive later; nothing waits on comptime collections, and the result removes code from three places instead of adding a third copy. The ceremony fix (step 1 of the earlier ruling) landed in #2509.
Step 1 (why are the adapters intrinsics?) — measured 2026-10-20.
The With bodies already exist: lib/std/traits.w defines every adapter once over Iter[T] (iter_map → Mapped, iter_filter → Filtered, iter_enumerate → Enumerated, iter_fold, iter_count, iter_any/all/none/find/position, zip/chain/take/drop/step_by …; #1746, §13.3), and Sema routes an adapter call on any non-built-in Iter[T] implementor to them (user_iter_adapter_fn). The intrinsics (ITER_*, *ITER_NEXT, 2026-06-02 "iterator combinator substrate") predate #1746 by four months and stay only for the built-in iterator types by #1746's own choice ("their intrinsics stay"). So the answer is history for the semantics and performance for the gate:
-O3, 4,000,000 i64, best of 7
ns
A intrinsics: v.iter() |> map |> filter |> fold
4,026,708
B std.traits bodies, same pipeline (user Iter[T] wrapper forces the trait path)
35,323,583
C hand loop over ListIter.next()
1,892,042
D std.traitsfold only
9,162,208
E intrinsic fold only
1,569,000
F for x in v
4,414,958
The whole gap is one thing, isolated by a second matrix (#2511): a generic I: Iter[T] call to next() costs nothing (1.86 ms, equal to the concrete loop), while a call through a callable parameter costs 4.5× — Sema treats a callable parameter as may-suspend at every call site ("the caller's value, unknown, so it may"), and MIR emits a with_fiber_wait_cancelled poll and the cancelled-return switch after each invocation; llvm-objdump shows the two out-of-line calls per element in the inlined iter_fold loop. §14.3 INVARIANT 5 says may_suspend is part of callable type information, so this is a compiler non-compliance, filed as #2511 with the fix shape (a may_suspend component of the fn type, bodies instantiated per it, a sync callable compiles to a plain call).
Step 2 probe (ListIter as a view) — spelled and run 2026-10-20. A list iterator written as plain With today, no unsafe, no pointer arithmetic:
type ViewIter[T] ephemeral { list: &List[T], idx: isize }
impl[T] Iter[&T] for ViewIter[T]:
mut fn next() -> Option[&T]:
if self.idx >= self.list.len(): return None
let i = self.idx
self.idx = self.idx + 1
Some(&self.list[i])
works through for, |> map |> collect, |> fold, count, over List[i64] and List[str] (the element place xs[i] observes, D27; the yielded &T is the view). It is also faster than the intrinsic, -O3, 4,000,000 i64, best of 7:
loop
ns
ListIter.next() intrinsic, hand loop
1,838,417
view iterator next(), hand loop
1,144,875
for x in view_iter(v)
1,140,542
for i in 0..v.len(): v[i]
1,017,084
So the view is the right ListIter: bounds-checked through List's own len() and element place, 1.6× faster than today's raw data_ptr walk, and comptime gets it for free once lists have a place in the arena (the evaluator already evaluates len() and xs[i]).
One ceremony gap found: over a view iterator filter's predicate sees &&i64 (std.traits' pred: fn(&T) -> bool with T = &i64), and filter(it % 2 == 1) fails with "arithmetic operator requires numeric operands"; *it and **it both pass, and for x in …: total + x and map(it * 2) already read through one level. D22's contextual Copy materializes one & on an owned demand but not two. Today's intrinsic filter hands it: i64 by value, so step 2 must close this before ListIter changes shape, or filter(it % 2 == 1) on a List[i64] regresses into *it ceremony.
Plan for step 2, in order: (a) Sema: an owned-value demand materializes through nested & (the &&i64 case; fixture), (b) ListIter[T] becomes { list: &List[T], idx: isize } with the body above and Iter[&T], the by-value Copy flavor dropped (D22: a &i64 reads as an i64 where one is demanded) — this retires VECITER_NEXT, VECITERREF_NEXT, LIST_ITER, LIST_ITER_REF and Sema's iter→iter_ref rewrite (#2145); ListIterPlace/ListSlot stay for in-place mutation until their own step, (c) MapIter/MapSource already hold &HashMap views (D44) and need no change.
Step 2 sizing (ListIter becomes the view), from the tree at 0790070. D139 (#2515) closes the &&i64 gap first. What the change touches:
lib/std/collections.w: ListIter[T] → { list: &List[T], idx: isize } with the probe's next() -> Option[&T] body and impl[T] Iter[&T] for ListIter[T]; ListIterRef[T] (same layout, Option[&T] by intrinsic) folds into it; Iterable[T].iter -> ListIter[T] and BTreeSet.iter unchanged in spelling. ListIterPlace/ListSlot (in-place mutation, data_ptr) stay for their own step. lib/std/iter.witer_sum(ListIter[i32]) and lib/std/collections/sorted_list.wSortedListIter { array: i64 … } carry the same raw-i64 shape and move with it.
src/MirLower.w: lower_for keeps the counter loop for for x in v and for x in v.iter() on a List place (lower_for_list, 1.0 ms, the floor); the LIST_ITER/LIST_ITER_REF redirect becomes "the iterable is a List place" rather than "Sema recorded the intrinsic".
src/ComptimeEval.w: nothing — a view over a list the evaluator already holds is len() and xs[i], which it evaluates.
Copy elements: today v.iter() over i64 yields i64 by value and over str yields &str (#2145). The view yields &T for both; a for binding, map(it * 2) and (with D139) filter(it %% 2 == 1) read through it, so user code does not change. The one visible difference is a typed binding let x: &i64 = … where code assumed a value, which the spec already calls a demand (§3).
Step 3 (adapter families off the intrinsics, gated by IR or 2%): measured before moving anything. With ListIter a std view (step 2, #2526) and map traversals std structs (D44), no program can construct any of the thirteen intrinsic adapter types: their only constructors sit inside the intrinsic return table that only those types reach; ranges, generators and str have no adapters at all (#2544 filed for ranges); comprehensions lower as loops. The family is dead code and the gate is moot, so step 3 is a deletion (branch step3-adapters: the ITER_* and *ITER_NEXT intrinsics, the 13 symbols, the Sema rows and constructors, the LLVM emitters, ~1,970 lines), with the always-false helpers left for a follow-up pass. Step 4 (the small arena) follows.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced for maps; lists already work at comptime.
$ cat main.w # comptime fn pushing into a List[i32] and summing
$ with run main.w
14
$ cat map.w # comptime fn counting words in a HashMap[str, i32]
$ with run map.w
error: HashMap method is not comptime-evaluable yet; reached through count_words
--> map.w:4:31
post-release: the ruled campaign (Option 2, 2026-10-20) is at step 4, the evaluator arena.
Works inside a comptime fn today: a List (push, index, nested lists, iteration), and a HashMap (HashMap.new() or a literal, [:] or with pairs, as of #3609; insert, get, remove, contains, len, iteration over its pairs).
Still refused, each tried on main:
program
diagnostic
HashSet.new()
type method 'new' is not comptime-evaluable yet
xs.sort()
unsafe is not allowed in comptime
xs.reverse()
'List.reverse' is not comptime-callable: it reaches List.reverse -> with_alloc (an extern) (§17.1)
xs |> filter(…) |> map(…) |> sum()
List method is not comptime-evaluable yet
m.keys(), m.values()
cannot evaluate 'HashMap.keys' at compile time: it belongs to another package () and is not declared comptime fn
Every one of these is a standard-library method with a real body that allocates or uses unsafe. Evaluating them is what the ruled campaign's last step, the evaluator arena, is for; the step before it is the built-in methods getting real bodies and declared signatures, which is #3483. The ruling also says not to add a third hand-written copy of these methods in the evaluator, so I am not modelling them one by one.
Activity
D103, D104: value-to-Option conversion (§4.9a); comptime-callability …
D104: comptime-callability is inferred; a plain function runs at comp…
D104: comptime-callability is inferred; a plain function runs at comp…
ehartford commentedon Oct 7, 2026
Scoping 2026-10-07 (after D104 landed in b03a8ab): the first wall is before the allocator. A plain fn that builds a
Vec[i32]and is called undercomptimefails withcollection.new() requires a concrete generic type; reached through totalalthoughvar v: Vec[i32] = Vec.new()gives the type — the evaluator has no generic-instance resolution for a collection constructor inside a called body. Order of work: (1) the evaluator resolvesVec.new/push/iteration for a concrete instance reached through a call; (2) the evaluator's allocator backs them; (3) the result embeds as static data (§17.1). Repro:fn total(n: i32) -> i32: var v: Vec[i32] = Vec.new(); for i in 0..n: v.push(i); ...withlet k = comptime total(4).ehartford commentedon Oct 7, 2026
Step 1 on PR (branch comptime-vec): the evaluator carries a demand stack; a let annotation (
var v: Vec[i32] = Vec.new()) binds the constructor's instance before Sema has typed the node, in a comptime block and through any function called under comptime; push, index, len andfor x in vthen run. HashMapnew/insertbind the same way. Found withWITH_TRACE_COMPTIME=1, which now prints[ct] static_new … from=sema|demand|receiverat each static constructor. Remaining in step 1:for (k, v) in mat comptime ("comptime for requires an array, tuple, vec, or range"), a map-iteration gap in the evaluator separate from the demand. Steps 2 (the evaluator's allocator behind the containers) and 3 (embedding as static data) unchanged.Comptime: `for (k, v) in map` and `for (a, b) in vec` evaluate (#2220 …
ehartford commentedon Oct 7, 2026
Second half of step 1 on the same PR (#2259, 409ae30):
for (k, v) in mover a comptime map andfor (a, b) in vover a Vec of tuples evaluate (the map's entries iterate as (key, value) tuples; a pattern binding goes through match_pattern). Fixture test/behavior/behav_2220_comptime_map_iteration.w. Step 1 is complete pending the battery; steps 2 and 3 remain.Comptime: a let annotation binds a collection constructor's instance (#…
ehartford commentedon Oct 7, 2026
Step 1 merged in cab3b48 (PR #2259): a let annotation binds a collection constructor's instance at comptime, through calls and in blocks; Vec push/index/len/iteration and HashMap new/insert/iteration evaluate;
WITH_TRACE_COMPTIME=1prints the type's source at each static constructor. Remaining: step 2 (the evaluator's allocator behind the containers, so a plain fn touching a Vec is comptime-callable without the annotation ceremony where D93's use-demand would type it at runtime) and step 3 (embedding the result as static data, §17.1).ehartford commentedon Oct 7, 2026
Probe matrix on main (cab3b48), each a plain fn called under comptime: Vec new/push/pop/contains/index/len/
for x in vok;comptime fnwith a Vec ok (D104's gate admits it); a struct holding a Vec[str] built at comptime embeds and reads at runtime ok (step 3 holds already: the evaluator's CV_VEC/CV_MAP are the static data); HashMap new/insert/len/iteration ok. Not yet:v.enumerate()("Vec method is not comptime-evaluable yet") andv |> map(it * 2) |> filter(..) |> collect[Vec]()("pipeline rhs is not comptime-evaluable" inside a called body). Both are the shape of step 2: the evaluator models each container method by hand, so every unmodeled method is a wall. The sustainable step 2 is running lib/std's own Vec/HashMap bodies under the evaluator with its allocator behind the raw-pointer intrinsics, which is a design in its own right; the alternative of modeling methods one at a time is endless. Leaving this open for that design; the two misses above are its first fixtures.ehartford commentedon Oct 21, 2026
Ruling (Eric, 2026-10-20): go, in this order — (1) the ceremony fix:
var v = List.new()in a body called under comptime must type without the annotation (the const fold runs before D93's use-demand types the body; type the body on demand when the evaluator first enters it); (2) step 2 as the addressed arena: the std adapters (iter,enumerate, the pipeline stages,MapIter) run as the With bodies they are, with the evaluator's arena behind the declared builtin methods and theITER_*intrinsics — one source of truth, as Zig runs the same code at compile time. Delegated under D98 (compiler-internal, reversible, 85%).Three requirements:
data_ptr: i64is indistinguishable from an integer at embedding time, so a List or HashMap result is relocated into static data as a whole through its known type, and any other value carrying an arena-derived integer out of comptime is refused — provenance tracked through arithmetic on addresses makes the refusal possible.Fixtures:
v.enumerate()in a called body;v |> map(it * 2) |> collect[List]()in a called body; a struct holding a HashMap built at comptime and read at runtime; the wasm32 List-of-structs embed.After it lands, its own issue: why std's ListIter holds a raw
data_ptr: i64instead of a view of the list — the i64 is what forcesunsafeinto the adapters and makes provenance hard; a typed view would make the iterator safe and give the evaluator provenance for free.ehartford commentedon Oct 21, 2026
Ruling (Eric, 2026-10-20), refining the delegated decision — approved with one change:
comptime: an unannotated List/HashMap constructor in a called body is…
ehartford commentedon Oct 21, 2026
Ruling (Eric, 2026-10-20), on the finding that every adapter constructor and
nextis a codegen intrinsic (SemaCheckdispatch near line 8131,CodegenDispatchITER_*/*ITER_NEXT), so there are no std bodies for the evaluator to run: Option 2 — give the adapters real With bodies first; never a third copy of iterator semantics in the evaluator. Order:map |> filter |> collectinto one loop) → the std bodies must reach the same code before an intrinsic is deleted. Gate per move: the intrinsic and the std body produce the same IR, or a pipeline benchmark stays within 2%. Measure each family; do not assume monomorphization and inlining get there.ListIterbecomes a view, not a raw i64, before anything moves (the follow-up issue promoted to step one). Std iterators read through a checked view, so adapter bodies are safe With code with nounsafeand no pointer arithmetic; the evaluator then needs only what safe code needs: lists in the arena, the declared builtin methods (push, pop, index, len) over them, and views into them. Provenance-tagged integers stay only for whateverunsafestd code remains — or simpler, comptime refuses raw-addressunsafecode entirely, naming the function.Cost accepted: the comptime fixtures arrive later; nothing waits on comptime collections, and the result removes code from three places instead of adding a third copy. The ceremony fix (step 1 of the earlier ruling) landed in #2509.
ehartford commentedon Oct 21, 2026
Step 1 (why are the adapters intrinsics?) — measured 2026-10-20.
The With bodies already exist:
lib/std/traits.wdefines every adapter once overIter[T](iter_map→Mapped,iter_filter→Filtered,iter_enumerate→Enumerated,iter_fold,iter_count,iter_any/all/none/find/position, zip/chain/take/drop/step_by …; #1746, §13.3), and Sema routes an adapter call on any non-built-inIter[T]implementor to them (user_iter_adapter_fn). The intrinsics (ITER_*,*ITER_NEXT, 2026-06-02 "iterator combinator substrate") predate #1746 by four months and stay only for the built-in iterator types by #1746's own choice ("their intrinsics stay"). So the answer is history for the semantics and performance for the gate:-O3, 4,000,000i64, best of 7v.iter() |> map |> filter |> foldstd.traitsbodies, same pipeline (userIter[T]wrapper forces the trait path)ListIter.next()std.traitsfoldonlyfoldonlyfor x in vThe whole gap is one thing, isolated by a second matrix (#2511): a generic
I: Iter[T]call tonext()costs nothing (1.86 ms, equal to the concrete loop), while a call through a callable parameter costs 4.5× — Sema treats a callable parameter as may-suspend at every call site ("the caller's value, unknown, so it may"), and MIR emits awith_fiber_wait_cancelledpoll and the cancelled-return switch after each invocation;llvm-objdumpshows the two out-of-line calls per element in the inlinediter_foldloop. §14.3 INVARIANT 5 saysmay_suspendis part of callable type information, so this is a compiler non-compliance, filed as #2511 with the fix shape (amay_suspendcomponent of the fn type, bodies instantiated per it, a sync callable compiles to a plain call).Consequences for the order:
std.traitsbody should reach the hand loop (C), which is itself 2× faster than today's intrinsic (A) — the intrinsic's closure invocation is not the floor either, so "within 2% of the intrinsic" is a bar the bodies can clear from below.ListIteras a view) is independent of §14.3 INVARIANT 5: may_suspend is not part of the fn type, so every call through a callable parameter polls for cancellation (4.5× on a fold) #2511 and can proceed now.ehartford commentedon Oct 21, 2026
Step 2 probe (
ListIteras a view) — spelled and run 2026-10-20. A list iterator written as plain With today, nounsafe, no pointer arithmetic:works through
for,|> map |> collect,|> fold,count, overList[i64]andList[str](the element placexs[i]observes, D27; the yielded&Tis the view). It is also faster than the intrinsic,-O3, 4,000,000i64, best of 7:ListIter.next()intrinsic, hand loopnext(), hand loopfor x in view_iter(v)for i in 0..v.len(): v[i]So the view is the right
ListIter: bounds-checked throughList's ownlen()and element place, 1.6× faster than today's rawdata_ptrwalk, and comptime gets it for free once lists have a place in the arena (the evaluator already evaluateslen()andxs[i]).One ceremony gap found: over a view iterator
filter's predicate sees&&i64(std.traits'pred: fn(&T) -> boolwithT = &i64), andfilter(it % 2 == 1)fails with "arithmetic operator requires numeric operands";*itand**itboth pass, andfor x in …: total + xandmap(it * 2)already read through one level. D22's contextual Copy materializes one&on an owned demand but not two. Today's intrinsicfilterhandsit: i64by value, so step 2 must close this beforeListIterchanges shape, orfilter(it % 2 == 1)on aList[i64]regresses into*itceremony.Plan for step 2, in order: (a) Sema: an owned-value demand materializes through nested
&(the&&i64case; fixture), (b)ListIter[T]becomes{ list: &List[T], idx: isize }with the body above andIter[&T], the by-value Copy flavor dropped (D22: a&i64reads as ani64where one is demanded) — this retiresVECITER_NEXT,VECITERREF_NEXT,LIST_ITER,LIST_ITER_REFand Sema'siter→iter_refrewrite (#2145);ListIterPlace/ListSlotstay for in-place mutation until their own step, (c)MapIter/MapSourcealready hold&HashMapviews (D44) and need no change.ehartford commentedon Oct 21, 2026
Step 2 sizing (
ListIterbecomes the view), from the tree at 0790070. D139 (#2515) closes the&&i64gap first. What the change touches:lib/std/collections.w:ListIter[T]→{ list: &List[T], idx: isize }with the probe'snext() -> Option[&T]body andimpl[T] Iter[&T] for ListIter[T];ListIterRef[T](same layout,Option[&T]by intrinsic) folds into it;Iterable[T].iter -> ListIter[T]andBTreeSet.iterunchanged in spelling.ListIterPlace/ListSlot(in-place mutation,data_ptr) stay for their own step.lib/std/iter.witer_sum(ListIter[i32])andlib/std/collections/sorted_list.wSortedListIter { array: i64 … }carry the same raw-i64 shape and move with it.src/SemaCheck.w(12 sites): the intrinsic dispatch forListIter/ListIterRef.next(~8152),ensure_listiter_type_for(30919), the names.iter() |> filter(...) double-frees every kept element of a Vec[str] #2145iter→iter_refrewrite for owning elements (33330), thefor-binding element typing throughListIter/ListIterRef/ListIterPlace(34671–34716, 34753–34882), the element-view rules (37974–38023), the built-in iterator owner list (7962) that keepsListIteron the intrinsic adapters — with the view it leaves that list and the std.traits adapters apply (step 3's first family for free, gated by §14.3 INVARIANT 5: may_suspend is not part of the fn type, so every call through a callable parameter polls for cancellation (4.5× on a fold) #2511).src/MirLower.w:lower_forkeeps the counter loop forfor x in vandfor x in v.iter()on aListplace (lower_for_list, 1.0 ms, the floor); theLIST_ITER/LIST_ITER_REFredirect becomes "the iterable is aListplace" rather than "Sema recorded the intrinsic".src/CodegenDispatch.w:VECITER_NEXT,VECITERREF_NEXT,LIST_ITER,LIST_ITER_REFemitters (11840–11990) deleted;ListIterPlaceemitters stay.src/ComptimeEval.w: nothing — a view over a list the evaluator already holds islen()andxs[i], which it evaluates.Copy elements: today
v.iter()overi64yieldsi64by value and overstryields&str(#2145). The view yields&Tfor both; aforbinding,map(it * 2)and (with D139)filter(it %% 2 == 1)read through it, so user code does not change. The one visible difference is a typed bindinglet x: &i64 = …where code assumed a value, which the spec already calls a demand (§3).nested ref copy (#2515)
std: ListIter is a view of the list; the list-iterator intrinsics ret…
ehartford commentedon Oct 22, 2026
Step 3 (adapter families off the intrinsics, gated by IR or 2%): measured before moving anything. With ListIter a std view (step 2, #2526) and map traversals std structs (D44), no program can construct any of the thirteen intrinsic adapter types: their only constructors sit inside the intrinsic return table that only those types reach; ranges, generators and str have no adapters at all (#2544 filed for ranges); comprehensions lower as loops. The family is dead code and the gate is moot, so step 3 is a deletion (branch step3-adapters: the ITER_* and *ITER_NEXT intrinsics, the 13 symbols, the Sema rows and constructors, the LLVM emitters, ~1,970 lines), with the always-false helpers left for a follow-up pass. Step 4 (the small arena) follows.
The intrinsic iterator adapters retire: no source reaches them (#2220 …
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced for maps; lists already work at comptime.post-release: the ruled campaign (Option 2, 2026-10-20) is at step 4, the evaluator arena.
A map literal evaluates at compile time, empty or with pairs (part of #…
ehartford commentedon Nov 25, 2026
State on main (2026-11-25), after #3609:
Works inside a
comptime fntoday: aList(push, index, nested lists, iteration), and aHashMap(HashMap.new()or a literal,[:]or with pairs, as of #3609;insert,get,remove,contains,len, iteration over its pairs).Still refused, each tried on main:
HashSet.new()xs.sort()xs.reverse()xs |> filter(…) |> map(…) |> sum()m.keys(),m.values()comptime fnEvery one of these is a standard-library method with a real body that allocates or uses
unsafe. Evaluating them is what the ruled campaign's last step, the evaluator arena, is for; the step before it is the built-in methods getting real bodies and declared signatures, which is #3483. The ruling also says not to add a third hand-written copy of these methods in the evaluator, so I am not modelling them one by one.Labelling
blockedon #3483.