Skip to content

Conversation

@acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jan 2, 2026

Follows #2784; closes #2341

  • Abandon the Type/TypeRV distinction. Yes, this loses us some Rust static type checking. But RowVars were always a hack, in that they looked like one entry in a list, but were any number of entries. Instead now we have variables that range over lists (i.e. are not members of lists) - there is (already) a Term::ListConcat which is a much nicer/more-principled solution.
    • See 68fba45 for a way of bringing back some of the ease-of-use/compactness of the RV system using the checking we have implemented in Rust; however, the "improvement" in the user code (/the pain of having to explicitly Term::new_list_concat) was not that great so I have reverted...thoughts?
  • Define type Type/TypeRV = Term; remove Term::Runtime(Type) and add new Term constructors corresponding to the old ones in Type: Term::RuntimeFunction, Term::RuntimeSum and Term::RuntimeExtension.
    • Note that the next PR probably makes that just ::Extension, i.e. able to produce things that are not just runtime types....
  • I removed Aliases; I mean I could add them but they are vestigial and not really working anyway (Overhaul or scrap aliases #2558). Or perhaps we should add them in and support properly now we have linking?
  • TypeRow now stores Terms (of course)
  • Signature stores a TypeRow of fixed arity - each element must be a runtime type (exactly one, so no RVs); FuncValueType stores a Term (an instance of Term::ListType(Term::RuntimeType)) which could thus contain variables ranging over lists (RVs).

This is mostly pain, the bigger gains are expected to come in later PRs (#2296 and #2756, eventually allowing "inspectable" custom constants with efficient serialization). But perhaps removing the RV hack is a win.

It's a draft, things are not all working yet....

  • Everything serde-related breaks; I've disabled roundtrip+schema-check in validate, but there are still many other tests. I think is a no-go, estimate that producing backward-compatible serde output will be....waaaaay too much effort; we plan to deprecate serde anyway, so this might be for after it's gone. But, will we need to keep serde for serializing Extensions (not Hugrs)?
  • Proptesting is broken...wondering whether we need to do something like test: proptest Type validation and substitution #1744 i.e. specifying the type of the Term to be produced by Arbitrary.
  • Also there is some hugr-llvm snapshot weirdness

TODOs/unresolved questions:

  • Is it time to retire old aliases TypeArg, TypeParam and the new TypeRV, Type, TypeRowRV ?
  • What about TypeRow? Rename to TermRow? Or follow suggestion in previous PR and remove it?
  • Some naming is a bit dodgy....probably quite a lot....
  • I rather feel that we should rename all the Term::XXXType to XXXKind, and all Term::RuntimeYYY to ::YYYType (so Term::SumType, Term::ExtensionType, Term::FunctionType). Using the word "type" to mean types at the static/Term level rather than runtime (wire) types seems confusing.
  • The FuncValueType/Signature/SumType methods new, try_new and new_unchecked were a big help in debugging, getting back some of what was lost by the unification of Type-Term and RV-NoRV. I suspect we should extend this to all OpType variants - ExtensionOp, Call, and LoadFunction have always done these checks, so we could add to Input, Output, containers, etc. etc. too (?)
  • hugr-py needs updating too

BREAKING CHANGE: Term gains RuntimeFunction, RuntimeSum and RuntimeExtension variants; Type is now an alias for Term. Use check_term_type(tm, &TypeBound::Linear.into()) to check that tm: &Term represents a runtime type. No more aliases.

acl-cqc added 30 commits January 1, 2026 12:14
This reverts commit 3aad2180f710237a31fc67e5995a2f607d9f0168.
acl-cqc added 29 commits January 1, 2026 17:06
@hugrbot
Copy link
Collaborator

hugrbot commented Jan 2, 2026

Hey there and thank you for opening this pull request! 👋

We follow the Conventional Commits convention for PR titles. It looks like your title needs some adjustment.

The title should have a type prefix, followed by a colon. The most important ones are:

  • feat: for new features
  • fix: for bug fixes

If the PR contains a breaking change, use feat!: or fix!: instead and include a "BREAKING CHANGE:" footer in the description of the pull request.

You may also include a (scope) after the type prefix.

Expand this message for the full list of tags.
  • feat: New feature
  • fix: Bug fix
  • docs: Documentation-only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: Performance improvements
  • test: Adding missing or correcting existing tests
  • ci: Changes to our CI configuration files and scripts
  • chore: Other changes that do not alter public APIs or code behaviour
  • revert: Reverts a previous commit

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.

3 participants