Skip to content

bpo-29567: Allow argparse to be used in setup.py - #119

Closed
yan12125 wants to merge 1 commit into
python:masterfrom
yan12125:make-argparse-pure-python
Closed

yan12125 wants to merge 1 commit into
python:masterfrom
yan12125:make-argparse-pure-python

Conversation

@yan12125

Copy link
Copy Markdown
@brettcannon

Copy link
Copy Markdown
Member

Thanks for the pR, @yan12125 , but since this change adds a local import I would rather not accept it on its own but only as part of a larger patch that necessitated the actual change.

@yan12125
yan12125 deleted the make-argparse-pure-python branch February 16, 2017 09:48
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
…and thread safe

Store the return value during stack unwinding in the thread state instead of a global variable.
Change the macro STACKLESS_POSSIBLE() to disable nested stack unwinding.

https://bitbucket.org/stackless-dev/stackless/issues/119
(grafted from 7af03ffcfce3b00ad657ea957a7c1322b991fe6b)
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 24, 2026
Closes the SECOND pilot. Migrates the BasicBlock* → BytecodeInstructionBlock
mapping from std::unordered_map to a dense array indexed by BasicBlock::id,
exploiting the production-validated invariant that ids are
allocation-monotonic from 0 (cfg.h:139-144 `id = next_block_id_++`). Choice
of B-γ (dense array) over B-α (parallel hash) per theologian 11:13:21Z:
no hash, no collisions, no resize-on-load-factor — three classes of bug
B-α can have, B-γ cannot. Pattern is new (id-indexed dense array vs hash)
but well-suited to the data shape.

Combined with Phase A (push 39, 72bb8e9), block_map_ is ENTIRELY
migrated to PhxHirBuilderState. The wrapping BlockMap C++ struct + the
block_map_ C++ field are DELETED.

Net bridges: 0 (no new bridges; bc_blocks had zero C-side callers per
inventory). Per theologian 11:19:42Z: §5 python#11 prevents UNCONTROLLED bridge
growth, so a net-0 pilot is neither violation nor satisfaction — Phase B's
substantive deliverable is std::unordered_map elimination, which advances
the ZERO-C++ terminal goal equivalent to bridge subtraction.

PyCodeObject* code is constant per-compile and lives on
PhxHirBuilderState.code (set in HIRBuilder ctor), so it is not stored
per-array-slot — saves 8 bytes per block.

Three invariants asserted (theologian 11:13:21Z):
- I1 (JIT_DCHECK at createBlocks return): bc_block_array.count ==
  block_map_phx.count. The two are populated in lockstep on every loop
  iteration; counts must agree.
- I2 (JIT_DCHECK at buildHIRImpl read): tc.block->id <
  bc_block_array.count. Catches HIR-pass-created blocks accidentally
  being looked up; should never happen but assert it.
- I3 (documented, not asserted): BasicBlock::id is read-only post-
  allocation. No HIR pass renumbers ids; if any future pass does, B-γ
  is wrong. RPO and other passes traverse, never renumber. Runtime
  sentinel would defeat the dense-array O(1) win.

Lazy-grow uses single-realloc max(old_cap*2, block_id+1) per theologian
11:19:42Z verification (block_id=1000 with old_cap=16 is 1 alloc, not
7 doublings).

CALLER REWRITES (2 functional sites):
- builder.cpp createBlocks: writes both state_.block_map_phx (Phase A)
  and state_.bc_block_array_phx (Phase B) in lockstep. Return type
  void (was BlockMap).
- builder.cpp buildHIRImpl: read site reconstructs BytecodeInstructionBlock
  value from {code_, BCIndex{start}, BCIndex{end}} using array entry +
  state_.code (constant per-compile). Subsequent .begin/.end/iteration
  works on the local value identically to the old map-reference.

UNIT TESTS: +6 PhxBcBlockArray tests (init/insert+at/lazy-grow/n300/
clear/overwrite-same-id) appended to test_phx_block_map.c. Existing 8
PhxBlockMap tests unchanged.

GATE COVERAGE: the existing block_map_resize_chain wiring fixture (Phase A
push 39) exercises createBlocks which now populates BOTH structures in
lockstep, so PhxBcBlockArray growth is implicitly covered. Pythia python#119
(a) n=294 coverage extension is a separate followup commit (theologian
11:20:24Z + supervisor 11:20:43Z DEFERRED — sequence-isolated, not
bundled).

Auth chain: theologian B-γ pick 11:13:21Z + patch-shape APPROVE 11:19:42Z
(2 verifications applied at 11:20:15Z); supervisor 11:13:46Z + 11:18:54Z
+ 11:20:43Z; shepard sequence-isolation 11:11:59Z; librarian §5 python#11
non-violation framing 11:15:58Z.
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 24, 2026
Closes pythia python#119 (a) PhxBlockMap hash-clustering coverage gap deferred
from Phase A push 39 (theologian 11:20:24Z + supervisor 11:20:43Z DEFER:
separate from Phase B for clean revert boundary; sequence-isolated per
shepard 11:11:59Z).

Gap: the previous block_map_resize_chain (10 if-return arms,
~25 block_starts) trips PhxBlockMap_resize at insert python#12 but does not
exercise the 5 sequential resizes (16->32->64->128->256->512) that
re._parser:Tokenizer.__next at 294 blocks drives in production
(D2 measurement 2026-04-24).

Fix: add block_map_n294_chain — 110-arm if-return chain (~330 block_starts)
generated via exec to keep the source compact. force_compile must succeed
across n=0/54/109/200 (3 in-range hits + 1 default-arm miss); proves
Knuth multiplicative h=key*2654435761u clusters acceptably at production-
scale BCOffset density.

NO production code change. Pure test/fixture extension. Pre-commit
discipline satisfied via testkeeper bash -n syntax lint + diff-scope
confirmation (testkeeper 11:33:43Z): no C/C++ source touched, Phase B
binary 4145fe3 remains current.

Auth chain: theologian patch-shape APPROVE 11:33:03Z; testkeeper pre-
commit lint PASS 11:33:43Z.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants