Skip to content

A comptime evaluation keeps the type caches: the compiler compiles itself in 96 s where it took 166 (#3351) - #3357

Merged
ehartford merged 1 commit into
mainfrom
reachable-lowering
Nov 16, 2026
Merged

ehartford merged 1 commit into
mainfrom
reachable-lowering

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Exact line. Sema.prepare_comptime_eval_copy (src/Sema.w) replaced the nine type caches (layout size, align and field offsets, copy-ness, needs-drop, unwrapped type, generic-instance identity, generic field types) and the enum-payload cache with empty ones. That was needed when a comptime evaluation worked on a copy beside a live original. Since D120 (#2449) the evaluator takes the Sema whole (comptime_take_sema writes a placeholder back) and its Sema is written back when it finishes, so the caches came back empty. The next eager_type_caches_pass then computed the layout of every type in the program again.

Evidence. Timing lower_module step by step on a 31-line test that imports Sema (test/internals_compiler/comptime_value_share_test.w): function bodies 18 ms; the specialization loop 42 s over 64 specializations, nine of which each spent ~4.7 s in preregister_mir_types, with eager_type_caches_pass reporting fresh=22672 (every type) each time. Those nine are the specializations whose recheck evaluates something at comptime (print, eprint, List.sort, BTreeSet.drop_entries).

Fix. The caches stay: their entries are facts of type ids, which only grow.

Measured.

  • mir.lower for that test: 51 s -> 3.9 s (dev compiler).
  • The compiler compiling itself (stage2, built by a stage1 that has the fix): 95.7 s, against 165.8 s in the builds before it.
  • internals-compiler-tests (two tests that each compile the compiler, one at a time): 71.6 s.

Battery: GREEN.

#3351 stays open for the smaller part (codegen and link of functions nothing reaches); its premise is corrected there.

…pass computed every type's layout again, 4.7 s each over the compiler's types (#3351)
@ehartford
ehartford merged commit e8c6b22 into main Nov 16, 2026
@ehartford
ehartford deleted the reachable-lowering branch November 16, 2026 02:56
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