Skip to content

bpo-29474: Improve documentation for weakref.WeakValueDictionary#11

Merged
zware merged 1 commit intopython:2.7from
Mariatta:bpo-29474py2
Feb 11, 2017
Merged

bpo-29474: Improve documentation for weakref.WeakValueDictionary#11
zware merged 1 commit intopython:2.7from
Mariatta:bpo-29474py2

Conversation

@Mariatta
Copy link
Copy Markdown
Member

There were some grammatical errors in weakref.WeakValueDictionary
documentation.

This is to be applied to 2.7

There were some grammatical errors in weakref.WeakValueDictionary
documentation.

This is to be applied to 2.7
Copy link
Copy Markdown
Member

@zware zware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting that the sentence makes sense in context, this does indeed fix the grammar. LGTM.

@zware zware merged commit 5c32988 into python:2.7 Feb 11, 2017
@Mariatta Mariatta deleted the bpo-29474py2 branch February 12, 2017 04:10
@Mariatta
Copy link
Copy Markdown
Member Author

Thanks for the reviews, @zware :)

paulmon added a commit to paulmon/cpython that referenced this pull request Jan 10, 2019
emmatyping referenced this pull request in emmatyping/cpython Feb 24, 2020
nanjekyejoannah added a commit to nanjekyejoannah/cpython that referenced this pull request Nov 17, 2022
11: Warn for function attributes r=ltratt a=nanjekyejoannah

Warn for function attributes

Co-authored-by: Joannah Nanjekye <jnanjekye@python.org>
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 22, 2026
Symmetric defense to e808676 — guards against any future ARM64
build-pipeline refactor (e.g., switching to cp-and-cache for build
speed) silently regressing the binary-identity property.

Today the ARM64 chain (cmake clean → fetch → checkout → build → test
in same repo) inherently couples binary identity to checked-out
commit, so the check is belt-and-suspenders. Per theologian
2026-04-22 00:47:10Z: the defense-in-depth value is in preventing
future regression of the safety property, not in catching today's
bugs.

After build_phoenix.sh + chmod +x python:
  - capture sys.version of the freshly-built binary
  - grep for $ARM64_COMMIT (the just-checked-out short hash)
  - exit 99 if absent, with explicit ARM64_BINARY_MISMATCH message

Existing 'ARM64_REMOTE_FAIL' cascade catches the non-zero exit and
fails the gate. Transcript carries verbatim ARM64_BINARY_MATCH or
ARM64_BINARY_MISMATCH for gatekeeper item python#11 verification.
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 22, 2026
Push 42 (84/144 → 85/144 emit methods, 59%): bundles SLOT-specialization
conversion + bridge-guard fix per supervisor 01:39:54Z + theologian
01:40:13Z + gatekeeper 01:39:47Z delegation-approach concurrence.

================================================================
PART 1: BRIDGE GUARD FIX (delegation, not port)
================================================================

hir_c_api.cpp: replace broken findTypeByVersionTagWalk with 1-line
delegation to jit::hir::findTypeByVersionTag (builder.cpp:3829).

The prior in-file walk stripped 6 invariants from the C++ source +
missed the static-builtin indirection (getTypeSubclasses helper).
testkeeper caught it as SIGSEGV during cinderjit.force_compile(attr_probe)
post-warmup at 00:41Z (gate-binary contamination investigation).

Delegation chosen over verbatim port because invariants cannot be
stripped from a delegation: there is no copy. Future C++ retrofits
propagate automatically (e.g., D-1775642552 collision diagnostic when
implemented). Full BRIDGE SPEC TEMPLATE below.

----------------------------------------------------------------
BRIDGE SPEC TEMPLATE (theologian 01:39:09Z, archived as W7 reference)
----------------------------------------------------------------

Bridge: hir_find_type_by_version_tag
Purpose: Walk PyType subclass tree from PyBaseObject_Type, return type
         matching version_tag (or NULL). Used by LOAD_ATTR_SLOT to
         resolve slot_type from inline-cache version.
