Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add a test of instantiating an extension set #939

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions hugr/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,34 @@ mod test {
);
Ok(())
}

#[test]
fn instantiate_extension_delta() -> Result<(), Box<dyn std::error::Error>> {
use crate::extension::prelude::{BOOL_T, PRELUDE_REGISTRY};

let mut e = Extension::new(EXT_ID);

let params: Vec<TypeParam> = vec![TypeParam::Extensions];
let db_set = ExtensionSet::type_var(0);
let fun_ty = FunctionType::new_endo(vec![BOOL_T]).with_extension_delta(db_set);

let def = e.add_op(
"SimpleOp".into(),
"".into(),
PolyFuncType::new(params.clone(), fun_ty),
)?;

// Concrete extension set
let es = ExtensionSet::singleton(&EXT_ID);
let exp_fun_ty = FunctionType::new_endo(vec![BOOL_T]).with_extension_delta(es.clone());
let args = [TypeArg::Extensions { es }];

def.validate_args(&args, &PRELUDE_REGISTRY, &params)
.unwrap();
assert_eq!(
def.compute_signature(&args, &PRELUDE_REGISTRY),
Ok(exp_fun_ty)
);
Ok(())
}
}