Skip to content

Commit d81e580

Browse files
committed
test: canonicalize dk_version constant for cross-arch stability
ARM64 gate at 7a0c041 failed with diff: - v61:CUInt32[37] = LoadConst<CUInt32[37]> (x86_64) + v61:CUInt32[46] = LoadConst<CUInt32[46]> (ARM64) The CUInt32[N] constant is the `sys` module dict's `dk_version` — a monotonic counter bumped on every dict-key mutation. The value depends on how many key mutations happened during interpreter startup, which is architecture- and import-order dependent (x86_64 saw 37, ARM64 saw 46). Add a regex that canonicalizes `CUInt32[N]` (the only specialized type that can carry runtime dict-version state in the LoadAttr HIR). CUInt64[N] (slot count) and CInt64[N] (key hash / index) encode stable shape information from the class definition and are NOT canonicalized — divergence in those values is a real regression signal. Regenerated docs/golden/loadattr_hir.txt with the updated rule. Verified test PASSES on x86_64 at HEAD (run + verify cycle). ARM64 verification pending re-gate.
1 parent 7a0c041 commit d81e580

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

Lib/test/test_phoenix_jit_loadattr_golden.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,22 @@ def main():
135135
# stays stable.
136136
_PTR_RE = re.compile(r"0x[0-9a-fA-F]{6,}")
137137

138+
# LOAD_ATTR_MODULE embeds the module dict's `dk_version` (a monotonic
139+
# counter bumped on every dict-key mutation) into the HIR as
140+
# `LoadConst<CUInt32[N]>`. N depends on how many dict mutations happened
141+
# during interpreter startup, which is architecture- and import-order
142+
# dependent (x86_64 saw 37, ARM64 saw 46). Canonicalize the embedded
143+
# integer on `CUInt32[N]` annotations so the golden stays cross-arch
144+
# stable. Other integer-specialized constant types (CUInt64[N], CInt64[N])
145+
# encode stable shape information (slot index, key hash) and are NOT
146+
# canonicalized — divergence in those values is a real regression signal.
147+
_DK_VERSION_RE = re.compile(r"CUInt32\[\d+\]")
148+
138149

139150
def _canonicalize(text: str) -> str:
140-
return _PTR_RE.sub("0xPTR", text)
151+
text = _PTR_RE.sub("0xPTR", text)
152+
text = _DK_VERSION_RE.sub("CUInt32[N]", text)
153+
return text
141154

142155

143156
def _extract_blocks(stderr_text: str) -> str:

docs/golden/loadattr_hir.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fun __main__:attr_probe {
7878
v59:CPtr = LoadField<ma_keys@32, CPtr, owned> v58
7979
Decref v58
8080
v60:CUInt32 = LoadField<dk_version@12, CUInt32, owned> v59
81-
v61:CUInt32[37] = LoadConst<CUInt32[37]>
81+
v61:CUInt32[N] = LoadConst<CUInt32[N]>
8282
v62:CBool = PrimitiveCompare<Equal> v60 v61
8383
Guard v62 {
8484
LiveValues<7> b:v29 b:v30 unc:v32 o:v42 o:v53 b:v56 bool:v62
@@ -222,7 +222,7 @@ fun __main__:attr_probe {
222222
v59:CPtr = LoadField<ma_keys@32, CPtr, owned> v58
223223
Decref v58
224224
v60:CUInt32 = LoadField<dk_version@12, CUInt32, owned> v59
225-
v61:CUInt32[37] = LoadConst<CUInt32[37]>
225+
v61:CUInt32[N] = LoadConst<CUInt32[N]>
226226
v62:CBool = PrimitiveCompare<Equal> v60 v61
227227
Guard v62 {
228228
LiveValues<7> b:v29 b:v30 unc:v32 o:v42 o:v53 b:v56 bool:v62

0 commit comments

Comments
 (0)