irx.analysis.numeric_policy

irx.analysis.numeric_policy

Source: packages/irx/src/irx/analysis/numeric_policy.py

title: Value-preserving numeric promotion and conversion classification.
summary: >-
  Describe the checked-arithmetic policy independently of LLVM and runtime
  values. This policy covers fixed-width 8-64 bit integers and f16/f32/f64;
  Boolean, nullable, vector, and storage types must be handled by their owning
  semantic resolvers. Classification does not perform a conversion or a check.

Functions

integer_bounds(type_: astx.DataType) -> tuple[int, int] | None

title: Return the inclusive domain of a supported integer, excluding bool.
parameters:
  type_:
    type: astx.DataType
returns:
  type: tuple[int, int] | None

is_lossless_numeric_conversion(source: astx.DataType, target: astx.DataType) -> bool

title: Test containment of full numeric domains, not the current values.
parameters:
  source:
    type: astx.DataType
  target:
    type: astx.DataType
returns:
  type: bool

lossless_common_numeric_type(lhs: astx.DataType, rhs: astx.DataType) -> astx.DataType | None

title: Select the smallest containing numeric domain or reject the pair.
summary: >-
  Preserve matching integer signedness; mixed signed/unsigned operands
  require a containing signed type. Integer-only operations never acquire a
  floating result. Mixed floating operands require exact conversion of the
  entire integer domain. Unsupported types fail closed.
parameters:
  lhs:
    type: astx.DataType
  rhs:
    type: astx.DataType
returns:
  type: astx.DataType | None

numeric_conversion_kind(source: astx.DataType, target: astx.DataType) -> NumericConversionKind | None

title: Classify a supported conversion without inspecting runtime values.
parameters:
  source:
    type: astx.DataType
  target:
    type: astx.DataType
returns:
  type: NumericConversionKind | None

classify_numeric_conversion(source: astx.DataType, target: astx.DataType) -> NumericConversion | None

title: Plan implicit eligibility and explicit range checking for numerics.
summary: >-
  Return None for unsupported domains. Integer-to-float precision loss is
  explicit; a finite-range check is needed only for f16 among supported
  integer widths. Classification alone does not enable checked execution.
parameters:
  source:
    type: astx.DataType
  target:
    type: astx.DataType
returns:
  type: NumericConversion | None

Classes

NumericConversionKind(str, Enum)

title: Numeric conversion semantics before choosing an execution mechanism.

NumericConversion

title: >-
  Classification of a numeric conversion under the checked numeric policy.
summary: >-
  A required range check must precede publication of the converted value.
  Explicit floating conversions may round or truncate even when a range
  check succeeds; implicit conversions may not lose source-domain values.
attributes:
  source_type:
    type: astx.DataType
  target_type:
    type: astx.DataType
  kind:
    type: NumericConversionKind
  implicit:
    type: bool
  requires_range_check:
    type: bool
Back to top