Skip to content

feat[next]: generic operators called from programs (Stage 2) - #65

Open
havogt wants to merge 1 commit into
dtype-generics-3-field-operatorsfrom
dtype-generics-4-programs
Open

havogt wants to merge 1 commit into
dtype-generics-3-field-operatorsfrom
dtype-generics-4-programs

Conversation

@havogt

@havogt havogt commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Stack 4/4 — dtype-generic field operators. Base: `dtype-generics-3-field-operators` (#64).

A dtype-generic field operator can now be called from a concrete `@program`, including at
several dtypes in one program.

  • Type-checking: `return_type_fieldop` and `function_signature_incompatibilities_fieldop`
    bind the operator's type variables from the concrete call arguments and substitute before
    the existing checks (so zero-dim promotion only ever sees concrete types — this also obviated
    a separately-planned `promote_zero_dims` change).
  • Lowering: a new PAST pass `monomorphize_generic_calls` binds each call site, name-mangles
    the callee per binding (e.g. `diff__FloatT_float32`), and replaces the generic closure
    callable with concrete specializations via a new `GTCallable.gt_specialize(binding, name)`
    (implemented by `FieldOperator` and `ItirShim` using the `SpecializeTypeVars` FOAST pass +
    rename). Two bindings of one operator become two GTIR `FunctionDefinition`s.

Calling a generic operator from another operator remains a follow-up. Verified across the
backend matrix incl. GPU (a program instantiating one operator at float32 and float64).


Stacked: 1 (#62) → 2 (#63) → 3 (#64) → 4 this. Review/merge in order; this is the tip.

A dtype-generic field operator can now be called from a concrete `@program`,
including at several dtypes in one program.

- Type-checking: `return_type_fieldop` and `function_signature_incompatibilities_fieldop`
  bind the operator's type variables from the concrete call arguments and substitute
  before the existing checks (so zero-dim promotion only ever sees concrete types).
- Lowering: a new PAST pass `monomorphize_generic_calls` binds each call site, name-mangles
  the callee per binding (e.g. `diff__FloatT_float32`), and replaces the generic closure
  callable with concrete specializations via a new `GTCallable.__gt_specialize__(binding, name)`
  (implemented by `FieldOperator` and `ItirShim` using the `SpecializeTypeVars` FOAST pass
  + rename). Two bindings of one operator become two GTIR `FunctionDefinition`s.

Calling a generic operator from another operator remains a follow-up. Verified across
the backend matrix incl. GPU (a program instantiating one operator at float32 and float64).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant