Skip to content

compile: --target 3.11 emission switch; PyPy is the fastest measured host - #7

Merged
simontreanor merged 1 commit into
mainfrom
target-311
Jul 18, 2026
Merged

compile: --target 3.11 emission switch; PyPy is the fastest measured host#7
simontreanor merged 1 commit into
mainfrom
target-311

Conversation

@simontreanor

Copy link
Copy Markdown
Owner

The switch

Emitted Pyfun needed Python 3.12 for exactly one construct: an f-string hole carrying a nested same-quote string literal or a backslash (PEP 701). pyfun compile --target 3.11 rewrites exactly those f-strings into equivalent "template".format(args...) calls (src/python_emitter/py311.rs, applied by emit_for on a clone of the IR; single-file and project paths). Clean f-strings stay f-strings, so 3.11-target output only changes where it must, and the unsafe check renders each hole through the emitter itself, making it exact by construction. Everything else Pyfun emits is 3.10-compatible.

  • CLI: pyfun compile <file> --target 3.11|3.12 (default 3.12, help text updated)
  • Library: compile_targeting / project::compile_targeting (existing compile delegates)
  • Bench runner: --target 3.11 compiles into bench/out-3.11/
  • Tests: format-rewrite golden, safe-f-string-untouched, e2e run of rewritten output
  • INTERNALS.md: new emission-pass section

PyPy verification (the reason the switch exists)

PyPy 7.3.23 (pypy:3.11 container) runs the 3.11-target output with byte-identical results across the smoke test and full bench suite, and it is the best host measured for emitted Pyfun, cold:

benchmark PyPy CPython 3.14 speedup
expr_eval 0.525s 1.913s 3.6x
collatz 1.174s 1.732s 1.5x
map_build 0.428s 1.159s 2.7x

GraalPy's ADT-allocation pathology does not transfer (steady ~0.4s/iter on the warmup probe), and cold PyPy beats the mypyc-compiled expr_eval figure (0.525s vs 0.824s) with zero user toolchain. Weak spot: recursion (collatz 7.36x vs PyPy's own iterative baseline, though still faster than CPython in absolute terms). Full write-up in local/pypy-verification/ (untracked by design).

https://claude.ai/code/session_011PBhfjrzsUtwupYtJtzAWu

…host

Emitted code needed Python 3.12 for exactly one construct: f-string holes
carrying nested same-quote string literals or backslashes (PEP 701).
`pyfun compile --target 3.11` rewrites exactly those f-strings into
equivalent "template".format(args...) calls (src/python_emitter/py311.rs,
applied by emit_for on a clone of the IR, single-file and project paths);
clean f-strings stay f-strings, so output only changes where it must. The
unsafe check renders each hole through the emitter itself, so it is exact.

The switch unlocks PyPy (3.11 ceiling), which the same-day verification
crowns the best host measured for emitted Pyfun: 1.5-3.6x faster than
CPython 3.14 cold across the bench suite, byte-identical outputs, and none
of GraalPy's ADT-allocation pathology. bench/run.py grew --target (output in
bench/out-3.11/). Three new tests; INTERNALS + ROADMAP + bench README
updated.

Claude-Session: https://claude.ai/code/session_011PBhfjrzsUtwupYtJtzAWu
@simontreanor
simontreanor merged commit 6a446e0 into main Jul 18, 2026
11 checks passed
@simontreanor
simontreanor deleted the target-311 branch July 18, 2026 22:15
@simontreanor simontreanor mentioned this pull request Jul 18, 2026
simontreanor added a commit that referenced this pull request Jul 18, 2026
Ships the --target 3.11 emission switch (PyPy support) in the published
wheel. See the v0.1.1 tag and PR #7 for the feature itself.

Claude-Session: https://claude.ai/code/session_011PBhfjrzsUtwupYtJtzAWu
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