Skip to content

Prototype None-aware attribute access with ?. - #1

Draft
meanmail wants to merge 4 commits into
3.15from
meanmail/none-aware-access-3.15
Draft

meanmail wants to merge 4 commits into
3.15from
meanmail/none-aware-access-3.15

Conversation

@meanmail

@meanmail meanmail commented Oct 14, 2026 •

Copy link
Copy Markdown

This prototype adds ?. attribute access to CPython 3.15.0. user?.profile?.name checks each operand for None, skips the remaining attributes/calls/subscripts when a check fails, and evaluates each operand once. Other falsy values and ordinary exceptions retain their behavior; parentheses end the chain.

Every checked access now compiles to a dedicated stack-preserving JUMP_IF_NONE, with no COPY, temporary local or restriction to the first 16 local slots. Its JUMP_IF_NOT_NONE inverse supports CFG normalization. The change integrates instrumented branch events, branch-history caches, tier-two guards and reference analysis, and regenerates opcode/interpreter metadata and the frozen-main fixture. The fork's .pyc magic number changes from 3666 to 3667 because opcode numbering changes. It includes 38 feature tests and semantics/build/benchmark documentation in Doc/none-aware-prototype.md.

The branch starts at upstream v3.15.0 (d220409a13b77de7a6c30abe16ea90db01528edc). This PR targets the fork's 3.15 branch; main remains for upstream synchronization. This is a draft syntax experiment, not an upstream submission or a merge/deployment request. ?[...], ?(), ?? and ??= remain outside scope; IDEs, formatters and type checkers do not yet understand the new syntax.

Validation on macOS arm64:

  • Full debug-build suite: ./python.exe -E -Wd -m test -j8 -u all --timeout=900 --rerun --slowest, exit 0, FAILURE then SUCCESS. 53,158 test cases across all 558 test files; 478 files passed, 78 skipped and two resource-denied (test_xpickle, test_zipfile64); 2,607 skipped cases. The initial frozen-main failure was fixed by regenerating its stale bytecode fixture; two initial Tkinter failures passed automatic targeted rerun. Duration 14m16s. This was not a clean first-pass result.
  • Separate debug build with --enable-experimental-jit=interpreter: test_none_aware test_capi.test_opt test_monitoring test_sys_settrace -j2 --timeout=600 passed all four files: 890 cases, four skips. The mixed-chain test verifies actual executors contain the new stack-preserving guards.
  • Non-debug release build: 38 feature tests successful, with one tier-two skip. Coverage includes local slots 16/256, extended jump offsets, monitored branch outcomes and operand preservation under opcode tracing.
  • Ruff format and ruff check --fix --unsafe-fixes --preview pass on the changed tests. Configured mypy checks pass on Tools/cases_generator (19 files) and Tools/build (12 files).
  • Apple M3 Pro, non-debug -O3, no PGO/LTO: 51 shuffled rounds, one million calls per sample. Final medians (?. / explicit, ns per call): attribute/None 15.52/15.70; attribute/object 32.71/35.89; chain/None 15.50/16.36; chain/missing profile 34.00/38.63; chain/full object 48.96/51.95. These five microbenchmarks show no measured penalty against explicit checks; they do not establish universal zero overhead or whole-application speedups. Full methodology and comparison with the original COPY-based prototype are documented.

Native JIT machine-code generation, free-threaded builds and Linux/Windows remain unvalidated. The earlier 785 passing FinCtrl tests apply to the original prototype and were not repeated for the new opcode. Changes subsequently added to the target branch have not been tested together with this pinned 3.15.0 experiment.

@meanmail meanmail self-assigned this Oct 14, 2026
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