Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion hugr-core/src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod test {
let mut module_builder = ModuleBuilder::new();

let qubit_state_type =
module_builder.add_alias_declare("qubit_state", TypeBound::Any)?;
module_builder.add_alias_declare("qubit_state", TypeBound::Linear)?;

let f_build = module_builder.define_function(
"main",
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/declarative/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl From<TypeDefBoundDeclaration> for TypeDefBound {
bound: TypeBound::Copyable,
},
TypeDefBoundDeclaration::Any => Self::Explicit {
bound: TypeBound::Any,
bound: TypeBound::Linear,
},
}
}
Expand Down
16 changes: 8 additions & 8 deletions hugr-core/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub(super) mod test {
const OP_NAME: OpName = OpName::new_inline("Reverse");

let ext = Extension::try_new_test_arc(EXT_ID, |ext, extension_ref| {
const TP: TypeParam = TypeParam::RuntimeType(TypeBound::Any);
const TP: TypeParam = TypeParam::RuntimeType(TypeBound::Linear);
let list_of_var =
Type::new_extension(list_def.instantiate(vec![TypeArg::new_var_use(0, TP)])?);
let type_scheme = PolyFuncTypeRV::new(vec![TP], Signature::new_endo(vec![list_of_var]));
Expand Down Expand Up @@ -702,13 +702,13 @@ pub(super) mod test {
&self,
arg_values: &[TypeArg],
) -> Result<PolyFuncTypeRV, SignatureError> {
const TP: TypeParam = TypeParam::RuntimeType(TypeBound::Any);
const TP: TypeParam = TypeParam::RuntimeType(TypeBound::Linear);
let [TypeArg::BoundedNat(n)] = arg_values else {
return Err(SignatureError::InvalidTypeArgs);
};
let n = *n as usize;
let tvs: Vec<Type> = (0..n)
.map(|_| Type::new_var_use(0, TypeBound::Any))
.map(|_| Type::new_var_use(0, TypeBound::Linear))
.collect();
Ok(PolyFuncTypeRV::new(
vec![TP.clone()],
Expand Down Expand Up @@ -752,9 +752,9 @@ pub(super) mod test {

// quick sanity check that we are validating the args - note changed bound:
assert_eq!(
def.validate_args(&args, &[TypeBound::Any.into()]),
def.validate_args(&args, &[TypeBound::Linear.into()]),
Err(SignatureError::TypeVarDoesNotMatchDeclaration {
actual: TypeBound::Any.into(),
actual: TypeBound::Linear.into(),
cached: TypeBound::Copyable.into()
})
);
Expand Down Expand Up @@ -791,8 +791,8 @@ pub(super) mod test {
"SimpleOp".into(),
String::new(),
PolyFuncTypeRV::new(
vec![TypeBound::Any.into()],
Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Any)]),
vec![TypeBound::Linear.into()],
Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Linear)]),
),
extension_ref,
)?;
Expand All @@ -807,7 +807,7 @@ pub(super) mod test {
def.compute_signature(&[arg.clone()]),
Err(SignatureError::TypeArgMismatch(
TermTypeError::TypeMismatch {
type_: TypeBound::Any.into(),
type_: TypeBound::Linear.into(),
term: arg,
}
))
Expand Down
26 changes: 13 additions & 13 deletions hugr-core/src/extension/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ lazy_static! {
PANIC_OP_ID,
"Panic with input error".to_string(),
PolyFuncTypeRV::new(
[TypeParam::new_list_type(TypeBound::Any), TypeParam::new_list_type(TypeBound::Any)],
[TypeParam::new_list_type(TypeBound::Linear), TypeParam::new_list_type(TypeBound::Linear)],
FuncValueType::new(
vec![TypeRV::new_extension(error_type.clone()), TypeRV::new_row_var_use(0, TypeBound::Any)],
vec![TypeRV::new_row_var_use(1, TypeBound::Any)],
vec![TypeRV::new_extension(error_type.clone()), TypeRV::new_row_var_use(0, TypeBound::Linear)],
vec![TypeRV::new_row_var_use(1, TypeBound::Linear)],
),
),
extension_ref,
Expand All @@ -124,10 +124,10 @@ lazy_static! {
EXIT_OP_ID,
"Exit with input error".to_string(),
PolyFuncTypeRV::new(
[TypeParam::new_list_type(TypeBound::Any), TypeParam::new_list_type(TypeBound::Any)],
[TypeParam::new_list_type(TypeBound::Linear), TypeParam::new_list_type(TypeBound::Linear)],
FuncValueType::new(
vec![TypeRV::new_extension(error_type), TypeRV::new_row_var_use(0, TypeBound::Any)],
vec![TypeRV::new_row_var_use(1, TypeBound::Any)],
vec![TypeRV::new_extension(error_type), TypeRV::new_row_var_use(0, TypeBound::Linear)],
vec![TypeRV::new_row_var_use(1, TypeBound::Linear)],
),
),
extension_ref,
Expand Down Expand Up @@ -160,7 +160,7 @@ pub(crate) fn qb_custom_t(extension_ref: &Weak<Extension>) -> CustomType {
TypeName::new_inline("qubit"),
vec![],
PRELUDE_ID,
TypeBound::Any,
TypeBound::Linear,
extension_ref,
)
}
Expand Down Expand Up @@ -626,10 +626,10 @@ impl MakeOpDef for TupleOpDef {
}

fn init_signature(&self, _extension_ref: &Weak<Extension>) -> SignatureFunc {
let rv = TypeRV::new_row_var_use(0, TypeBound::Any);
let rv = TypeRV::new_row_var_use(0, TypeBound::Linear);
let tuple_type = TypeRV::new_tuple(vec![rv.clone()]);

let param = TypeParam::new_list_type(TypeBound::Any);
let param = TypeParam::new_list_type(TypeBound::Linear);
match self {
TupleOpDef::MakeTuple => {
PolyFuncTypeRV::new([param], FuncValueType::new(rv, tuple_type))
Expand Down Expand Up @@ -800,8 +800,8 @@ impl MakeOpDef for NoopDef {
}

fn init_signature(&self, _extension_ref: &Weak<Extension>) -> SignatureFunc {
let tv = Type::new_var_use(0, TypeBound::Any);
PolyFuncType::new([TypeBound::Any.into()], Signature::new_endo(tv)).into()
let tv = Type::new_var_use(0, TypeBound::Linear);
PolyFuncType::new([TypeBound::Linear.into()], Signature::new_endo(tv)).into()
}

fn description(&self) -> String {
Expand Down Expand Up @@ -912,8 +912,8 @@ impl MakeOpDef for BarrierDef {

fn init_signature(&self, _extension_ref: &Weak<Extension>) -> SignatureFunc {
PolyFuncTypeRV::new(
vec![TypeParam::new_list_type(TypeBound::Any)],
FuncValueType::new_endo(TypeRV::new_row_var_use(0, TypeBound::Any)),
vec![TypeParam::new_list_type(TypeBound::Linear)],
FuncValueType::new_endo(TypeRV::new_row_var_use(0, TypeBound::Linear)),
)
.into()
}
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/resolution/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn resolve_custom_const(#[case] custom_const: impl CustomConst) {
#[rstest]
fn resolve_call() {
let dummy_fn_sig = PolyFuncType::new(
vec![TypeParam::RuntimeType(TypeBound::Any)],
vec![TypeParam::RuntimeType(TypeBound::Linear)],
Signature::new(vec![], vec![bool_t()]),
);

Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/extension/type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl TypeDefBound {
#[must_use]
pub fn any() -> Self {
TypeDefBound::Explicit {
bound: TypeBound::Any,
bound: TypeBound::Linear,
}
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl TypeDef {
let args: Vec<_> = args.iter().collect();
if indices.is_empty() {
// Assume most general case
return TypeBound::Any;
return TypeBound::Linear;
}
least_upper_bound(indices.iter().map(|i| {
let ta = args.get(*i);
Expand Down
24 changes: 12 additions & 12 deletions hugr-core/src/hugr/serialize/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ fn serialize_types_roundtrip() {
#[case(bool_t())]
#[case(usize_t())]
#[case(INT_TYPES[2].clone())]
#[case(Type::new_alias(crate::ops::AliasDecl::new("t", TypeBound::Any)))]
#[case(Type::new_alias(crate::ops::AliasDecl::new("t", TypeBound::Linear)))]
#[case(Type::new_var_use(2, TypeBound::Copyable))]
#[case(Type::new_tuple(vec![bool_t(),qb_t()]))]
#[case(Type::new_sum([vec![bool_t(),qb_t()], vec![Type::new_unit_sum(4)]]))]
Expand Down Expand Up @@ -477,9 +477,9 @@ fn polyfunctype1() -> PolyFuncType {
}

fn polyfunctype2() -> PolyFuncTypeRV {
let tv0 = TypeRV::new_row_var_use(0, TypeBound::Any);
let tv0 = TypeRV::new_row_var_use(0, TypeBound::Linear);
let tv1 = TypeRV::new_row_var_use(1, TypeBound::Copyable);
let params = [TypeBound::Any, TypeBound::Copyable].map(TypeParam::new_list_type);
let params = [TypeBound::Linear, TypeBound::Copyable].map(TypeParam::new_list_type);
let inputs = vec![
TypeRV::new_function(FuncValueType::new(tv0.clone(), tv1.clone())),
tv0,
Expand All @@ -496,11 +496,11 @@ fn polyfunctype2() -> PolyFuncTypeRV {
#[case(polyfunctype1())]
#[case(PolyFuncType::new([TypeParam::StringType], Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Copyable)])))]
#[case(PolyFuncType::new([TypeBound::Copyable.into()], Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Copyable)])))]
#[case(PolyFuncType::new([TypeParam::new_list_type(TypeBound::Any)], Signature::new_endo(type_row![])))]
#[case(PolyFuncType::new([TypeParam::new_tuple_type([TypeBound::Any.into(), TypeParam::bounded_nat_type(2.try_into().unwrap())])], Signature::new_endo(type_row![])))]
#[case(PolyFuncType::new([TypeParam::new_list_type(TypeBound::Linear)], Signature::new_endo(type_row![])))]
#[case(PolyFuncType::new([TypeParam::new_tuple_type([TypeBound::Linear.into(), TypeParam::bounded_nat_type(2.try_into().unwrap())])], Signature::new_endo(type_row![])))]
#[case(PolyFuncType::new(
[TypeParam::new_list_type(TypeBound::Any)],
Signature::new_endo(Type::new_tuple(TypeRV::new_row_var_use(0, TypeBound::Any)))))]
[TypeParam::new_list_type(TypeBound::Linear)],
Signature::new_endo(Type::new_tuple(TypeRV::new_row_var_use(0, TypeBound::Linear)))))]
fn roundtrip_polyfunctype_fixedlen(#[case] poly_func_type: PolyFuncType) {
check_testing_roundtrip(poly_func_type);
}
Expand All @@ -509,11 +509,11 @@ fn roundtrip_polyfunctype_fixedlen(#[case] poly_func_type: PolyFuncType) {
#[case(FuncValueType::new_endo(type_row![]).into())]
#[case(PolyFuncTypeRV::new([TypeParam::StringType], FuncValueType::new_endo(vec![Type::new_var_use(0, TypeBound::Copyable)])))]
#[case(PolyFuncTypeRV::new([TypeBound::Copyable.into()], FuncValueType::new_endo(vec![Type::new_var_use(0, TypeBound::Copyable)])))]
#[case(PolyFuncTypeRV::new([TypeParam::new_list_type(TypeBound::Any)], FuncValueType::new_endo(type_row![])))]
#[case(PolyFuncTypeRV::new([TypeParam::new_tuple_type([TypeBound::Any.into(), TypeParam::bounded_nat_type(2.try_into().unwrap())])], FuncValueType::new_endo(type_row![])))]
#[case(PolyFuncTypeRV::new([TypeParam::new_list_type(TypeBound::Linear)], FuncValueType::new_endo(type_row![])))]
#[case(PolyFuncTypeRV::new([TypeParam::new_tuple_type([TypeBound::Linear.into(), TypeParam::bounded_nat_type(2.try_into().unwrap())])], FuncValueType::new_endo(type_row![])))]
#[case(PolyFuncTypeRV::new(
[TypeParam::new_list_type(TypeBound::Any)],
FuncValueType::new_endo(TypeRV::new_row_var_use(0, TypeBound::Any))))]
[TypeParam::new_list_type(TypeBound::Linear)],
FuncValueType::new_endo(TypeRV::new_row_var_use(0, TypeBound::Linear))))]
#[case(polyfunctype2())]
fn roundtrip_polyfunctype_varlen(#[case] poly_func_type: PolyFuncTypeRV) {
check_testing_roundtrip(poly_func_type);
Expand All @@ -524,7 +524,7 @@ fn roundtrip_polyfunctype_varlen(#[case] poly_func_type: PolyFuncTypeRV) {
#[case(ops::FuncDefn::new("polyfunc1", polyfunctype1()))]
#[case(ops::FuncDecl::new("polyfunc2", polyfunctype1()))]
#[case(ops::AliasDefn { name: "aliasdefn".into(), definition: Type::new_unit_sum(4)})]
#[case(ops::AliasDecl { name: "aliasdecl".into(), bound: TypeBound::Any})]
#[case(ops::AliasDecl { name: "aliasdecl".into(), bound: TypeBound::Linear})]
#[case(ops::Const::new(Value::false_val()))]
#[case(ops::Const::new(Value::function(crate::builder::test::simple_dfg_hugr()).unwrap()))]
#[case(ops::Input::new(vec![Type::new_var_use(3,TypeBound::Copyable)]))]
Expand Down
38 changes: 19 additions & 19 deletions hugr-core/src/hugr/validate/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fn invalid_types() {
"MyContainer",
vec![usize_t().into()],
EXT_ID,
TypeBound::Any,
TypeBound::Linear,
&Arc::downgrade(&ext),
));
let mut hugr = identity_hugr_with_type(valid.clone()).0;
Expand All @@ -332,7 +332,7 @@ fn invalid_types() {
"MyContainer",
vec![valid.clone().into()],
EXT_ID,
TypeBound::Any,
TypeBound::Linear,
&Arc::downgrade(&ext),
);
assert_eq!(
Expand All @@ -354,7 +354,7 @@ fn invalid_types() {
validate_to_sig_error(bad_bound.clone()),
SignatureError::WrongBound {
actual: TypeBound::Copyable,
expected: TypeBound::Any
expected: TypeBound::Linear
}
);

Expand All @@ -363,22 +363,22 @@ fn invalid_types() {
"MyContainer",
vec![Type::new_extension(bad_bound).into()],
EXT_ID,
TypeBound::Any,
TypeBound::Linear,
&Arc::downgrade(&ext),
);
assert_eq!(
validate_to_sig_error(nested),
SignatureError::WrongBound {
actual: TypeBound::Copyable,
expected: TypeBound::Any
expected: TypeBound::Linear
}
);

let too_many_type_args = CustomType::new(
"MyContainer",
vec![usize_t().into(), 3u64.into()],
EXT_ID,
TypeBound::Any,
TypeBound::Linear,
&Arc::downgrade(&ext),
);
assert_eq!(
Expand All @@ -393,8 +393,8 @@ fn typevars_declared() -> Result<(), Box<dyn std::error::Error>> {
let f = FunctionBuilder::new(
"myfunc",
PolyFuncType::new(
[TypeBound::Any.into()],
Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Any)]),
[TypeBound::Linear.into()],
Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Linear)]),
),
)?;
let [w] = f.input_wires_arr();
Expand All @@ -403,8 +403,8 @@ fn typevars_declared() -> Result<(), Box<dyn std::error::Error>> {
let f = FunctionBuilder::new(
"myfunc",
PolyFuncType::new(
[TypeBound::Any.into()],
Signature::new_endo(vec![Type::new_var_use(1, TypeBound::Any)]),
[TypeBound::Linear.into()],
Signature::new_endo(vec![Type::new_var_use(1, TypeBound::Linear)]),
),
)?;
let [w] = f.input_wires_arr();
Expand All @@ -413,7 +413,7 @@ fn typevars_declared() -> Result<(), Box<dyn std::error::Error>> {
let f = FunctionBuilder::new(
"myfunc",
PolyFuncType::new(
[TypeBound::Any.into()],
[TypeBound::Linear.into()],
Signature::new_endo(vec![Type::new_var_use(1, TypeBound::Copyable)]),
),
)?;
Expand Down Expand Up @@ -486,10 +486,10 @@ fn no_polymorphic_consts() -> Result<(), Box<dyn std::error::Error>> {
}

pub(crate) fn extension_with_eval_parallel() -> Arc<Extension> {
let rowp = TypeParam::new_list_type(TypeBound::Any);
let rowp = TypeParam::new_list_type(TypeBound::Linear);
Extension::new_test_arc(EXT_ID, |ext, extension_ref| {
let inputs = TypeRV::new_row_var_use(0, TypeBound::Any);
let outputs = TypeRV::new_row_var_use(1, TypeBound::Any);
let inputs = TypeRV::new_row_var_use(0, TypeBound::Linear);
let outputs = TypeRV::new_row_var_use(1, TypeBound::Linear);
let evaled_fn = TypeRV::new_function(FuncValueType::new(inputs.clone(), outputs.clone()));
let pf = PolyFuncTypeRV::new(
[rowp.clone(), rowp.clone()],
Expand All @@ -498,7 +498,7 @@ pub(crate) fn extension_with_eval_parallel() -> Arc<Extension> {
ext.add_op("eval".into(), String::new(), pf, extension_ref)
.unwrap();

let rv = |idx| TypeRV::new_row_var_use(idx, TypeBound::Any);
let rv = |idx| TypeRV::new_row_var_use(idx, TypeBound::Linear);
let pf = PolyFuncTypeRV::new(
[rowp.clone(), rowp.clone(), rowp.clone(), rowp.clone()],
Signature::new(
Expand Down Expand Up @@ -548,13 +548,13 @@ fn list1ty(t: TypeRV) -> Term {
#[test]
fn row_variables() -> Result<(), Box<dyn std::error::Error>> {
let e = extension_with_eval_parallel();
let tv = TypeRV::new_row_var_use(0, TypeBound::Any);
let tv = TypeRV::new_row_var_use(0, TypeBound::Linear);
let inner_ft = Type::new_function(FuncValueType::new_endo(tv.clone()));
let ft_usz = Type::new_function(FuncValueType::new_endo(vec![tv.clone(), usize_t().into()]));
let mut fb = FunctionBuilder::new(
"id",
PolyFuncType::new(
[TypeParam::new_list_type(TypeBound::Any)],
[TypeParam::new_list_type(TypeBound::Linear)],
Signature::new(inner_ft.clone(), ft_usz),
),
)?;
Expand Down Expand Up @@ -582,8 +582,8 @@ fn test_polymorphic_load() -> Result<(), Box<dyn std::error::Error>> {
let id = m.declare(
"id",
PolyFuncType::new(
vec![TypeBound::Any.into()],
Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Any)]),
vec![TypeBound::Linear.into()],
Signature::new_endo(vec![Type::new_var_use(0, TypeBound::Linear)]),
),
)?;
let sig = Signature::new(
Expand Down
6 changes: 3 additions & 3 deletions hugr-core/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ impl<'a> Context<'a> {

/// Import a [`Term`] from a term that represents a static type or value.
fn import_term(&mut self, term_id: table::TermId) -> Result<Term, ImportError> {
self.import_term_with_bound(term_id, TypeBound::Any)
self.import_term_with_bound(term_id, TypeBound::Linear)
}

fn import_term_with_bound(
Expand Down Expand Up @@ -1542,7 +1542,7 @@ impl<'a> Context<'a> {
}
}
table::Term::Var(table::VarId(_, index)) => {
let var = RV::try_from_rv(RowVariable(*index as _, TypeBound::Any))
let var = RV::try_from_rv(RowVariable(*index as _, TypeBound::Linear))
.map_err(|_| error_invalid!("expected a closed list"))?;
types.push(TypeBase::new(TypeEnum::RowVar(var)));
}
Expand Down Expand Up @@ -1796,7 +1796,7 @@ impl LocalVar {
pub fn new(r#type: table::TermId) -> Self {
Self {
r#type,
bound: TypeBound::Any,
bound: TypeBound::Linear,
}
}
}
Loading
Loading