Skip to content

refactor: extract partial-eval constant phase - #184

Merged
lbliii merged 1 commit into
mainfrom
codex/split-partial-eval-expressions
Jul 7, 2026
Merged

refactor: extract partial-eval constant phase#184
lbliii merged 1 commit into
mainfrom
codex/split-partial-eval-expressions

Conversation

@lbliii

@lbliii lbliii commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • extract the literal-only evaluator, unresolved sentinel, expected-failure policy, and comparison dispatch into partial_eval_constants.py
  • preserve partial_evaluate() and eliminate_dead_code() behavior through module-local compatibility aliases
  • add focused tests for nested folding, dynamic fallback, short-circuiting, expected failures, invalid operators, and process-control exceptions
  • reduce partial_eval.py from 2,307 to 2,174 lines

Why

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

  • focused partial-eval suite: 319 passed
  • make verify-stability: 4,459 passed, 5 skipped; coverage gate, safety suite, build, and clean-venv smoke passed
  • repository-wide Ruff, format, and default-severity ty checks
  • before/after: pytest benchmarks/test_benchmark_compile_pipeline.py benchmarks/test_benchmark_partial_eval.py --benchmark-only

Benchmark Evidence

  • macOS 26.5.1 arm64, Python 3.14.2 free-threading build, gil_enabled=False
  • 13 partial-eval render medians were flat or within about 4.2% of baseline; the worst movement was 2.000µs to 2.083µs and remains below the 5% regression threshold
  • compile-pipeline medians improved 6–14% in this local run; treated as non-regression evidence, not a performance claim
  • no committed baseline update; Linux CI remains authoritative

Steward Notes

  • Consulted: Compiler/Codegen, Test Corpus, Benchmark, and root runtime guidance.
  • Accepted: extract only the constant-expression phase and preserve both existing entrypoints.
  • Required proof: direct phase tests, full partial-eval suite, full stability gate, package smoke, and before/after compiler benchmarks.
  • No collateral: no public docs, examples, changelog, schemas, or migration notes because behavior and public contracts are unchanged.
  • Deferred: control-flow, call/def inlining, loop-unrolling, and transform-phase extraction remain in Split partial evaluation into smaller phase-owned modules #143.

Refs #143.

@lbliii
lbliii marked this pull request as ready for review July 7, 2026 16:25
Copilot AI review requested due to automatic review settings July 7, 2026 16:25
@lbliii
lbliii merged commit 99d6729 into main Jul 7, 2026
10 checks passed
@lbliii
lbliii deleted the codex/split-partial-eval-expressions branch July 7, 2026 16:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py to own the literal-only constant evaluator, the unresolved sentinel, expected-failure exception policy, and comparison dispatch.
  • Updated partial_eval.py to 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.

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.

2 participants