Conversation
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
nielstron
left a comment
There was a problem hiding this comment.
there are tests missing that unsafe inlinings are not performed:
- field access that could crash and only executed in a branch
- using the variable multiple times
| target = eval_uplc_raw(target_code, 4, config=_DEFAULT_CONFIG) | ||
|
|
||
| assert source.result == target.result | ||
| assert source.cost.cpu >= target.cost.cpu |
There was a problem hiding this comment.
Fixed in e0478c5 — all cost assertions now use <=.
|
@copilot |
… variables Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
…ment removal, new tests - Add GuaranteedLoadCollector to identify loads at guaranteed positions - Include function arguments in guaranteed_names and is_simple check - Remove inlined assignments with dependency-aware removable set - Change cost assertions from >= to <= - Add test_no_inline_unsafe_in_branch: unsafe expr in branch not inlined - Add test_no_inline_multiple_reads_non_simple: non-simple multi-read not inlined - Add test_inline_guaranteed_execution: non-safe expr inlined when guaranteed Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Added in e0478c5:
Implemented in e0478c5 — added |
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
|
|
|
@copilot please fix the failing tests and binary size checker |
…r cost assertions Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
The test assertion issue is fixed in d799269 — The Tests & QA workflow already passes. The binary size tracker failure is pre-existing on the dev branch — it also fails for PRs #612, #614, and #616 (since commit |
Implements an expression inline optimizer that substitutes simple variable assignments at their usage sites, reducing intermediate bindings in compiled output.
Inlining criteria
DefinedTimesVisitor)bound_vars)SafeOperationVisitor)Changes
opshin/optimize/optimize_inline_expressions.py— New optimizer with four visitors:AssignmentCollector— gathers single-target assignmentsGuaranteedLoadCollector— identifies variable loads at guaranteed execution positions (not inside if/while/for branches), enabling safe inlining of non-pure expressions when the use is unconditionalNameSubstitutor— performs substitution with frozenlist-safegeneric_visitoverride and removes inlined assignments using a dependency-awareremovableset (assignments whose expressions reference other inlineable variables are kept for the next iteration)OptimizeInlineExpressions— iterates to fixpoint, handling chained inlining (a=5; b=a; c=b→c=5)opshin/compiler.py— Integrated beforeOptimizeRemoveDeadvarsin the pipeline, gated byconfig.remove_dead_codetests/test_optimize/test_inline_expressions.py— 10 tests:Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.