refactor: extract partial-eval constant phase - #184
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the compiler’s partial-evaluation implementation by extracting the constant-only expression evaluation primitives into a dedicated module, keeping existing partial_evaluate() / dead-code elimination behavior wired through compatibility aliases while adding targeted regression tests.
Changes:
- Added
partial_eval_constants.pyto own the literal-only constant evaluator, the unresolved sentinel, expected-failure exception policy, and comparison dispatch. - Updated
partial_eval.pyto import and alias the extracted constants/functions, removing the inlined implementations. - Added focused tests covering nested folding, unresolved fallback, short-circuiting, expected failures, invalid operators, and process-control exception propagation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/test_partial_eval_constants.py | New focused test suite for the constant-expression partial-eval phase contracts. |
| src/kida/compiler/partial_eval.py | Rewires the monolithic partial evaluator to use extracted constant-phase primitives via module-local aliases. |
| src/kida/compiler/partial_eval_constants.py | New internal module encapsulating constant-only evaluation, sentinel, exception policy, and comparison dispatch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
partial_eval_constants.pypartial_evaluate()andeliminate_dead_code()behavior through module-local compatibility aliasespartial_eval.pyfrom 2,307 to 2,174 linesWhy
This is the first bounded #143 phase split. Constant-only expression evaluation is a cohesive boundary shared by dead-code elimination and static-context evaluation, but it was embedded across the monolithic partial evaluator.
Impact
No public API, AST, render output, escaping, source-location, or optimization semantics change. The package smoke test confirms the new internal module ships in wheel and sdist artifacts.
Verification
make verify-stability: 4,459 passed, 5 skipped; coverage gate, safety suite, build, and clean-venv smoke passedpytest benchmarks/test_benchmark_compile_pipeline.py benchmarks/test_benchmark_partial_eval.py --benchmark-onlyBenchmark Evidence
gil_enabled=FalseSteward Notes
Refs #143.