Skip to content

Aggregates over two words cross With calls through memory (ABI v11): compiler build 115s -> 46s - #1939

Merged
ehartford merged 5 commits into
fix-1816from
outline-drop-glue
Sep 30, 2026
Merged

ehartford merged 5 commits into
fix-1816from
outline-drop-glue

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Compile-speed item 3. Structs/arrays >16 bytes pass by pointer to a caller copy and return via sret on every target under With's own convention (the rule windows-x86_64 already used). SROA was scalarizing 700-field aggregates into per-leaf loads/args: run_mir_lower 360KB -> 8.4KB. Compiler build wall 115s -> 46.5s, peak RSS 11.3GB -> 3.8GB, slowest LLVM unit 63s -> 4.1s. ABI change: batteries alone.

Eric Hartford added 4 commits September 30, 2026 10:57
…rget (ABI v11)

A struct or array larger than 16 bytes is now passed as a pointer to a
caller-made copy and returned through sret under With's own convention on
every target, the rule windows-x86_64 already applied above 8 bytes
(fn_abi_platform_aggregate_indirect). By LLVM value, SROA scalarized each
such argument into one load and insertvalue per leaf field and the backend
passed every leaf as its own argument: Compilation.run_mir_lower was 87%
`.fca` loads/insertvalues (59,775 of 68,841 IR instructions), passing a
700-field Sema by value to Zcu.sync_from_sema and friends.

Measured (llc -time-passes on the slowest unit, u4): AArch64 instruction
selection 64%, post-RA scheduler 21%, machine scheduler 9% of 53 s.

Compiling the compiler (out/release/bin/with build out/gen/main.w -O1):
  wall 115.0 s -> 46.5 s; user CPU 478 s -> 89 s; peak RSS 11.3 GB -> 3.8 GB
  llvm.gen_units_serial 24.5 s -> 15.6 s
  slowest unit 63.1 s -> 4.1 s (units now 2.8-4.1 s)
  run_mir_lower 360 KB -> 8.4 KB machine code; the other giants
  (compile_source_frontend_mode 233->60 KB, comptime_eval_tool_action_result
  226->2.4 KB, comptime_eval_tool_build_result 225->1.8 KB,
  load_build_graph_from_build_w 220->17.6 KB); With __text 11 -> 7 MiB.
Stage build: stage2 115 s -> 57 s, link-compiler 114 s -> 50 s.

The drop-glue hypothesis was checked first and is not the cause: drop
glue is already outlined per type (__drop_struct_N / __drop_enum_N).

Benchmarks at -O2 (5 interleaved runs, same checksums): buffers, grow,
nbody, words unchanged within noise; trees ~5% faster.

Verified: :gate green, :drop-audit 254 cells 0 regressions,
:debug-alloc-tests green, :fixpoint stage2 == stage3 over 16 units.
… takes

rt/linux_x86_64.w and rt/linux_aarch64.w passed `len - off` (u64) to
rt_read(len: i64); the implicit-narrowing rule (§4.2.6) refuses it, so
stage1-rt-platform-object failed and no Linux build of main (9adac70)
got past stage1 (verified on eric-5090 with origin/main).
…ls never use byval; decl lookup by name index

Three changes to compiling a multi-unit program (the compiler itself):

1. Pipelined units (CodegenUnits.CodegenUnitPipeline). Each unit's
   finished module and its own LLVMContext go straight to a thread that
   optimizes and emits it while the next unit generates; the serial
   write-bitcode / parse-bitcode round trip is gone (WITH_KEEP_BITCODE=1
   still writes <obj>.u<k>.gen.bc). Builders (IR and debug-info, which the
   old deinit leaked) are disposed on the generating thread before the
   handoff. Per-function sroa,mem2reg moves from generation to the unit's
   thread as function(sroa,mem2reg) over the module. A one-unit window
   (hosts at or under 8 GiB) keeps the old no-overlap behavior. Every
   started thread is joined before any return.

2. ABI v11 refinement: an indirect argument under With's own conventions
   is a plain pointer to the caller's copy on every target; LLVM byval is
   only for the C convention on SysV x86_64 (fn_abi_indirect_uses_byval,
   FnAbi.w; hash re-recorded). v11 had given With calls byval on x86_64,
   a path Windows never exercised: on Linux x86_64 examples_async-auction
   segfaulted and `analyze audit:all` reported "byval attribute disagrees
   with FnAbi" (Box.new receiver). fn_abi_byval_types stays the callee's
   copy-type list; fn_abi_byval_attr_types is what attributes read.

3. Codegen.generic_type_decl_node scanned every declaration, cloning two
   names per step, on each lookup: the hottest IR-generation frame (sample:
   863 self + 467 AstPool.get_decl of ~6000 main-thread samples). A
   first-match name index, built once per module, answers it.

Compiling the compiler (out/gen/main.w -O1, idle Mac, two interleaved
runs each; "before" = main's compiler, which stops at the final bundle
ABI check after all units emit):
  wall            103.6 s -> 35.8 s
  user CPU        439 s   -> 72 s
  peak RSS        11.6 GB -> 1.46 GB
  gen_units_serial 22.5 s -> 7.0 s; gen + emit 9.7 s total
  (after ABI v11 alone, fe1cd98: 46.5 s wall, 15.6 s gen, 3.8 GB)

Verified (Mac): :gate green, :fixpoint stage2 == stage3 over 16 units,
:drop-audit 254 cells 0 regressions, :debug-alloc-tests green.
Linux x86_64 (eric-5090): :gate green except no-host-toolchain, which
fails the same way on origin/main (llvm_ld.rsp names host libxml2).
… D22/D27)

`let id = self.count` binds a view of the field; `self.count += 1` then
mutates self while it is live, which §21.1 rule 1 refuses ("cannot mutate
`self` while `id` is a live view into it"). The annotation is the owned
demand that takes the snapshot the function returns.
@ehartford
ehartford changed the base branch from main to fix-1816 September 30, 2026 14:57
@ehartford
ehartford added this pull request to stack #1940 September 30, 2026 14:57
…e-word Trio by plain pointer (ABI v11)

The test pinned v10: `@plain_trio(%Trio` by LLVM value. Under v11 an
aggregate over two words crosses a With call as a plain pointer on every
target (fn_abi_platform_aggregate_indirect), never byval; the variadic
definition keeps the C convention (byval on SysV x86_64). The #1939
battery on 1d01be3 was red on this test alone.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack top 23f1cf4 (seed-driven, with run tools/battery.w; stack #1940 = #1937 → #1938 → #1939): gate rc=0, battery-checks rc=0. Previous run on 1d01be3 was RED on behav_variadic_definition_target_abi alone (it pinned the v10 by-value @plain_trio(%Trio); updated to v11's plain pointer in 23f1cf4. ABI doc v11 wording awaits Eric's sign-off.

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