diff --git a/hugr-core/src/export.rs b/hugr-core/src/export.rs index 8139602f9..db52e96f0 100644 --- a/hugr-core/src/export.rs +++ b/hugr-core/src/export.rs @@ -1045,7 +1045,7 @@ impl<'a> Context<'a> { parts: contents.into_bump_slice(), }); - let symbol = self.resolve_symbol("collections.array.const"); + let symbol = self.resolve_symbol(ArrayValue::CTR_NAME); let args = self.bump.alloc_slice_copy(&[element_type, len, contents]); return self.make_term(model::Term::ApplyFull { symbol, args }); } @@ -1054,14 +1054,14 @@ impl<'a> Context<'a> { let bitwidth = self.make_term(model::Term::Nat(v.log_width() as u64)); let literal = self.make_term(model::Term::Nat(v.value_u())); - let symbol = self.resolve_symbol("arithmetic.int.const"); + let symbol = self.resolve_symbol(ConstInt::CTR_NAME); let args = self.bump.alloc_slice_copy(&[bitwidth, literal]); return self.make_term(model::Term::ApplyFull { symbol, args }); } if let Some(v) = e.value().downcast_ref::() { let literal = self.make_term(model::Term::Nat(v.to_bits())); - let symbol = self.resolve_symbol("arithmetic.float.const-f64"); + let symbol = self.resolve_symbol(ConstF64::CTR_NAME); let args = self.bump.alloc_slice_copy(&[literal]); return self.make_term(model::Term::ApplyFull { symbol, args }); } diff --git a/hugr-core/src/import.rs b/hugr-core/src/import.rs index 1d02e37aa..af4797713 100644 --- a/hugr-core/src/import.rs +++ b/hugr-core/src/import.rs @@ -1358,7 +1358,7 @@ impl<'a> Context<'a> { // NOTE: We have special cased arrays, integers, and floats for now. // TODO: Allow arbitrary extension values to be imported from terms. - if symbol_name == "collections.array.const" { + if symbol_name == ArrayValue::CTR_NAME { let element_type_term = args.first().ok_or(model::ModelError::TypeError(term_id))?; let element_type = self.import_type(*element_type_term)?; @@ -1375,7 +1375,7 @@ impl<'a> Context<'a> { return Ok(ArrayValue::new(element_type, contents).into()); } - if symbol_name == "arithmetic.int.const" { + if symbol_name == ConstInt::CTR_NAME { let bitwidth = { let bitwidth = args.first().ok_or(model::ModelError::TypeError(term_id))?; let model::Term::Nat(bitwidth) = self.get_term(*bitwidth)? else { @@ -1400,7 +1400,7 @@ impl<'a> Context<'a> { .into()); } - if symbol_name == "arithmetic.float.const-f64" { + if symbol_name == ConstF64::CTR_NAME { let value = { let value = args.first().ok_or(model::ModelError::TypeError(term_id))?; let model::Term::Nat(value) = self.get_term(*value)? else { diff --git a/hugr-core/src/std_extensions/arithmetic/float_types.rs b/hugr-core/src/std_extensions/arithmetic/float_types.rs index 3275548dd..acad6403e 100644 --- a/hugr-core/src/std_extensions/arithmetic/float_types.rs +++ b/hugr-core/src/std_extensions/arithmetic/float_types.rs @@ -52,6 +52,9 @@ impl std::ops::Deref for ConstF64 { } impl ConstF64 { + /// Name of the constructor for creating constant 64bit floats. + pub(crate) const CTR_NAME: &'static str = "arithmetic.float.const-f64"; + /// Create a new [`ConstF64`] pub fn new(value: f64) -> Self { // This function can't be `const` because `is_finite()` is not yet stable as a const function. diff --git a/hugr-core/src/std_extensions/arithmetic/int_types.rs b/hugr-core/src/std_extensions/arithmetic/int_types.rs index 88ee9d154..1342dd932 100644 --- a/hugr-core/src/std_extensions/arithmetic/int_types.rs +++ b/hugr-core/src/std_extensions/arithmetic/int_types.rs @@ -104,6 +104,9 @@ pub struct ConstInt { } impl ConstInt { + /// Name of the constructor for creating constant integers. + pub(crate) const CTR_NAME: &'static str = "arithmetic.int.const"; + /// Create a new [`ConstInt`] with a given width and unsigned value pub fn new_u(log_width: u8, value: u64) -> Result { if !is_valid_log_width(log_width) { diff --git a/hugr-core/src/std_extensions/collections/array.rs b/hugr-core/src/std_extensions/collections/array.rs index c1ccfe57e..618bd6182 100644 --- a/hugr-core/src/std_extensions/collections/array.rs +++ b/hugr-core/src/std_extensions/collections/array.rs @@ -42,6 +42,9 @@ pub struct ArrayValue { } impl ArrayValue { + /// Name of the constructor for creating constant arrays. + pub(crate) const CTR_NAME: &'static str = "collections.array.const"; + /// Create a new [CustomConst] for an array of values of type `typ`. /// That all values are of type `typ` is not checked here. pub fn new(typ: Type, contents: impl IntoIterator) -> Self {