-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Prereqs: #2296; ideally #2266, #2353
- Add some
Term::SumValue(tag: usize, items: Vec<Term>)- thischeck_term_types againstTerm::ConstType(Type::Sum(...))if theitemseachcheck_term_typeagainstTerm::ConstType(...)of the relevant sum element.- We may need to store the target SumType, as
hugr_core::ops::constant::Sumdoes, to support an equivalent ofValue::get_typeon Terms that are constants -Term::get_const_type(&self) -> Option<Type>, say. (See below for an alternative.) - Note hugr-core
Term::ConstTypeshould serialize to/from a hugr-modelTerm::ApplyofCORE_CONSTbut this has not been implemented yet (in either direction) - SumValue (Like Value::Sum) serializes as a
CORE_CONST_ADT, although the docs for CORE_CONST_ADT look dodgy (instead see uses infn export_valueandfn import_value):
- We may need to store the target SumType, as
/// Constants for runtime algebraic data types.
///
/// - **Parameter:** `?variants : (core.list core.type)` -- should be (core.list (core.list core.type)) ?
/// - **Parameter:** `?types : (core.list core.static)` -- written out as Wildcard, ignored when read in
/// - **Parameter:** `?tag : core.nat`
/// - **Parameter:** `?values : (core.tuple ?types)`. -- so perhaps `?types` is intended to be `?variants[?tag]` and inferred
/// - **Result:** `(core.const (core.adt ?variants))`
pub const CORE_CONST_ADT: &str = "core.const.adt";
- We are expecting to deprecate
Value::FunctionDeprecate Value::Function #2353 so hopefully don't need to add that here. - Probably also add
Term::OpaqueConstcontaining adyn CustomConstas a migration aid (serializing to/from hugr-modelCOMPAT_CONST_JSON) - Since this follows model-style Custom constructors in hugr-core, i.e. TypeDef -> TermDef #2296, we can use the same
Term::Extensioninstantiation of aTermDef, giving us inspectable extension values, rather than opaque ones based ontrait CustomConst. - Add new
LoadTermop that stores a Term (which mustcheck_term_typeagainst someTerm::Const(t), and then has a single value outport with typet).- This requires being able to synthesize the type of the Term (the above
get_const_type) rather than having LoadTerm store the type as well; another option would be a struct equivalent toValuethat store both Term and result-type (with methods to build a Value from a TermDef+args or compose Values into sums) - this might be better? - If we have Terms shared using Arcs, this allows strictly more sharing than using OpType::Const. If not, we might have to retain Const storing a Term and LoadConstant to allow sharing
- We should think about rendering (visualisation) here!!
- This requires being able to synthesize the type of the Term (the above
- We can then deprecate
Term::ConstandTerm::LoadConstant - Finally remove special cases for lists/arrays/etc. from
fn import_valueandfn export_valueas these should just be Term::Extensions
Serialization believe this does not affect hugr-model, only import.rs/export.rs and making more hugr-model Terms convertible into hugr-core. Model import will need to decide between core Term::OpaqueConst or a Term::Extension
Metadata
Metadata
Assignees
Labels
No labels