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 1 commit
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 ext_id = e.name().clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can't you just use EXT_ID rather than ext_id and avoid this?


let es = ExtensionSet::singleton(&ext_id);
let params: Vec<TypeParam> = vec![TypeParam::Extensions];
let args = [TypeArg::Extensions { es: es.clone() }];
let mut db_set = ExtensionSet::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you use let db_set = ExtensionSet::type_var(0)? Or, include a non-variable too (so let mut ... = ExtensionSet::singleton followed by insert_type_var) and check we take the union?

db_set.insert_type_var(0);
let fun_ty = FunctionType::new_endo(vec![BOOL_T]).with_extension_delta(db_set);

let exp_fun_ty = FunctionType::new_endo(vec![BOOL_T]).with_extension_delta(es);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional/super-nit: I think I'd finish making def before you start on what you're going to do with def (so move let es and let exp_fun_ty after let def)


let def = e.add_op(
"SimpleOp".into(),
"".into(),
PolyFuncType::new(params.clone(), fun_ty),
)?;
def.validate_args(&args, &PRELUDE_REGISTRY, &params)
.unwrap();
assert_eq!(
def.compute_signature(&args, &PRELUDE_REGISTRY),
Ok(exp_fun_ty)
);
Ok(())
}
}