C++ source: builder.cpp:3795-3833 (findTypeByVersionTagImpl +
            findTypeByVersionTag + getTypeSubclasses)

PRIOR DECISIONS (scribe 01:37:08Z):
  D-1775580885: pymalloc reentrancy via Python __subclasses__ callback
                during HIR build. Bridge MUST NOT invoke Python during
                compile. (Inherited via delegation: C++ uses PyDict_Next
                + PyWeakref_GetObject, no Python call.)

  D-1775636801, D-1775636859: tp_subclasses for static builtin types
                (TPFLAGS_STATIC_BUILTIN: object, int, str) is a 1-based
                index into PyInterpreterState array, NOT a dict pointer.
                Direct tp_subclasses access = dead code on PyBaseObject_Type
                (the walk root). MUST use _PyStaticType_GetState. (Inherited
                via delegation: C++ getTypeSubclasses helper handles this.)

  D-1775637417: Zero-allocation walk crashed on ARM64 in prior session
                due to _PyType_GetSubclasses() PyList_New temp allocation.
                Current C++ uses PyDict_Next directly (no temp alloc).
                (Inherited via delegation; ARM64 pre-flight at 01:43Z
                confirms the fix is holding under RelWithDebInfo.)

  D-1775642552: Version-tag collision is an UNRESOLVED hypothesis class.
                If two types share a version_tag, walk returns wrong type
                → in auto-compile receiver matches → LoadField at wrong
                slot_offset → corruption. Diagnostic logging is a separate
                W-tracked workstream, not bridge-impl scope. (Inherited.)

INVARIANTS PRESERVED (via delegation, no copy — strongest preservation):
  1. Depth limit 50 (builder.cpp:3799) — prevents stack overflow on
     cyclic / very-deep subclass graphs.
  2. version == 0 short-circuit (builder.cpp:3830) — sentinel handling
     for the unspecialized version-tag value.
  3. PyDict_Check before PyDict_Next (builder.cpp:3810) — tp_subclasses
     may be NULL or non-dict for some types; PyDict_Next on non-dict is UB.
  4. PyType_Check on weakref-resolved subtype (builder.cpp:3817) — weakref
     may resolve to non-type if the subclass was gc'd or list contaminated.
  5. PyWeakref_GetObject (G form, NULL-safe) instead of _GET_OBJECT macro
     (builder.cpp:3816) — assumes-weakref macro returns Py_None on NULL
     but UB if argument isn't a weakref.
  6. _PyStaticType_GetState indirection for TPFLAGS_STATIC_BUILTIN
     (builder.cpp:3786-3793) — PyBaseObject_Type IS static-builtin; without
     this, walk dies at root.
  7. PyDict_Next direct iteration — zero pymalloc allocation in walk body
     (NOT _PyType_GetSubclasses which allocates via PyList_New). Required
     for ARM64 safety per D-1775637417.

Falsifier:
  - cinderjit.force_compile(attr_probe-with-warmup) on x86_64 completes
    without SIGSEGV. (Verified compile-clean; gate result follows.)
  - Same on ARM64 RelWithDebInfo per testkeeper pre-flight 01:43:22Z PASS:
    'JIT_ENABLE=1 ./python /tmp/g1_6_force.py → FORCE_COMPILE_OK ✓'
    'JIT_ENABLE=1 ./python /tmp/g1_5_auto_compile_capture.py → AUTO_COMPILE_OK ✓'

W7 — full C port of findTypeByVersionTag (post-Tier-5, MEDIUM, queued):
  Owner: theologian design (this spec) + generalist implement
  Trigger: when builder.cpp deletion approaches AND findTypeByVersionTag
           chain is the next C++ surface to convert
  Acceptance: this 7-invariant spec satisfied + ARM64 pydebug pre-flight
              PASS (W8 must complete first) + post-port differential
              JIT_DCHECK PASS

================================================================
PART 2: LOAD_ATTR_SLOT WIRING
================================================================

builder_emit_c.c: hir_builder_emit_load_attr_slot_c, ~42 lines.
builder.cpp: emitLoadAttr LOAD_ATTR_SLOT case shrinks to delegating stub
(46 lines deleted, 6 lines added).

