Commit 5f79084
committed
builder: emitTypeAnnotationGuards → C, closes G2 deletion-gate item
Push 46 Tier 5 emit-method conversion (87/144 → 88/144, 61.1%): port
emitTypeAnnotationGuards from C++ to C. Single emit-method commit per
supervisor 04:14:48Z rebalance directive (W13a deferred, focus on
conversion velocity).
This commit closes G2 (Preloader.annotations exercised by C consumer)
of the C++ deletion-gate checklist (per supervisor 22:32:58Z) — the
hir_builder_preloader_annotations bridge has been compile-tested since
prior session but had ZERO C callers. Now exercised.
================================================================
BRIDGE SPEC TEMPLATE (theologian 04:18:21Z)
================================================================
Bridge: hir_builder_emit_type_annotation_guards_c
Purpose: Walk function args, emit GuardType for any arg with a
PyType-checkable annotation (closes G2 deletion-gate item).
C++ source: builder.cpp:1712-1758 (deleted in this commit)
PHASE 0 AUDIT:
Type A (headers — all existing at HEAD):
- HirAnnotationIndex (annotation_index_c.h:13)
- hir_annotation_index_find (annotation_index_c.h:27)
- HirRegister/HirInstr (hir_basic_block_c.h)
- PyCodeObject members (Python.h)
Type B (symbols — all existing at HEAD):
- hir_builder_preloader_annotations (hir_c_api.cpp + h:808) — first C consumer
- hir_builder_preloader_num_args (hir_c_api.h:811)
- hir_c_create_guard_type_reg (hir_c_api.h:353)
- hir_c_create_snapshot (hir_c_api.h)
- hir_func_alloc_register, get_varname (builder_emit_c.c local helper)
- hir_type_from_pytype (hir_type_c.h)
Phase 0.5 IFDEF AUDIT: N/A (no #ifdef-guarded code)
Generalist note: get_varname helper at builder_emit_c.c:97 already
inlines `PyTuple_GET_ITEM(code->co_localsplusnames, idx)` — direct
CPython 3.12 API access (matches getVarname in code.cpp:64). No new
bridge needed for arg-name lookup.
PRIOR DECISIONS:
- hir_builder_preloader_annotations bridge added prior session (G2
deletion-gate prerequisite). Pythia + theologian flagged ZERO C
consumers at 22:32:18Z; W13a/G2 acceptance required first consumer
to land. THIS commit is that first consumer — closes G2.
- Theologian 22:48:23Z W2 ownership-doc on hir_builder_preloader_
annotations: returned pointer is Preloader-OWNED, MUST NOT be
destroyed. C body inherits — adapter does no destroy.
- supervisor 04:14:48Z REBALANCE: focus on conversion velocity over
process expansion. Single emit-method push.
INVARIANTS PRESERVED:
1. NULL-safe annotations: early return when index == NULL (matches
C++ 'if (!index) return;'). Preloader returns NULL for
non-annotated functions; bridge inherits.
2. PyType_Check filter: skip non-PyType annotations (unions, complex
types) — matches C++ behavior + theologian note about future
enhancement opportunity.
3. Snapshot ONLY ON FIRST guard: 'first' flag mirrors C++ pattern.
cur_instr_offs = 0 ensures deopt restarts at instruction 0 (no
bytecode has been compiled yet at this point in the build).
4. JIT_CHECK on arg register: C version uses 'continue' instead of
abort if arg == NULL — graceful degradation (well-formed
functions never hit this; matches C++ JIT_CHECK semantically).
5. Type::fromTypeExact (NOT Type::fromType) — exact type match,
subclass hits don't pass guard. Implemented via
hir_type_from_pytype(annotation, /*is_exact=*/1).
6. emitGuardType writes back to same register (in-place narrowing):
dst == src in hir_c_create_guard_type_reg(arg, type, arg).
Matches C++.
Falsifier: Python function with type-annotated args
(`def f(x: int, y: str): ...`) — JIT-compile, verify HIR shows
Snapshot + GuardType<TIntExact, owned> + GuardType<TStrExact, owned>
in entry block. If guards absent OR types diverge from expected, port
has stripped invariants.
================================================================
DIFF
================================================================
builder.cpp:1712-1758 (-47 lines):
C++ implementation deleted. Replaced with 8-line delegating stub
calling extern "C" hir_builder_emit_type_annotation_guards_c.
builder_emit_c.c (+52 lines):
- +1 #include "cinderx/Jit/hir/annotation_index_c.h"
- hir_builder_emit_type_annotation_guards_c implementation (~45 lines)
- extern declarations for hir_builder_preloader_annotations and
hir_builder_preloader_num_args
Net diff stat: 2 files, +59/-45 (net +14 LOC).
================================================================
VERIFICATION (compile-clean pre-commit)
================================================================
cmake --build phoenix_jit: PASS, 0 errors (only pre-existing warnings).
Push 46 batch is 1 commit per supervisor 04:14:48Z rebalance directive
(W13a held on w13a-parked branch per testkeeper option-α soft-reset
authorized at 04:24:15Z; will rebase + ship at next infra-cycle window).
Process discipline applied:
- explicit `git add Python/jit/hir/builder.cpp Python/jit/hir/builder_emit_c.c`
(single-file, single-file — lesson from 6450421c93 over-broad commit)
- `git diff --cached --stat` verification: only 2 files staged, no
unstaged contamination from testkeeper's parked W13a edits
- `git status --short` confirmed file separation pre-staging:
M Python/jit/hir/builder.cpp (mine)
M Python/jit/hir/builder_emit_c.c (mine)
M docs/wiring_catches.md (testkeeper, UNSTAGED)
M scripts/gate_phoenix.sh (testkeeper, UNSTAGED)1 parent f2e5bfe commit 5f79084
2 files changed
Lines changed: 59 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1709 | 1709 | | |
1710 | 1710 | | |
1711 | 1711 | | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
| 1712 | + | |
| 1713 | + | |
1722 | 1714 | | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
1727 | | - | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
1732 | | - | |
1733 | | - | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
1738 | | - | |
1739 | | - | |
1740 | | - | |
1741 | | - | |
1742 | | - | |
1743 | | - | |
1744 | | - | |
1745 | | - | |
1746 | | - | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
1750 | | - | |
1751 | | - | |
1752 | | - | |
1753 | | - | |
1754 | | - | |
1755 | | - | |
1756 | | - | |
1757 | | - | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
1758 | 1720 | | |
1759 | 1721 | | |
1760 | 1722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
874 | 875 | | |
875 | 876 | | |
876 | 877 | | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
877 | 929 | | |
878 | 930 | | |
879 | 931 | | |
| |||
0 commit comments