Skip to content

Commit bc565ba

Browse files
committed
Add TypeBase<RV> w/out default, Type is alias for TypeBase<false>
When inference had figured out that Type == Type::<true>, we must now write TypeRV explicitly :(
1 parent edca745 commit bc565ba

File tree

13 files changed

+118
-110
lines changed

13 files changed

+118
-110
lines changed

hugr-core/src/builder/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub(crate) mod test {
212212

213213
use crate::std_extensions::logic::test::and_op;
214214
use crate::types::type_param::TypeParam;
215-
use crate::types::{FunTypeVarArgs, FunctionType, Type, TypeBound};
215+
use crate::types::{FunTypeVarArgs, FunctionType, Type, TypeBound, TypeRV};
216216
use crate::utils::test_quantum_extension::h_gate;
217217
use crate::{
218218
builder::test::{n_identity, BIT, NAT, QB},
@@ -533,7 +533,7 @@ pub(crate) mod test {
533533
#[test]
534534
fn no_outer_row_variables() -> Result<(), BuildError> {
535535
let e = crate::hugr::validate::test::extension_with_eval_parallel();
536-
let tv = Type::new_row_var_use(0, TypeBound::Copyable);
536+
let tv = TypeRV::new_row_var_use(0, TypeBound::Copyable);
537537
// Can *declare* a function that takes a function-value of unknown #args
538538
FunctionBuilder::new(
539539
"bad_eval",

hugr-core/src/extension/op_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub(super) mod test {
496496
use crate::ops::{CustomOp, OpName};
497497
use crate::std_extensions::collections::{EXTENSION, LIST_TYPENAME};
498498
use crate::types::type_param::{TypeArgError, TypeParam};
499-
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeBound};
499+
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeBound, TypeRV};
500500
use crate::{const_extension_ids, Extension};
501501

502502
const_extension_ids! {
@@ -734,7 +734,7 @@ pub(super) mod test {
734734
Ok(FunctionType::new_endo(tv))
735735
);
736736
// But not with an external row variable
737-
let arg: TypeArg = Type::new_row_var_use(0, TypeBound::Eq).into();
737+
let arg: TypeArg = TypeRV::new_row_var_use(0, TypeBound::Eq).into();
738738
assert_eq!(
739739
def.compute_signature(&[arg.clone()], &EMPTY_REG),
740740
Err(SignatureError::TypeArgMismatch(

hugr-core/src/extension/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ mod test {
544544
#[test]
545545
fn test_external_symbol() {
546546
let subject = ConstExternalSymbol::new("foo", Type::UNIT, false);
547-
assert_eq!(subject.get_type(), Type::<false>::UNIT);
547+
assert_eq!(subject.get_type(), Type::UNIT);
548548
assert_eq!(subject.name(), "@foo");
549549
assert!(subject.validate().is_ok());
550550
assert_eq!(

hugr-core/src/hugr/serialize/test.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::std_extensions::arithmetic::int_ops::INT_OPS_REGISTRY;
1414
use crate::std_extensions::arithmetic::int_types::{self, int_custom_type, ConstInt, INT_TYPES};
1515
use crate::std_extensions::logic::NotOp;
1616
use crate::types::type_param::TypeParam;
17-
use crate::types::{FunTypeVarArgs, FunctionType, PolyFuncType, SumType, Type, TypeArg, TypeBound};
17+
use crate::types::{
18+
FunTypeVarArgs, FunctionType, PolyFuncType, SumType, Type, TypeArg, TypeBound, TypeRV,
19+
};
1820
use crate::{type_row, OutgoingPort};
1921

2022
use itertools::Itertools;
@@ -30,7 +32,7 @@ const QB: Type = crate::extension::prelude::QB_T;
3032
/// Version 1 of the Testing HUGR serialisation format, see `testing_hugr.py`.
3133
#[derive(Serialize, Deserialize, PartialEq, Debug, Default)]
3234
struct SerTestingV1 {
33-
typ: Option<crate::types::Type<true>>,
35+
typ: Option<crate::types::TypeRV>,
3436
sum_type: Option<crate::types::SumType>,
3537
poly_func_type: Option<crate::types::PolyFuncType>,
3638
value: Option<crate::ops::Value>,
@@ -85,7 +87,7 @@ macro_rules! impl_sertesting_from {
8587
};
8688
}
8789

88-
impl_sertesting_from!(crate::types::Type<true>, typ);
90+
impl_sertesting_from!(crate::types::TypeRV, typ);
8991
impl_sertesting_from!(crate::types::SumType, sum_type);
9092
impl_sertesting_from!(crate::types::PolyFuncType, poly_func_type);
9193
impl_sertesting_from!(crate::ops::Value, value);
@@ -99,9 +101,9 @@ impl From<PolyFuncType<false>> for TestingModel {
99101
}
100102
}
101103

102-
impl From<Type<false>> for TestingModel {
103-
fn from(v: Type<false>) -> Self {
104-
let t: Type<true> = v.into();
104+
impl From<Type> for TestingModel {
105+
fn from(v: Type) -> Self {
106+
let t: TypeRV = v.into();
105107
t.into()
106108
}
107109
}
@@ -382,16 +384,15 @@ fn constants_roundtrip() -> Result<(), Box<dyn std::error::Error>> {
382384

383385
#[test]
384386
fn serialize_types_roundtrip() {
385-
let g: Type<true> = Type::new_function(FunctionType::new_endo(vec![]));
386-
387+
let g = Type::new_function(FunctionType::new_endo(vec![]));
387388
check_testing_roundtrip(g.clone());
388389

389390
// A Simple tuple
390-
let t: Type = Type::new_tuple(vec![USIZE_T.into(), g]);
391+
let t = Type::new_tuple(vec![USIZE_T.into(), g]);
391392
check_testing_roundtrip(t);
392393

393394
// A Classic sum
394-
let t: Type<true> = Type::new_sum([type_row![USIZE_T], type_row![FLOAT64_TYPE]]);
395+
let t = TypeRV::new_sum([type_row![USIZE_T], type_row![FLOAT64_TYPE]]);
395396
check_testing_roundtrip(t);
396397

397398
let t: Type = Type::new_unit_sum(4);
@@ -438,11 +439,11 @@ fn polyfunctype1() -> PolyFuncType<false> {
438439
}
439440

440441
fn polyfunctype2() -> PolyFuncType {
441-
let tv0 = Type::new_row_var_use(0, TypeBound::Any);
442-
let tv1 = Type::new_row_var_use(1, TypeBound::Eq);
442+
let tv0 = TypeRV::new_row_var_use(0, TypeBound::Any);
443+
let tv1 = TypeRV::new_row_var_use(1, TypeBound::Eq);
443444
let params = [TypeBound::Any, TypeBound::Eq].map(TypeParam::new_list);
444445
let inputs = vec![
445-
Type::new_function(FunTypeVarArgs::new(tv0.clone(), tv1.clone())),
446+
TypeRV::new_function(FunTypeVarArgs::new(tv0.clone(), tv1.clone())),
446447
tv0,
447448
];
448449
let res = PolyFuncType::new(params, FunTypeVarArgs::new(inputs, tv1));
@@ -461,7 +462,7 @@ fn polyfunctype2() -> PolyFuncType {
461462
#[case(PolyFuncType::new([TypeParam::Tuple { params: [TypeBound::Any.into(), TypeParam::bounded_nat(2.try_into().unwrap())].into() }], FunctionType::new_endo(type_row![])))]
462463
#[case(PolyFuncType::new(
463464
[TypeParam::new_list(TypeBound::Any)],
464-
FunctionType::new_endo(Type::new_tuple(Type::new_row_var_use(0, TypeBound::Any)))))]
465+
FunctionType::new_endo(Type::new_tuple(TypeRV::new_row_var_use(0, TypeBound::Any)))))]
465466
fn roundtrip_polyfunctype_fixedlen(#[case] poly_func_type: PolyFuncType<false>) {
466467
check_testing_roundtrip(poly_func_type)
467468
}
@@ -474,7 +475,7 @@ fn roundtrip_polyfunctype_fixedlen(#[case] poly_func_type: PolyFuncType<false>)
474475
#[case(PolyFuncType::new([TypeParam::Tuple { params: [TypeBound::Any.into(), TypeParam::bounded_nat(2.try_into().unwrap())].into() }], FunctionType::new_endo(type_row![])))]
475476
#[case(PolyFuncType::new(
476477
[TypeParam::new_list(TypeBound::Any)],
477-
FunTypeVarArgs::new_endo(Type::new_row_var_use(0, TypeBound::Any))))]
478+
FunTypeVarArgs::new_endo(TypeRV::new_row_var_use(0, TypeBound::Any))))]
478479
#[case(polyfunctype2())]
479480
fn roundtrip_polyfunctype_varlen(#[case] poly_func_type: PolyFuncType<true>) {
480481
check_testing_roundtrip(poly_func_type)

hugr-core/src/hugr/validate/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::std_extensions::logic::test::{and_op, or_op};
1818
use crate::std_extensions::logic::{self, NotOp};
1919
use crate::types::type_param::{TypeArg, TypeArgError};
2020
use crate::types::{
21-
CustomType, FunTypeVarArgs, FunctionType, PolyFuncType, Type, TypeBound, TypeRow,
21+
CustomType, FunTypeVarArgs, FunctionType, PolyFuncType, Type, TypeBound, TypeRV, TypeRow,
2222
};
2323
use crate::{const_extension_ids, type_row, Direction, IncomingPort, Node};
2424

@@ -573,16 +573,16 @@ pub(crate) fn extension_with_eval_parallel() -> Extension {
573573
let rowp = TypeParam::new_list(TypeBound::Any);
574574
let mut e = Extension::new(EXT_ID);
575575

576-
let inputs = Type::new_row_var_use(0, TypeBound::Any);
577-
let outputs = Type::new_row_var_use(1, TypeBound::Any);
578-
let evaled_fn = Type::new_function(FunTypeVarArgs::new(inputs.clone(), outputs.clone()));
576+
let inputs = TypeRV::new_row_var_use(0, TypeBound::Any);
577+
let outputs = TypeRV::new_row_var_use(1, TypeBound::Any);
578+
let evaled_fn = TypeRV::new_function(FunTypeVarArgs::new(inputs.clone(), outputs.clone()));
579579
let pf = PolyFuncType::new(
580580
[rowp.clone(), rowp.clone()],
581581
FunTypeVarArgs::new(vec![evaled_fn, inputs], outputs),
582582
);
583583
e.add_op("eval".into(), "".into(), pf).unwrap();
584584

585-
let rv = |idx| Type::new_row_var_use(idx, TypeBound::Any);
585+
let rv = |idx| TypeRV::new_row_var_use(idx, TypeBound::Any);
586586
let pf = PolyFuncType::new(
587587
[rowp.clone(), rowp.clone(), rowp.clone(), rowp.clone()],
588588
FunctionType::new(
@@ -630,7 +630,7 @@ fn instantiate_row_variables() -> Result<(), Box<dyn std::error::Error>> {
630630
Ok(())
631631
}
632632

633-
fn seq1ty(t: Type<true>) -> TypeArg {
633+
fn seq1ty(t: TypeRV) -> TypeArg {
634634
TypeArg::Sequence {
635635
elems: vec![t.into()],
636636
}
@@ -639,7 +639,7 @@ fn seq1ty(t: Type<true>) -> TypeArg {
639639
#[test]
640640
fn row_variables() -> Result<(), Box<dyn std::error::Error>> {
641641
let e = extension_with_eval_parallel();
642-
let tv = Type::new_row_var_use(0, TypeBound::Any);
642+
let tv = TypeRV::new_row_var_use(0, TypeBound::Any);
643643
let inner_ft = Type::new_function(FunTypeVarArgs::new_endo(tv.clone()));
644644
let ft_usz = Type::new_function(FunTypeVarArgs::new_endo(vec![tv.clone(), USIZE_T.into()]));
645645
let mut fb = FunctionBuilder::new(

hugr-core/src/ops/constant.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,12 @@ mod test {
688688
32, // Target around 32 total elements
689689
3, // Each collection is up to 3 elements long
690690
|child_strat| {
691-
(any::<Type<false>>(), vec(child_strat, 0..3)).prop_map(
692-
|(typ, children)| {
693-
Self::new(ListValue::new(
694-
typ,
695-
children.into_iter().map(|e| Value::Extension { e }),
696-
))
697-
},
698-
)
691+
(any::<Type>(), vec(child_strat, 0..3)).prop_map(|(typ, children)| {
692+
Self::new(ListValue::new(
693+
typ,
694+
children.into_iter().map(|e| Value::Extension { e }),
695+
))
696+
})
699697
},
700698
)
701699
.boxed()

hugr-core/src/std_extensions/arithmetic/conversions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
},
1313
ops::{custom::ExtensionOp, NamedOp},
1414
type_row,
15-
types::{FunTypeVarArgs, PolyFuncType, Type, TypeArg},
15+
types::{FunTypeVarArgs, PolyFuncType, TypeArg, TypeRV},
1616
Extension,
1717
};
1818

@@ -46,7 +46,7 @@ impl MakeOpDef for ConvertOpDef {
4646
match self {
4747
trunc_s | trunc_u => FunTypeVarArgs::new(
4848
type_row![FLOAT64_TYPE],
49-
Type::<true>::from(sum_with_error(int_tv(0))),
49+
TypeRV::from(sum_with_error(int_tv(0))),
5050
),
5151
convert_s | convert_u => {
5252
FunTypeVarArgs::new(vec![int_tv(0)], type_row![FLOAT64_TYPE])

0 commit comments

Comments
 (0)