----------------------------------------------------------------
PER-SPECIALIZATION RUBRIC (theologian 00:24:00Z, 8 common + 4 SLOT)
----------------------------------------------------------------

Common items (cited per gatekeeper review):

1. Source structural diff: C body in builder_emit_c.c mirrors C++ logic
   line-for-line (cache lookup → type guard → load slot → check NULL).
   C++ stub in builder.cpp passes (tc, func, builder, receiver, code,
   name_idx, instr_idx); C body returns 1 on success / 0 to fall back.

2. Bridge usage audit:
   - hir_builder_get_attr_cache(builder, instr_idx, &type_version, &slot_offset)
     [hir_c_api.cpp:2653, reads _PyAttrCache via Preloader's code]
   - hir_find_type_by_version_tag(type_version) [delegation, see Part 1]
   - hir_func_add_reference(func, slot_type) [hir_c_api.cpp:168, roots
     the type pointer through GC for compiled-code lifetime]
   - hir_type_from_pytype(slot_type, 1) [exact-type HirType construction]
   - hir_c_create_guard_type_reg(receiver, type, receiver) [no-FS variant
     matches C++ tc.emitGuardType 3-arg form at builder.cpp:3964]
   - hir_func_alloc_register, hir_c_create_load_field_reg,
     hir_c_create_check_field_reg, hir_c_set_guilty_reg
   All bridges exist; ordering matches C++.

3. Reference annotation: receiver is BORROWED (read from stack),
   guarded result is the same register (in-place narrow), LoadField
   result is owned-or-NULL (TOptObject = OBJECT|NULLPTR), CheckField
   raises AttributeError on NULL via guilty_reg=receiver. Matches C++.

4. FrameState capture: GuardType uses no-FS variant (matches C++ which
   also calls 3-arg tc.emitGuardType for SLOT). CheckField uses FS-aware
   variant (hir_c_create_check_field_reg with &tc->frame). Snapshot is
   not explicitly emitted; the existing tc.frame supplies state for
   CheckField deopt.

5. Wiring exercise: existing emitCond wiring at gate_phoenix.sh:347
   exercises Point class with .x/.y/.z dict-attrs (not __slots__). For
   __slots__ specifically, the existing test_phoenix_jit_loadattr_golden
   harness (Lib/test/test_phoenix_jit_loadattr_golden.py) exercises the
   exact attr_probe pattern (Pt with __slots__) — gate_phoenix.sh runs
   this in PHOENIX_MODULES.

6. Golden diff exact match (HARD GATE): docs/golden/loadattr_hir.txt
   captured at C++ baseline (push 35 aa430e6). After this push, the
   SLOT block of the golden must remain byte-identical. testkeeper to
   re-run test_phoenix_jit_loadattr_golden and post the diff result —
   if non-empty, HALT push 42.

7. Py_REF_DEBUG delta: this is the FIRST LoadAttr conversion; baseline
   from C++ = +1772 (per supervisor 00:00:17Z). After SLOT lands, run
   pydebug Python with sys.gettotalrefcount() before/after the LoadAttr
   test suite, post delta. Must be within 5% of +1772 baseline.

8. ARM64 commit-match + 4 stash markers: per gatekeeper item python#11,
   testkeeper's gate excerpt must show BOTH BINARY_MATCH (clean) lines
   + commit-match + stash markers. Standard discipline.

SLOT-specific items:

S1. Slot offset comes from _PyAttrCache->index via hir_builder_get_attr_cache
    bridge (NOT hand-coded). The cache is the canonical CPython source for
    LOAD_ATTR_SLOT specialization data. Matches C++ behavior at builder.cpp:3946.

S2. LoadField uses TOptObject (OBJECT|NULLPTR) for the slot output type,
    matching C++ tc.emitLoadField(attr, receiver, "slot", slot_offset, TOptObject)
    at builder.cpp:3970. Constructed via hir_type_union(HIR_TYPE_OBJECT,
    HIR_TYPE_NULLPTR) — semantic equivalent of C++ TOptObject.

S3. Subclass check: C version returns 0 (fallback to generic LoadAttr) if
    slot_type has subclasses (PyDict_GET_SIZE(tp_subclasses) > 0). Matches
    C++ guard at builder.cpp:3956 — without the subclass check, GuardType
    against a parent type would fail when receiver is a subclass instance,
    causing unnecessary deopt.

S4. dk_version Guard (per theologian rubric): for SLOT specifically, the
    GuardType against slot_type SERVES the version-check role. CPython's
    _PyAttrCache->version is checked at adaptive-specializer time to set
    LOAD_ATTR_SLOT; the JIT GuardType then ensures the runtime receiver
    type matches what was cached. This satisfies S4 in spirit (type-version
    guard precedes LoadField), even though the constant materialization is
    not via separate Guard<dk_version> instruction.

================================================================
VERIFICATION (compile-clean pre-commit)
================================================================

cmake --build Python/jit_build/build --target phoenix_jit:
  [ 96%] Built target jit
  [100%] Built target phoenix_jit
  0 errors. Pre-existing warnings only.

Pre-flight ARM64 (testkeeper 01:43:22Z, RelWithDebInfo PASS at HEAD ae8224e):
  - JIT_ENABLE=1 ./python /tmp/g1_6_force.py → FORCE_COMPILE_OK ✓
  - JIT_ENABLE=1 ./python /tmp/g1_5_auto_compile_capture.py → AUTO_COMPILE_OK ✓
  - D-1775637417 fix is holding for production C++ findTypeByVersionTag
    on ARM64. Delegation inherits this safety.

Pydebug ARM64 deferred to W8 per supervisor 01:45:32Z (pre-existing
libfmt.a linker issue, separate from SLOT scope).

Diff stat: 3 files changed, 56 insertions(+), 62 deletions(-).
  builder.cpp: -46 +6 (LOAD_ATTR_SLOT case → delegating stub)
  builder_emit_c.c: +42 (hir_builder_emit_load_attr_slot_c)
  hir_c_api.cpp: -16 +6 (broken walk → delegation)
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 24, 2026
…DE.md

Bundle of two theologian-authored doc amendments per supervisor
dispositions:

CLAUDE.md (+2L) — Pre-Edit WT Integrity 'undiagnosed-recurring'
honest framing per pythia python#105 (3) + supervisor 02:13:12Z + theologian
02:13:54Z. Acknowledges 5+ prior incidents closed at SYMPTOM layer
without root-cause attribution; this 4-step discipline codifies
reactive HALT, not automated detection. Detection still depends on
agent noticing mid-edit. Recurrence-prevention claim does not exceed
what text mechanizes; automated detection feasibility (file-watcher /
git-hook) is fixup PIR territory and remains open.

docs/tier8-class-b-cport-migrate-arm-spec.md (+93/-20) — pythia python#104
amendments per theologian 01:38:08Z + supervisor 01:38:26Z + 01:37:05Z:
  §1.1 container-shape transferability caveat (vector-pilot ≠ hash/
       stack/allocator-shape pattern transferability)
  §5 python#11 NEW: bridge-count-delta acceptance (each pilot must NET-
       SUBTRACT bridges OR honestly add with W45 fixture coverage)
  §5 python#12 NEW: Phase B FORCING-FUNCTION (Tier 8 SECOND-PILOT block_map_
       Step A BLOCKED until exception_table_ Phase B commit lands)

