From b256c2bc42e8499dac89c6f8bff7a0d478a1ff59 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Thu, 9 Nov 2023 17:17:54 +0000 Subject: [PATCH] fix: actually add the error type to prelude (#672) --- src/extension/prelude.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/extension/prelude.rs b/src/extension/prelude.rs index 56542b89c..98038fc18 100644 --- a/src/extension/prelude.rs +++ b/src/extension/prelude.rs @@ -66,6 +66,14 @@ lazy_static! { ) .unwrap(); prelude + .add_type( + ERROR_TYPE_NAME, + vec![], + "Simple opaque error type.".into(), + TypeDefBound::Explicit(TypeBound::Eq), + ) + .unwrap(); + prelude }; /// An extension registry containing only the prelude pub static ref PRELUDE_REGISTRY: ExtensionRegistry = [PRELUDE_DEF.to_owned()].into(); @@ -120,11 +128,14 @@ pub fn new_array_op(element_ty: Type, size: u64) -> LeafOp { /// Unspecified opaque error type. pub const ERROR_TYPE: Type = Type::new_extension(CustomType::new_simple( - smol_str::SmolStr::new_inline("error"), + ERROR_TYPE_NAME, PRELUDE_ID, TypeBound::Eq, )); +/// The string name of the error type. +pub const ERROR_TYPE_NAME: SmolStr = SmolStr::new_inline("error"); + #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] /// Structure for holding constant usize values. pub struct ConstUsize(u64); @@ -183,4 +194,17 @@ mod test { b.finish_prelude_hugr_with_outputs(out.outputs()).unwrap(); } + + #[test] + /// Test building a HUGR involving a new_array operation. + fn test_error_type() { + let ext_def = PRELUDE + .get_type(&ERROR_TYPE_NAME) + .unwrap() + .instantiate([]) + .unwrap(); + + let ext_type = Type::new_extension(ext_def); + assert_eq!(ext_type, ERROR_TYPE); + } }