Skip to content

Feat: Strings, subscripts, iteration and f-strings compile through the interpreter's C API; cost rule (#150) - #253

Merged
b-re-w merged 5 commits into
developfrom
feat/tp-dict-str
Oct 17, 2026
Merged

b-re-w merged 5 commits into
developfrom
feat/tp-dict-str

Conversation

@b-re-w

@b-re-w b-re-w commented Oct 17, 2026

Copy link
Copy Markdown
Member

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):

  • str constants and f-strings (PyObject_Format, PyUnicode_Join);
  • o[i], o[i] = v, in (PyObject_GetItem, PyObject_SetItem, PySequence_Contains);
  • empty {}/[], and for x in o / for a, b in o with CPython's unpacking errors;
  • in-place augmented assignment on objects (PyNumber_InPlace*). This also fixes a latent bug: lst += x was lowered as a plain add.
  • Exact-type fast paths, each calling the same C function the generic path ends in: exact-dict get and set, and exact str + str.

Cost rule (typedpython/cost.py): an impure function that has loops, none of which does native work, stays interpreted, with policy/cost and a reason. Straight-line impure functions keep compiling, as before.

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_report and the test_pipeline* files: their "unsupported" example became s[1:].
  • test_free_threaded: its fixture uses cost_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):

  • Full suite: 1174 passed, 3 skipped.
  • The five benchmarks compile the same sets as develop. The Kotlin bridge fixture (drive, checked) still compiles.

@b-re-w
b-re-w merged commit 913ab17 into develop Oct 17, 2026
@b-re-w
b-re-w deleted the feat/tp-dict-str branch October 17, 2026 13:44
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