MCPcopy Create free account
hub / github.com/python/mypy / PrimitiveDescription

Class PrimitiveDescription

mypyc/ir/ops.py:692–754  ·  view source on GitHub ↗

Description of a primitive op. Primitives get lowered into lower-level ops before code generation. If c_function_name is provided, a primitive will be lowered into a CallC op. Otherwise, custom logic will need to be implemented to transform the primitive into lower-level ops.

Source from the content-addressed store, hash-verified

690
691@final
692class PrimitiveDescription:
693 """Description of a primitive op.
694
695 Primitives get lowered into lower-level ops before code generation.
696
697 If c_function_name is provided, a primitive will be lowered into a CallC op.
698 Otherwise, custom logic will need to be implemented to transform the
699 primitive into lower-level ops.
700 """
701
702 def __init__(
703 self,
704 name: str,
705 arg_types: list[RType],
706 return_type: RType, # TODO: What about generic?
707 var_arg_type: RType | None,
708 truncated_type: RType | None,
709 c_function_name: str | None,
710 error_kind: int,
711 steals: StealsDescription,
712 is_borrowed: bool,
713 ordering: list[int] | None,
714 extra_int_constants: list[tuple[int, RType]],
715 priority: int,
716 is_pure: bool,
717 experimental: bool,
718 dependencies: list[Dependency] | None,
719 ) -> None:
720 # Each primitive much have a distinct name, but otherwise they are arbitrary.
721 self.name: Final = name
722 self.arg_types: Final = arg_types
723 self.return_type: Final = return_type
724 self.var_arg_type: Final = var_arg_type
725 self.truncated_type: Final = truncated_type
726 # If non-None, this will map to a call of a C helper function; if None,
727 # there must be a custom handler function that gets invoked during the lowering
728 # pass to generate low-level IR for the primitive (in the mypyc.lower package)
729 self.c_function_name: Final = c_function_name
730 self.error_kind: Final = error_kind
731 self.steals: Final = steals
732 self.is_borrowed: Final = is_borrowed
733 self.ordering: Final = ordering
734 self.extra_int_constants: Final = extra_int_constants
735 self.priority: Final = priority
736 # Pure primitives have no side effects, take immutable arguments, and
737 # never fail. They support additional optimizations.
738 self.is_pure: Final = is_pure
739 if is_pure:
740 assert error_kind == ERR_NEVER
741 # Experimental primitives are not used unless mypyc experimental features are
742 # explicitly enabled
743 self.experimental = experimental
744 # Dependencies for the primitive, such as a capsule that needs to imported
745 # and configured to call the primitive.
746 self.dependencies = dependencies
747 # Native integer types such as u8 can cause ambiguity in primitive
748 # matching, since these are assignable to plain int *and* vice versa.
749 # If this flag is set, the primitive has native integer types and must

Callers 5

method_opFunction · 0.90
function_opFunction · 0.90
binary_opFunction · 0.90
custom_primitive_opFunction · 0.90
unary_opFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…