@@ -37,13 +37,15 @@ class to enable the new behavior. Sometimes adding a new abstract
3737 RStruct ,
3838 RTuple ,
3939 RType ,
40+ RUnion ,
4041 RVoid ,
4142 bit_rprimitive ,
4243 bool_rprimitive ,
4344 cstring_rprimitive ,
4445 float_rprimitive ,
4546 int_rprimitive ,
4647 is_bool_or_bit_rprimitive ,
48+ is_fixed_width_rtype ,
4749 is_int_rprimitive ,
4850 is_none_rprimitive ,
4951 is_pointer_rprimitive ,
@@ -688,7 +690,7 @@ class PrimitiveDescription:
688690 Primitives get lowered into lower-level ops before code generation.
689691
690692 If c_function_name is provided, a primitive will be lowered into a CallC op.
691- Otherwise custom logic will need to be implemented to transform the
693+ Otherwise, custom logic will need to be implemented to transform the
692694 primitive into lower-level ops.
693695 """
694696
@@ -737,11 +739,24 @@ def __init__(
737739 # Capsule that needs to imported and configured to call the primitive
738740 # (name of the target module, e.g. "librt.base64").
739741 self .capsule = capsule
742+ # Native integer types such as u8 can cause ambiguity in primitive
743+ # matching, since these are assignable to plain int *and* vice versa.
744+ # If this flag is set, the primitive has native integer types and must
745+ # be matched using more complex rules.
746+ self .is_ambiguous = any (has_fixed_width_int (t ) for t in arg_types )
740747
741748 def __repr__ (self ) -> str :
742749 return f"<PrimitiveDescription { self .name !r} : { self .arg_types } >"
743750
744751
752+ def has_fixed_width_int (t : RType ) -> bool :
753+ if isinstance (t , RTuple ):
754+ return any (has_fixed_width_int (t ) for t in t .types )
755+ elif isinstance (t , RUnion ):
756+ return any (has_fixed_width_int (t ) for t in t .items )
757+ return is_fixed_width_rtype (t )
758+
759+
745760@final
746761class PrimitiveOp (RegisterOp ):
747762 """A higher-level primitive operation.
0 commit comments