Bundle scope: doc-only, no §3.5 BUILD MODE (no builder*.{cpp,h,c}
touched). Atomic per supervisor 02:13:12Z + 01:38:26Z dispositions.

Push 28 advances the Tier 8 Phase A resume deadline tracker per
theologian 02:13:54Z + supervisor 02:13:12Z (push 28 OR session-end
whichever first). If Alex disposition + fixup PIR not received by
deadline, theologian amends Phase 3 closure summary fa8dfef to
remove Tier 8 pilot citation + re-opens pythia python#103 escape question.
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 24, 2026
Per docs/tier8-class-b-cport-migrate-arm-spec.md theologian 01:01:50Z +
supervisor 01:02:46Z ADOPTED + supervisor 01:18:35Z + 03:44:19Z +
04:14:27Z (8-incident root-cause attribution to §3.5 restore-trap +
b83f084 fix LIVE).

Migrates HIRBuilder std::vector<ExceptionTableEntry> exception_table_
field to PhxExceptionTable (purpose-built typed-inline pure-C
container in PhxHirBuilderState.exception_table_phx). Validates
Pythia python#103 + python#94 (3) §5 forcing-decision MIGRATE-ARM via 1-pilot
port (vs Phase 3's 4-Class-B-kept disposition).

CONTAINER:
  PhxExceptionTable (builder_state_c.h): typed-inline data/count/capacity
  with 6 inline funcs (init/destroy/push/size/at/clear). Lazy-init,
  doubling realloc, free at HIRBuilder dtor.
  ExceptionTableEntry (builder_state_c.h): POD mirror of deleted C++
  struct, fields flattened BCOffset → int + bool → unsigned char.

C BODY PORTS (builder_state_c.c):
  hir_builder_state_init: also calls phx_exception_table_init
  hir_builder_state_destroy: NEW (calls phx_exception_table_destroy)
  parse_exception_table_c: pushes ExceptionTableEntry via
    phx_exception_table_push (replaces deleted push_cpp bridge)
  find_exception_handler_c: linear scan via phx_exception_table_size +
    at (replaces deleted size_cpp/entry_cpp bridges)

C++ SHIM (transient compatibility per Phase A; Phase B deletes):
  HIRBuilder::parseExceptionTable → 1-line delegate to C body
  HIRBuilder::findExceptionHandler → C body returns index, shim
    converts via phx_exception_table_at preserving caller-contract
  HIRBuilder::buildHIRImpl translate-loop iterates PhxExceptionTable
    via size+at; .clear() goes to phx_exception_table_clear
  HIRBuilder::getSimpleExceptInfo wraps handler.target in BCOffset{}
    (now plain int post-C struct migration)
  emit_call_method_exception_handler_inline_c at builder.cpp:2883
    still calls self->findExceptionHandler (KEPT shim — Phase B
    will rewire)

DELETED:
  3 _cpp bridge impls in builder.cpp (push/size/entry, ~37L)
  3 friend decls in builder.h
  C++ struct ExceptionTableEntry in builder.h (5L)
  std::vector<ExceptionTableEntry> exception_table_ field in builder.h

W45 §1-§2 fixture removals (3): the deleted bridges no longer have
signatures to fuzz. Cumulative bridge-count delta: -3 (per Tier 8
spec §5 python#11 acceptance).

Numstat (vs HEAD b83f084):
  Python/jit/hir/builder.cpp           +21 -44   (-23 NET)
  Python/jit/hir/builder.h             +14 -19   (-5 NET)
  Python/jit/hir/builder_state_c.c     +30 -17   (+13 NET)
  Python/jit/hir/builder_state_c.h     +103 -48  (+55 NET)
  scripts/w45_bridge_drift_falsifier.sh +0 -3    (-3 NET)
TOTAL: NET +37L, bridge-count delta -3.

Per Tier 8 spec §5 python#10 amendment (theologian 01:14:29Z): full Tier 8
endpoint ≤+0L cumulative is across all 4 Class B containers, not
single pilot. exception_table_ pilot subtracts ~19% of Phase 3 +257L
foundation cost; Phase 3 + Tier 8 Phase A cumulative now +257 + 37 =
+294L.

Apply mechanism: python single-process write (8-incident root cause
was §3.5 restore-trap, NOT Write-tool-burst — but python single-process
remains best practice per Pythia python#107 (4) isolation principle). Apply
script: /tmp/apply_phase_a.py.

EXPANDED PRE-COMMIT GATE per supervisor 01:17:23Z (testkeeper 04:24:49Z):
  Stage 1 compile-check: BUILD_EXIT=0
  Stage 2 §3.5 BUILD MODE: 4/4 PASS, PhxExceptionTable INTACT post
    (§3.5 fix b83f084 VINDICATED)
  Stage 3 per-bench gate: GEO 1.27x, all 4 floor criteria PASS

§5 forcing-decision MIGRATE-ARM EMPIRICALLY VALIDATED via this pilot:
exception_table_ migrated to PhxArray-equivalent pure-C container
without C++-side-keep dependency in C-side reads. Pattern propagatable
to remaining 3 Class B containers (block_map_, temps_,
static_method_stack_) in future Tier 8 batches per spec §1.1
container-shape transferability caveat.

Phase B follow-up commit (NEXT) deletes C++ shims + rewires the
remaining caller at builder.cpp:2883 per Tier 8 spec §5 python#5.

Authorization: supervisor 03:44:19Z + 04:14:27Z; theologian 03:33:50Z
patch-apply hybrid + 03:54:15Z content-trigger refinement (later
attributed to §3.5 trap, not content) + 04:14:27Z fix directive.

Cross-link: 8 incidents resolved via b83f084 §3.5 restore-trap fix.
Pythia python#105 'fever has name infection still spreads' RESOLVED — fever
was self-inflicted instrumentation. W48 spec marked CANCELLED post-
this-commit per supervisor 04:14:27Z cascade re-retract.
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 24, 2026
Per Tier 8 spec §5 python#5 + theologian 04:48:17Z + supervisor 04:48:47Z.
Completes the exception_table_ pilot started in Phase A (6945b96)
by deleting the transient C++ compatibility layer.

DELETED:
  HIRBuilder::parseExceptionTable shim (builder.cpp:1243-1245 area
    + builder.h decl)
  HIRBuilder::findExceptionHandler shim (builder.cpp:1247-1258 area
    + builder.h decl)

REWIRED:
  builder.cpp:1197 (translate setup) → inline call
    hir_builder_state_parse_exception_table_c(&state_, this)
  builder.cpp:2865 (emit_call_method_exception_handler_inline_c) →
    inline call hir_builder_state_find_exception_handler_c +
    phx_exception_table_at conversion preserves caller-contract

HIRBuilder no longer has any accessor methods for exception_table_phx;
all access via bridges (parse_exception_table_c +
find_exception_handler_c + phx_exception_table_at). §5 python#5 acceptance
criterion fully satisfied. ZERO new bridges (uses existing C bodies
+ inline phx_exception_table_at helper).

Numstat (vs HEAD f33bde6):
  Python/jit/hir/builder.cpp +22 -27  (-5 NET)
  Python/jit/hir/builder.h   +5  -10  (-5 NET)
TOTAL: NET -10L, bridge-count delta 0, fixture delta 0.

Per Tier 8 spec §5 python#11 acceptance: ZERO bridge additions ✓.
Per Tier 8 spec §5 python#12 forcing-function: this commit IS the Phase B
landing; block_map_ Phase A Step A NOW UNBLOCKED for next session.

EXPANDED PRE-COMMIT GATE per supervisor 01:17:23Z (testkeeper
04:57:42Z):
  Stage 1 compile: BUILD_EXIT=0
  Stage 2 §3.5 BUILD MODE: 4/4 PASS, post-restore clean, staged
    content INTACT (§3.5 fix b83f084 VINDICATED — cpp/h mtimes
    identical pre/post all 3 stages)
  Stage 3 per-bench gate: GEO 1.26x, all 4 floor criteria PASS
    (worst single-bench gen_simple 0.70x > 0.5x absolute floor)

Phase 3 + Tier 8 (Phase A + B) cumulative: +257 + 37 - 10 = +284L.
exception_table_ pilot COMPLETE — first Class B container fully
migrated to pure-C with no C++-side accessor residue.

Authorization: theologian 04:48:17Z cross-check + supervisor
04:48:47Z Step B GO + librarian 04:51:37Z broader sister-script
audit CLEAN.
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.

3 participants