Commit f0891d7
committed
builder: LOAD_ATTR_MODULE + LOAD_ATTR_INSTANCE_VALUE in C
Push 43 (85/144 → 87/144 emit methods, 60.4%): bundles MODULE +
INSTANCE_VALUE specialization conversion + 1 thin-wrapper bridge accessor
per supervisor 02:11:09Z bundle decision + theologian 02:10:50Z concur.
Re-audit at 02:09:21Z found that 4 of 5 originally-identified "new"
bridges already exist (hir_c_create_bit_cast, hir_c_create_int_binary_op,
hir_c_set_descr, hir_c_set_guilty_reg) — only ~5 LOC of new infra
needed (jit_rt_load_module_dict_entry_addr accessor).
================================================================
PART 1: BRIDGE ACCESSOR (LITE TEMPLATE)
================================================================
Bridge: jit_rt_load_module_dict_entry_addr
Purpose: extern C accessor returning JITRT_LoadModuleDictEntry function
pointer for CallStatic in LOAD_ATTR_MODULE.
C++ source: Python/jit/jit_rt.h:656 (declaration), jit_rt.cpp:2587 (defn)
PRIOR DECISIONS: NONE (mirrors existing jit_rt_invoke_iter_next_addr)
INVARIANTS PRESERVED:
1. Returns the unwrapped C++ function pointer (no copy, no transformation)
2. Function signature: (PyDictKeysObject* keys, Py_ssize_t index) → PyObject*
3. Caller must pass exactly 2 operands to CallStatic (keys, index)
Falsifier: bridge result called via CallStatic with valid (keys, index)
returns the dict entry; mismatch indicates bridge returned wrong pointer.
================================================================
PART 2: LOAD_ATTR_MODULE WIRING
================================================================
builder_emit_c.c: hir_builder_emit_load_attr_module_c, ~70 lines.
builder.cpp: emitLoadAttr LOAD_ATTR_MODULE case shrinks to delegating
stub (66 lines deleted, 7 lines added).
Per-spec rubric (theologian 00:24:00Z + 02:06:35Z):
Common items:
C1. Source structural diff: C body mirrors C++ logic line-for-line
(guard module type → cache lookup → dict_version!=0 fast path →
load md_dict/ma_keys/dk_version → version Guard → CallStatic
JITRT_LoadModuleDictEntry → CheckField).
C2. Bridge usage audit: hir_c_create_guard_type_reg, hir_c_create_load_field_reg,
hir_c_create_load_const, hir_c_create_primitive_compare,
hir_c_create_guard + hir_deopt_set_frame_state, hir_c_create_call_static_reg
+ hir_c_set_operand, hir_c_create_check_field_reg + hir_c_set_guilty_reg.
All bridges exist; ordering matches C++.
C3. Reference annotation: receiver borrowed; intermediates (dict, keys,
loaded_version) typed correctly per C++ original; result is OBJECT|NULL
from CallStatic, narrowed to OBJECT by CheckField.
C4. FrameState capture: emitSnapshot is in builder.cpp before the switch
(unchanged); Guard + CheckField receive &tc->frame.
C5. Wiring exercise: test_phoenix_jit_loadattr_golden harness exercises
sys.maxsize (LOAD_ATTR_MODULE) — covered.
C6. Golden diff exact match (HARD GATE): MODULE block of
docs/golden/loadattr_hir.txt must remain byte-identical.
test_phoenix_jit_loadattr_golden internally diffs.
C7. Py_REF_DEBUG delta: deferred per W8 retroactive trigger
(pydebug infra block, supervisor 01:53:52Z).
C8. ARM64 commit-match + 4 stash markers + BINARY_MATCH (clean) on
both arches: testkeeper to verify.
MODULE-specific items:
M1. CallStatic argument order EXACTLY matches C++: (keys, index_reg)
via hir_c_set_operand(call, 0, keys) + hir_c_set_operand(call, 1, index_reg).
M2. CheckField fallback target is the DEOPT path (FrameState replay),
NOT raise-NameError directly. Achieved via hir_c_create_check_field_reg
+ tc->frame.
M3. guiltyReg attached to CheckField via hir_c_set_guilty_reg(cf, receiver)
for nice runtime errors.
================================================================
PART 3: LOAD_ATTR_INSTANCE_VALUE WIRING
================================================================
builder_emit_c.c: hir_builder_emit_load_attr_instance_value_c, ~92 lines.
builder.cpp: emitLoadAttr LOAD_ATTR_INSTANCE_VALUE case shrinks to delegating
stub (98 lines deleted, 7 lines added).
Per-spec rubric:
Common items C1-C8 same pattern as MODULE; key differences:
C1. Mirrors C++ split-dict path: guard slot_type → load dorv from
managed-dict slot (offset -3*sizeof(PyObject*)) → CheckField NULL
→ BitCast dorv to CUInt64 → IntBinaryOp kAnd 1 (low-bit test) →
Guard with descr "dict values check" → IntBinaryOp kAdd 1 (strip tag)
→ BitCast to OptObject → LoadField at index*sizeof(PyObject*) →
CheckField NULL.
C3. dorv loaded with borrowed=1 (matches C++ — dorv may be tagged pointer,
not valid PyObject*); attr loaded as OptObject (becomes owned via
CheckField narrowing, then refcount_insertion adds Incref).
INSTANCE_VALUE-specific items:
V1. Dispatch: handles split-dict (managed_dict + values pointer) ONLY,
regular __dict__ deopts via Guard "dict values check". Matches C++
single-branch pattern.
V2. Values-pointer offset embedded as CUInt64[1] (the constant 1 used
in the AND mask + tag-strip add). Code-state, preserved by
canonicalization rule (NOT CUInt32 which is dk_version).
V3. Py_NewRef on loaded value: handled implicitly by LoadField OptObject
type; refcount_insertion pass adds Incref after CheckField result.
Verify by checking golden HIR shows Incref after LoadField in the
INSTANCE_VALUE block.
Static-builtin / subclass-fallback semantics: matches C++ early-return
behavior — if slot_type lookup fails OR has subclasses OR lacks
TPFLAGS_MANAGED_DICT OR ht_cached_keys is NULL, returns 0 (fallback to
generic LoadAttr). Optionally emits GuardType-only as the C++ does.
================================================================
VERIFICATION (compile-clean pre-commit)
================================================================
cmake --build phoenix_jit: PASS, 0 errors (warnings pre-existing).
make python: link PASS (no undefined references).
Includes added to builder_emit_c.c:
- internal/pycore_moduleobject.h (PyModuleObject)
- internal/pycore_dict.h (PyDictKeysObject)
Diff stat:
Python/jit/hir/builder.cpp | -159 +11 (-148 net, MODULE+INSTANCE_VALUE → stubs)
Python/jit/hir/builder_emit_c.c | +163 (MODULE wiring + INSTANCE_VALUE wiring + extern decls)
Python/jit/hir/hir_c_api.cpp | +4 (jit_rt_load_module_dict_entry_addr)
Python/jit/hir/hir_c_api.h | +6 (accessor declaration + doc)
4 files changed, 184 insertions(+), 158 deletions(-)
Item 6 HARD GATE: testkeeper to re-capture loadattr_hir.txt and verify
MODULE + INSTANCE_VALUE blocks byte-identical to C++ baseline. If either
block diverges, HALT push 43.
Item 7 deferred per W8 retroactive trigger.1 parent 8f9642d commit f0891d7
4 files changed
Lines changed: 184 additions & 158 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3849 | 3849 | | |
3850 | 3850 | | |
3851 | 3851 | | |
| 3852 | + | |
| 3853 | + | |
3852 | 3854 | | |
3853 | 3855 | | |
3854 | 3856 | | |
| |||
3874 | 3876 | | |
3875 | 3877 | | |
3876 | 3878 | | |
3877 | | - | |
3878 | | - | |
3879 | | - | |
3880 | | - | |
3881 | | - | |
3882 | | - | |
3883 | | - | |
3884 | | - | |
3885 | | - | |
3886 | | - | |
3887 | | - | |
3888 | | - | |
3889 | | - | |
3890 | | - | |
3891 | | - | |
3892 | | - | |
3893 | | - | |
3894 | | - | |
3895 | | - | |
3896 | | - | |
3897 | | - | |
3898 | | - | |
3899 | | - | |
3900 | | - | |
3901 | | - | |
3902 | | - | |
3903 | | - | |
3904 | | - | |
3905 | | - | |
3906 | | - | |
3907 | | - | |
3908 | | - | |
3909 | | - | |
3910 | | - | |
3911 | | - | |
3912 | | - | |
3913 | | - | |
3914 | | - | |
3915 | | - | |
3916 | | - | |
3917 | | - | |
3918 | | - | |
3919 | | - | |
3920 | | - | |
3921 | | - | |
3922 | | - | |
3923 | | - | |
3924 | | - | |
3925 | | - | |
3926 | | - | |
3927 | | - | |
3928 | | - | |
3929 | | - | |
3930 | | - | |
3931 | | - | |
3932 | | - | |
3933 | | - | |
3934 | | - | |
3935 | | - | |
3936 | | - | |
3937 | | - | |
3938 | | - | |
3939 | | - | |
3940 | | - | |
| 3879 | + | |
| 3880 | + | |
| 3881 | + | |
| 3882 | + | |
3941 | 3883 | | |
3942 | 3884 | | |
3943 | 3885 | | |
| |||
3952 | 3894 | | |
3953 | 3895 | | |
3954 | 3896 | | |
3955 | | - | |
3956 | | - | |
3957 | | - | |
3958 | | - | |
3959 | | - | |
3960 | | - | |
3961 | | - | |
3962 | | - | |
3963 | | - | |
3964 | | - | |
3965 | | - | |
3966 | | - | |
3967 | | - | |
3968 | | - | |
3969 | | - | |
3970 | | - | |
3971 | | - | |
3972 | | - | |
3973 | | - | |
3974 | | - | |
3975 | | - | |
3976 | | - | |
3977 | | - | |
3978 | | - | |
3979 | | - | |
3980 | | - | |
3981 | | - | |
3982 | | - | |
3983 | | - | |
3984 | | - | |
3985 | | - | |
3986 | | - | |
3987 | | - | |
3988 | | - | |
3989 | | - | |
3990 | | - | |
3991 | | - | |
3992 | | - | |
3993 | | - | |
3994 | | - | |
3995 | | - | |
3996 | | - | |
3997 | | - | |
3998 | | - | |
3999 | | - | |
4000 | | - | |
4001 | | - | |
4002 | | - | |
4003 | | - | |
4004 | | - | |
4005 | | - | |
4006 | | - | |
4007 | | - | |
4008 | | - | |
4009 | | - | |
4010 | | - | |
4011 | | - | |
4012 | | - | |
4013 | | - | |
4014 | | - | |
4015 | | - | |
4016 | | - | |
4017 | | - | |
4018 | | - | |
4019 | | - | |
4020 | | - | |
4021 | | - | |
4022 | | - | |
4023 | | - | |
4024 | | - | |
4025 | | - | |
4026 | | - | |
4027 | | - | |
4028 | | - | |
4029 | | - | |
4030 | | - | |
4031 | | - | |
4032 | | - | |
4033 | | - | |
4034 | | - | |
4035 | | - | |
4036 | | - | |
4037 | | - | |
4038 | | - | |
4039 | | - | |
4040 | | - | |
4041 | | - | |
4042 | | - | |
4043 | | - | |
4044 | | - | |
4045 | | - | |
4046 | | - | |
4047 | | - | |
4048 | | - | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
4049 | 3902 | | |
4050 | 3903 | | |
4051 | 3904 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
711 | 713 | | |
712 | 714 | | |
713 | 715 | | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
714 | 877 | | |
715 | 878 | | |
716 | 879 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
529 | 533 | | |
530 | 534 | | |
531 | 535 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
760 | 760 | | |
761 | 761 | | |
762 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
763 | 769 | | |
764 | 770 | | |
765 | 771 | | |
| |||
0 commit comments