Skip to content

Comptime: a let annotation binds a collection constructor's instance (#2220 step 1) - #2259

Merged
ehartford merged 2 commits into
mainfrom
comptime-vec
Oct 7, 2026
Merged

ehartford merged 2 commits into
mainfrom
comptime-vec

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

See the commit. The evaluator gains a demand stack; a let annotation is the demand; Vec.new()/HashMap.new() under an annotation evaluate through calls and in blocks. Trace line for the class; route in the tools doc. Gate and battery to follow.

Eric Hartford added 2 commits October 7, 2026 11:46
…tructor's instance (#2220 step 1)

Top-level folding runs before Sema, so typed_expr_types is empty for the
nodes being folded and `Vec.new()` under `var v: Vec[i32] = Vec.new()` saw
only the generic base `Vec`; eval_static_collection_new refused it with
"requires a concrete generic type", in a comptime block and through any
function called under comptime. The annotation was in the AST and never
read.

The evaluator now carries a demand stack (expected_types, Law 2's demand
in the evaluator): eval_let_binding pushes the binding's annotation type
around its initializer, and the static `new` path takes the demanded
generic instance when the receiver gives only the base and the bases
agree (Vec, HashMap). `v.push`, indexing, `len` and `for x in v` then run
on the concrete instance. HashMap `new`/`insert` bind the same way; map
iteration at comptime is a separate evaluator gap, noted on the issue.

WITH_TRACE_COMPTIME=1 prints at each static constructor
`[ct] static_new node=… recv='Vec' result='Vec[i32]' from=sema|demand|receiver`,
so this class is one run; the route is in deep-debugging-tools.md. The
refusal, when no demand exists, now says why and what to write.

Fixture: test/behavior/behav_2220_comptime_vec_by_demand.w (through a
call, len through a call, and a comptime block; fails on the installed
compiler with the old refusal). Comptime behavior set: 42 files ok on
stage1.
…step 1, second half)

eval_for refused a map ("comptime for requires an array, tuple, vec, or
range") and bound a tuple pattern as if it were a symbol. A map value's
entries sit in extra_values as key/value pairs, so each entry is a
(key, value) tuple over its pair (no copy), and a binding the parser
marked as a pattern (has_pattern_binding) goes through match_pattern.
D44's map traversal and tuple destructuring now hold at comptime.

Fixture: test/behavior/behav_2220_comptime_map_iteration.w (a map built
and summed in a function called under comptime; a Vec of tuples
destructured); fails on the installed compiler. Comptime behavior set:
41 files ok on stage1.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 409ae30 (tools/battery.w: gate 62s, uat 27s, battery-checks 782s; status.txt has no RED).

@ehartford
ehartford marked this pull request as ready for review October 7, 2026 19:21
@ehartford
ehartford merged commit cab3b48 into main Oct 7, 2026
@ehartford
ehartford deleted the comptime-vec branch October 7, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant