Skip to content

Merge Type and Term in hugr-core. #2341

@zrho

Description

@zrho

Includes removing Row Variables and <RV> parametrization from Types, instead using Term::ListConcat/TupleConcat.

  • Add Term::RuntimeSum - i.e. equivalent to Type::Sum, storing a SumType. (Serializes to core.adt, code already present)
  • SumType could become either
    • A Term of type Term::ListType(Term::ListType(Term::RuntimeType(x))) if we want to allow the number of variants to be extensible, or
    • A Vec<Term> each of type Term::ListType(Term::RuntimeType(x)) if we want fixed #variants but variable number of elements in each variant - this is equivalent to current SumType storing a Vec<Vec<Type<RV>
    • May also want the Simple/Unit(num variants) option for efficient storage
    • May want to cache the computed TypeBound inside the SumType, as we do not have Term/TermEnum (like current Type/TypeEnum) so cannot cache the bound there
  • Add Term::RuntimeFunc - to support row vars, this stores a Term for inputs and another for outputs, each of type Term::ListType(Term::RuntimeType(x))
  • Add Term::RuntimeExtension i.e. paralleling current Type::Extension (but currently for runtime types only. In model-style Custom constructors in hugr-core, i.e. TypeDef -> TermDef #2296 we'll make this into Term::Extension that can be any term, so perhaps best to call it that now, even if a little inconsistent.)
  • Each of these check_term_types against Term::RuntimeType (of appropriate TypeBound)
  • Remove Term::Runtime and define type Type = Term for now. However, anything that was Type (i.e. TypeBase<NoRV>) now needs to be check_term_typed against Term::RuntimeType(TypeBound::Linear) - this may be a large part of the PR (making up for the loss of the Type/Term distinction in Rust), and/or may just mean combining check_term_type with TypeBase::validate.
  • Signature (no toplevel row vars) has Vec<Term> (each element of type Term::RuntimeType) for inputs/outputs
  • Note difference between SumType (has row vars) and Vec<Vec<Type>> (no RowVars); we can convert rowvar-less sumtypes into the latter form by matching Term::List (not ListConcat).

Serialization
Believe no change to hugr-model here so serialization should remain backwards-compatible; more of hugr-model becomes convertible into hugr-core, but (until we do any of the followup issues) remains invalid in hugr-core. Likely quite breaking for Rust code using hugr-core....

Related Issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions