Commit 0cc6e12
* feat(trunk-ir): add arena IR transform passes and rewrite helpers
- Add DCE pass using use-chain analysis to eliminate dead operations
- Add Global DCE pass with call graph analysis for dead function removal
- Add SCF-to-CF lowering pass using split_block/inline_region_blocks/RAUW
- Add arena rewrite helpers: split_block, inline_region_blocks, erase_op
- Add add_block_arg and detach_op methods to IrContext
- Fix register_pure_op\!/register_isolated_op\! macros to use raw_ident_str\!
instead of stringify\!, enabling correct DCE detection for ops like arith.const
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(trunk-ir): fix two bugs in arena rewrite/transform helpers
- `inline_region_blocks`: add early-return guard when `src_region ==
dest_region` to prevent a panic caused by aliased mutable borrow of
the same region; add test `inline_region_blocks_same_region_is_noop`
- `lower_scf_switch`: scan all case regions (not just the first) when
inferring `result_ty` from yield values, so a yield in any case is
found even when earlier cases are void; add test
`lower_scf_switch_yield_in_later_case`
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(trunk-ir): fix global DCE dropping callees of abi functions
Abi functions (marked with the `abi` attribute) are externally callable
and must be treated as reachability roots so that their callees are not
incorrectly eliminated. Previously, abi functions were preserved by a
special guard in `filter_region`, but that guard only kept the functions
themselves — any function called exclusively from an abi function was
still silently removed.
Fix the root cause: add abi functions to `reachability_roots` during
analysis so the BFS traversal naturally keeps their entire transitive
call graph alive. The now-redundant abi preservation guard in
`filter_region` is removed.
Rename the internal `entry_points` field to `reachability_roots` to
reflect that abi functions, main/wasm exports, and custom roots are all
treated uniformly as BFS starting points. The public API
`GlobalDceConfig::extra_entry_points` is unchanged.
Add test `abi_function_callees_are_reachable` to cover the fixed case.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(trunk-ir): fix scf_to_cf lowering bugs for switch and yield
- Remove stale `remove_op_from_block` call in `lower_scf_if`: after
`split_block`, the scf op is already moved to the merge block, so
the removal was a silent no-op; only `detach_op` is needed.
- Fix `lower_scf_switch` result_ty determination: infer from the op's
actual results instead of scanning yield ops, consistent with
`lower_scf_if`. Since `scf.switch` has no result, `result_ty` is
always `None`, eliminating the merge block / branch arg count mismatch.
- Make `replace_yield_with_br` defensive by truncating yield values to
the target block's expected arg count, preventing malformed `cf.br` ops.
- Remove unused `find_yield_type` helper.
- Update test: rename to `lower_scf_switch_no_result` and correct the
assertion from 1 merge block arg to 0.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f135f06 commit 0cc6e12
File tree
9 files changed
+2855
-4
lines changed- crates/trunk-ir/src
- arena
- rewrite
- transforms
9 files changed
+2855
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
316 | 329 | | |
317 | 330 | | |
318 | 331 | | |
| |||
361 | 374 | | |
362 | 375 | | |
363 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
364 | 388 | | |
365 | 389 | | |
366 | 390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
0 commit comments