Skip to content

Commit dc9696f

Browse files
committed
infra: add field accessors, hir_type_from_cdouble, container_eq gate
New instruction field accessors: hir_c_load_tuple_item_idx, hir_c_load_field_offset, hir_c_load_array_item_offset. hir_type_from_cdouble: C equivalent of Type::fromCDouble — constructs CDouble HirType with double specialization. container_eq: new wiring gate function exercising container equality ([1,2]==[1,2], dict, tuple). Catches type-dispatch bugs like the TLongExact/TListExact confusion.
1 parent ab3eb80 commit dc9696f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Python/jit/hir/hir_instr_c.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,18 @@ static inline int32_t hir_c_load_arg_idx(const void *instr) {
764764
return ((const HirLoadArg *)instr)->arg_idx;
765765
}
766766

767+
static inline size_t hir_c_load_tuple_item_idx(const void *instr) {
768+
return ((const HirLoadTupleItem *)instr)->idx;
769+
}
770+
771+
static inline intptr_t hir_c_load_field_offset(const void *instr) {
772+
return (intptr_t)((const HirLoadField *)instr)->offset;
773+
}
774+
775+
static inline intptr_t hir_c_load_array_item_offset(const void *instr) {
776+
return ((const HirLoadArrayItem *)instr)->offset;
777+
}
778+
767779
static inline HirType hir_c_load_arg_type(const void *instr) {
768780
return ((const HirLoadArg *)instr)->type;
769781
}

Python/jit/hir/hir_type_c.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ static inline int hir_type_has_value_spec(const HirType *t, HirType ty) {
288288
hir_type_is_subtype(*t, ty);
289289
}
290290

291+
/* Construct a CDouble HirType with double specialization.
292+
* C equivalent of Type::fromCDouble(d). */
293+
static inline HirType hir_type_from_cdouble(double d) {
294+
HirType t = HIR_TYPE_CDOUBLE;
295+
t.bits_and_flags |= ((uint64_t)HIR_SPEC_DOUBLE << HIR_TYPE_SPEC_SHIFT);
296+
t.double_val = d;
297+
return t;
298+
}
299+
291300
/* Return the type with specialization stripped (spec_kind=Top, spec_val=0).
292301
* C equivalent of Type::unspecialized(). */
293302
static inline HirType hir_type_unspecialized(const HirType *t) {

scripts/gate_phoenix.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ def make_closure(x):
215215
return x + y
216216
return inner
217217
218+
def container_eq():
219+
return ([1,2]==[1,2], [1,2]==[1,3], {1:2}=={1:2}, (1,2)==(1,2))
220+
218221
tests = [
219222
(straight_add, (3, 4), 7),
220223
(recursive_fib, (10,), 55),
@@ -224,6 +227,7 @@ tests = [
224227
(multi_var, (10,), 230),
225228
(cond_loop, (10,), -5),
226229
(make_closure(10), (5,), 15),
230+
(container_eq, (), (True, False, True, True)),
227231
]
228232
for func, args, expected in tests:
229233
cinderjit.force_compile(func)

0 commit comments

Comments
 (0)