Skip to content

Commit 23db41d

Browse files
committed
remove type annots, fix doclinks, various comments
1 parent 3477596 commit 23db41d

File tree

12 files changed

+35
-34
lines changed

12 files changed

+35
-34
lines changed

hugr-core/src/extension/op_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl SignatureFunc {
235235
args: &[TypeArg],
236236
exts: &ExtensionRegistry,
237237
) -> Result<FunctionType, SignatureError> {
238-
let temp: TypeSchemeRV;
238+
let temp: TypeSchemeRV; // to keep alive
239239
let (pf, args) = match &self {
240240
SignatureFunc::TypeScheme(custom) => {
241241
custom.validate.validate(args, def, exts)?;

hugr-core/src/extension/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ mod test {
436436
.instantiate([])
437437
.unwrap();
438438

439-
let ext_type: Type = Type::new_extension(ext_def);
439+
let ext_type = Type::new_extension(ext_def);
440440
assert_eq!(ext_type, ERROR_TYPE);
441441

442442
let error_val = ConstError::new(2, "my message");

hugr-core/src/extension/type_def.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ mod test {
182182
description: "Some parametrised type".into(),
183183
bound: TypeDefBound::FromParams(vec![0]),
184184
};
185-
let typ: Type = Type::new_extension(
185+
let typ = Type::new_extension(
186186
def.instantiate(vec![TypeArg::Type {
187187
ty: Type::new_function(FunctionType::new(vec![], vec![])),
188188
}])
189189
.unwrap(),
190190
);
191191
assert_eq!(typ.least_upper_bound(), TypeBound::Copyable);
192-
let typ2: Type = Type::new_extension(def.instantiate([USIZE_T.into()]).unwrap());
192+
let typ2 = Type::new_extension(def.instantiate([USIZE_T.into()]).unwrap());
193193
assert_eq!(typ2.least_upper_bound(), TypeBound::Eq);
194194

195195
// And some bad arguments...firstly, wrong kind of TypeArg:

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn constants_roundtrip() -> Result<(), Box<dyn std::error::Error>> {
381381

382382
#[test]
383383
fn serialize_types_roundtrip() {
384-
let g = Type::new_function(FunctionType::new_endo(vec![]));
384+
let g: Type = Type::new_function(FunctionType::new_endo(vec![]));
385385
check_testing_roundtrip(g.clone());
386386

387387
// A Simple tuple
@@ -392,7 +392,7 @@ fn serialize_types_roundtrip() {
392392
let t = TypeRV::new_sum([type_row![USIZE_T], type_row![FLOAT64_TYPE]]);
393393
check_testing_roundtrip(t);
394394

395-
let t: Type = Type::new_unit_sum(4);
395+
let t = Type::new_unit_sum(4);
396396
check_testing_roundtrip(t);
397397
}
398398

hugr-core/src/hugr/validate.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,8 @@ impl<'a, 'b> ValidationContext<'a, 'b> {
298298
match &port_kind {
299299
EdgeKind::Value(ty) => ty.validate(self.extension_registry, var_decls),
300300
// Static edges must *not* refer to type variables declared by enclosing FuncDefns
301-
// as these are only types at runtime. (Note the choice of `allow_row_vars` as `false` is arbitrary here.)
301+
// as these are only types at runtime.
302302
EdgeKind::Const(ty) => ty.validate(self.extension_registry, &[]),
303-
// Allow function "value" to have unknown arity. A Call node will have to provide
304-
// TypeArgs that produce a known arity, but a LoadFunction might pass the function
305-
// value ("function pointer") around without knowing how to call it.
306303
EdgeKind::Function(pf) => pf.validate(self.extension_registry),
307304
_ => Ok(()),
308305
}

hugr-core/src/ops/constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ mod test {
593593
fn function_value(simple_dfg_hugr: Hugr) {
594594
let v = Value::function(simple_dfg_hugr).unwrap();
595595

596-
let correct_type: Type = Type::new_function(FunctionType::new_endo(type_row![
596+
let correct_type = Type::new_function(FunctionType::new_endo(type_row![
597597
crate::extension::prelude::BOOL_T
598598
]));
599599

@@ -652,12 +652,12 @@ mod test {
652652
let yaml_const: Value =
653653
CustomSerialized::new(typ_int.clone(), YamlValue::Number(6.into()), ex_id.clone())
654654
.into();
655-
let classic_t: Type = Type::new_extension(typ_int.clone());
655+
let classic_t = Type::new_extension(typ_int.clone());
656656
assert_matches!(classic_t.least_upper_bound(), TypeBound::Eq);
657657
assert_eq!(yaml_const.get_type(), classic_t);
658658

659659
let typ_qb = CustomType::new("my_type", vec![], ex_id, TypeBound::Eq);
660-
let t: Type = Type::new_extension(typ_qb.clone());
660+
let t = Type::new_extension(typ_qb.clone());
661661
assert_ne!(yaml_const.get_type(), t);
662662
}
663663

hugr-core/src/types.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub enum EdgeKind {
5050
Value(Type),
5151
/// A reference to a static constant value - must be a Copyable type
5252
Const(Type),
53-
/// A reference to a function i.e. [FuncDecl] or [FuncDefn]
53+
/// A reference to a function i.e. [FuncDecl] or [FuncDefn].
5454
///
5555
/// [FuncDecl]: crate::ops::FuncDecl
5656
/// [FuncDefn]: crate::ops::FuncDefn
@@ -259,7 +259,7 @@ impl<RV: MaybeRV> TypeEnum<RV> {
259259
/// # use hugr::types::{Type, TypeBound};
260260
/// # use hugr::type_row;
261261
///
262-
/// let sum: Type = Type::new_sum([type_row![], type_row![]]);
262+
/// let sum = Type::new_sum([type_row![], type_row![]]);
263263
/// assert_eq!(sum.least_upper_bound(), TypeBound::Eq);
264264
/// ```
265265
///
@@ -614,7 +614,6 @@ pub(crate) mod test {
614614
assert_eq!(pred1, pred2);
615615

616616
let pred_direct = SumType::Unit { size: 2 };
617-
// Pick <false> arbitrarily
618617
assert_eq!(pred1, Type::from(pred_direct));
619618
}
620619

hugr-core/src/types/poly_func.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ use super::{signature::FuncTypeBase, MaybeRV, NoRV, RowVariable};
2828
"params.iter().map(ToString::to_string).join(\" \")",
2929
"body"
3030
)]
31-
pub struct TypeSchemeBase<ROWVARS: MaybeRV = RowVariable> {
31+
pub struct TypeSchemeBase<RV: MaybeRV> {
3232
/// The declared type parameters, i.e., these must be instantiated with
3333
/// the same number of [TypeArg]s before the function can be called. This
3434
/// defines the indices used by variables inside the body.
3535
#[cfg_attr(test, proptest(strategy = "vec(any_with::<TypeParam>(params), 0..3)"))]
3636
params: Vec<TypeParam>,
3737
/// Template for the function. May contain variables up to length of [Self::params]
38-
#[cfg_attr(test, proptest(strategy = "any_with::<FuncTypeBase<ROWVARS>>(params)"))]
39-
body: FuncTypeBase<ROWVARS>,
38+
#[cfg_attr(test, proptest(strategy = "any_with::<FuncTypeBase<RV>>(params)"))]
39+
body: FuncTypeBase<RV>,
4040
}
4141

4242
/// The polymorphic type of a [Call]-able function ([FuncDecl] or [FuncDefn]).
@@ -106,7 +106,7 @@ impl<RV: MaybeRV> TypeSchemeBase<RV> {
106106
}
107107

108108
/// Create a new TypeSchemeBase given the kinds of the variables it declares
109-
/// and the underlying function type.
109+
/// and the underlying [FuncTypeBase].
110110
pub fn new(params: impl Into<Vec<TypeParam>>, body: impl Into<FuncTypeBase<RV>>) -> Self {
111111
Self {
112112
params: params.into(),

hugr-core/src/types/serialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<RV: MaybeRV> TryFrom<SerSimpleType> for TypeBase<RV> {
5858
SerSimpleType::Opaque(o) => TypeBase::new_extension(o),
5959
SerSimpleType::Alias(a) => TypeBase::new_alias(a),
6060
SerSimpleType::V { i, b } => TypeBase::new_var_use(i, b),
61-
// We can't use new_row_var because that returns Type<true> not Type<RV>.
61+
// We can't use new_row_var because that returns TypeRV not TypeBase<RV>.
6262
SerSimpleType::R { i, b } => TypeBase::new(TypeEnum::RowVar(
6363
RV::try_from_rv(RowVariable(i, b))
6464
.map_err(|var| SignatureError::RowVarWhereTypeExpected { var })?,

hugr-core/src/types/signature.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use {crate::proptest::RecursionDepth, ::proptest::prelude::*, proptest_derive::A
1717

1818
#[derive(Clone, Debug, Eq, serde::Serialize, serde::Deserialize)]
1919
#[cfg_attr(test, derive(Arbitrary), proptest(params = "RecursionDepth"))]
20-
/// Describes the edges required to/from a node (when ROWVARS=false);
21-
/// or (when ROWVARS=true) the type of a [Graph] or the inputs/outputs from an OpDef
20+
/// Describes the edges required to/from a node or inside a [FuncDefn] (when ROWVARS=[NoRV]);
21+
/// or (when ROWVARS=[RowVariable]) the type of a higher-order [function value] or the inputs/outputs from an OpDef
2222
///
2323
/// ROWVARS specifies whether it may contain [RowVariable]s or not.
2424
///
25-
/// [Graph]: crate::ops::constant::Value::Function
26-
/// [RowVariable]: crate::types::TypeEnum::RowVariable
25+
/// [function value]: crate::ops::constant::Value::Function
26+
/// [FuncDefn]: crate::ops::FuncDefn
2727
pub struct FuncTypeBase<ROWVARS: MaybeRV> {
2828
/// Value inputs of the function.
2929
#[cfg_attr(test, proptest(strategy = "any_with::<TypeRowBase<ROWVARS>>(params)"))]
@@ -35,12 +35,17 @@ pub struct FuncTypeBase<ROWVARS: MaybeRV> {
3535
pub extension_reqs: ExtensionSet,
3636
}
3737

38-
/// The concept of "signature" in the spec - the edges required to/from a node or graph
39-
/// and also the target (value) of a call (static).
38+
/// The concept of "signature" in the spec - the edges required to/from a node
39+
/// or within a [FuncDefn], also the target (value) of a call (static).
40+
///
41+
/// [FuncDefn]: crate::ops::FuncDefn
4042
pub type FunctionType = FuncTypeBase<NoRV>;
4143

4244
/// A function that may contain [RowVariable]s and thus has potentially-unknown arity;
43-
/// passable as a value round a Hugr (see [Type::new_function]) but not a valid node type.
45+
/// used for [OpDef]'s and passable as a value round a Hugr (see [Type::new_function])
46+
/// but not a valid node type.
47+
///
48+
/// [OpDef]: crate::extension::OpDef
4449
pub type FunctionTypeRV = FuncTypeBase<RowVariable>;
4550

4651
impl<RV: MaybeRV> FuncTypeBase<RV> {
@@ -63,7 +68,7 @@ impl<RV: MaybeRV> FuncTypeBase<RV> {
6368
Self {
6469
input: input.into(),
6570
output: output.into(),
66-
extension_reqs: ExtensionSet::default(),
71+
extension_reqs: ExtensionSet::new(),
6772
}
6873
}
6974

hugr-core/src/types/type_param.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ impl UpperBound {
4646
}
4747
}
4848

49-
/// A *kind* of [TypeArg]. Thus, a parameter declared by a [TypeSchemeRV] (e.g. [OpDef]),
50-
/// specifying a value that may (resp. must) be provided to instantiate it.
49+
/// A *kind* of [TypeArg]. Thus, a parameter declared by a [TypeScheme] or [TypeSchemeRV],
50+
/// specifying a value that must be provided statically in order to instantiate it.
5151
///
52+
/// [TypeScheme]: super::TypeScheme
5253
/// [TypeSchemeRV]: super::TypeSchemeRV
53-
/// [OpDef]: crate::extension::OpDef
5454
#[derive(
5555
Clone, Debug, PartialEq, Eq, derive_more::Display, serde::Deserialize, serde::Serialize,
5656
)]

hugr/benches/benchmarks/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use criterion::{black_box, criterion_group, AxisScale, Criterion, PlotConfigurat
1010
fn make_complex_type() -> Type {
1111
let qb = QB_T;
1212
let int = USIZE_T;
13-
let q_register: Type = Type::new_tuple(vec![qb; 8]);
13+
let q_register = Type::new_tuple(vec![qb; 8]);
1414
let b_register = Type::new_tuple(vec![int; 8]);
1515
let q_alias = Type::new_alias(AliasDecl::new("QReg", TypeBound::Any));
16-
let sum: Type = Type::new_sum([q_register, q_alias]);
16+
let sum = Type::new_sum([q_register, q_alias]);
1717
Type::new_function(FunctionType::new(vec![sum], vec![b_register]))
1818
}
1919

0 commit comments

Comments
 (0)