Repository navigation
Feat: Strings, subscripts, iteration and f-strings compile through the interpreter's C API; cost rule (#150) - #253
Merged
Merged
Conversation
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.
Closes #150. The wordfreq speedup it aimed at is blocked on #232; see below.
Feature added (each new operation calls the C API the interpreter's bytecode calls, so results, exceptions and user
__hash__/__eq__/__index__/__format__calls are identical):strconstants and f-strings (PyObject_Format,PyUnicode_Join);o[i],o[i] = v,in(PyObject_GetItem,PyObject_SetItem,PySequence_Contains);{}/[], andfor x in o/for a, b in owith CPython's unpacking errors;PyNumber_InPlace*). This also fixes a latent bug:lst += xwas lowered as a plain add.str + str.Cost rule (
typedpython/cost.py): an impure function that has loops, none of which does native work, stays interpreted, withpolicy/costand a reason. Straight-line impure functions keep compiling, as before.word_ofwas 2.6x slower compiled.PyNumber_*calls, while CPython 3.15 specialises the same code.benchmarks/typedpython/results/2026-10-17-wordfreq-object-mode.md. The real fix is TypedPython: native ints in impure functions, with in-place promotion on overflow #232.Tests added:
test_str_dict.py, 29 tests: differential against the interpreter for results, exception repr and user-hook call logs, plus mutation tests on the fast-path guards. Red before: 26 of 27 failed.test_cost_rule.py, 7 tests: the object-only loop stays interpreted, a native loop compiles, straight-line code compiles, callers of a rejected function are rejected, and a mutation that disables the rule fails. Red: 3 of 6 failed with the rule disabled.Tests changed: where a fact changed.
test_frontend:inplace=True.test_runtime: the invalid-op code moved from 9 to 12.test_verify_classes: a str constant is now valid.test_module_reportand thetest_pipeline*files: their "unsupported" example becames[1:].test_free_threaded: its fixture usescost_rule=False.Measured: wordfreq with the rule against develop is 1.003 (0.974 to 1.027), still 1.1x against CPython. No regression.
Verification (local, 3.15.0rc1t, numpy present):
drive,checked) still compiles.