Skip to content

Commit

Permalink
Rename: PolyFixedFunc -> PolyFuncType (consistent, but seems misleadi…
Browse files Browse the repository at this point in the history
…ng); doc
  • Loading branch information
acl-cqc committed Apr 2, 2024
1 parent 57a71b0 commit c36780e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions quantinuum-hugr/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub(crate) mod test {

use crate::hugr::{views::HugrView, HugrMut, NodeType};
use crate::ops;
use crate::types::{FunctionType, PolyFixedFunc, Type};
use crate::types::{FunctionType, PolyFuncType, Type};
use crate::{type_row, Hugr};

use super::handle::BuildHandle;
Expand All @@ -246,7 +246,7 @@ pub(crate) mod test {
}

pub(super) fn build_main(
signature: PolyFixedFunc,
signature: PolyFuncType,
f: impl FnOnce(FunctionBuilder<&mut Hugr>) -> Result<BuildHandle<FuncID<true>>, BuildError>,
) -> Result<Hugr, BuildError> {
let mut module_builder = ModuleBuilder::new();
Expand Down
4 changes: 2 additions & 2 deletions quantinuum-hugr/src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
};

use crate::extension::{ExtensionRegistry, ExtensionSet, PRELUDE_REGISTRY};
use crate::types::{FunctionType, PolyFixedFunc, Type, TypeArg, TypeRow};
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeRow};

use itertools::Itertools;

Expand Down Expand Up @@ -85,7 +85,7 @@ pub trait Container {
fn define_function(
&mut self,
name: impl Into<String>,
signature: impl Into<PolyFixedFunc>,
signature: impl Into<PolyFuncType>,
) -> Result<FunctionBuilder<&mut Hugr>, BuildError> {
let signature = signature.into();
let body = signature.body().clone();
Expand Down
4 changes: 2 additions & 2 deletions quantinuum-hugr/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::marker::PhantomData;
use crate::hugr::{HugrView, NodeType, ValidationError};
use crate::ops;

use crate::types::{FunctionType, PolyFixedFunc};
use crate::types::{FunctionType, PolyFuncType};

use crate::extension::{ExtensionRegistry, ExtensionSet};
use crate::Node;
Expand Down Expand Up @@ -147,7 +147,7 @@ impl FunctionBuilder<Hugr> {
/// # Errors
///
/// Error in adding DFG child nodes.
pub fn new(name: impl Into<String>, signature: PolyFixedFunc) -> Result<Self, BuildError> {
pub fn new(name: impl Into<String>, signature: PolyFuncType) -> Result<Self, BuildError> {
let body = signature.body().clone();
let op = ops::FuncDefn {
signature,
Expand Down
4 changes: 2 additions & 2 deletions quantinuum-hugr/src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
extension::ExtensionRegistry,
hugr::{hugrmut::sealed::HugrMutInternals, views::HugrView, ValidationError},
ops,
types::{PolyFixedFunc, Type, TypeBound},
types::{PolyFuncType, Type, TypeBound},
};

use crate::ops::handle::{AliasID, FuncID, NodeHandle};
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<T: AsMut<Hugr> + AsRef<Hugr>> ModuleBuilder<T> {
pub fn declare(
&mut self,
name: impl Into<String>,
signature: PolyFixedFunc,
signature: PolyFuncType,
) -> Result<FuncID<false>, BuildError> {
// TODO add param names to metadata
let declare_n = self.add_child_node(NodeType::new_pure(ops::FuncDecl {
Expand Down
20 changes: 10 additions & 10 deletions quantinuum-hugr/src/hugr/validate/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::std_extensions::logic::{self, NotOp};
use crate::types::type_param::{TypeArg, TypeArgError, TypeParam};
use crate::types::type_row::RowVarOrType;
use crate::types::{
CustomType, FuncTypeVarLen, FunctionType, PolyFixedFunc, Type, TypeBound, TypeRow,
CustomType, FuncTypeVarLen, FunctionType, PolyFuncType, Type, TypeBound, TypeRow,
};
use crate::{type_row, Direction, IncomingPort, Node};

Expand Down Expand Up @@ -435,7 +435,7 @@ fn typevars_declared() -> Result<(), Box<dyn std::error::Error>> {
// Base case
let f = FunctionBuilder::new(
"myfunc",
PolyFixedFunc::new(
PolyFuncType::new(
[TypeBound::Any.into()],
FunctionType::new_endo(vec![Type::new_var_use(0, TypeBound::Any)]),
),
Expand All @@ -445,7 +445,7 @@ fn typevars_declared() -> Result<(), Box<dyn std::error::Error>> {
// Type refers to undeclared variable
let f = FunctionBuilder::new(
"myfunc",
PolyFixedFunc::new(
PolyFuncType::new(
[TypeBound::Any.into()],
FunctionType::new_endo(vec![Type::new_var_use(1, TypeBound::Any)]),
),
Expand All @@ -455,7 +455,7 @@ fn typevars_declared() -> Result<(), Box<dyn std::error::Error>> {
// Variable declaration incorrectly copied to use site
let f = FunctionBuilder::new(
"myfunc",
PolyFixedFunc::new(
PolyFuncType::new(
[TypeBound::Any.into()],
FunctionType::new_endo(vec![Type::new_var_use(1, TypeBound::Copyable)]),
),
Expand All @@ -473,14 +473,14 @@ fn nested_typevars() -> Result<(), Box<dyn std::error::Error>> {
fn build(t: Type) -> Result<Hugr, BuildError> {
let mut outer = FunctionBuilder::new(
"outer",
PolyFixedFunc::new(
PolyFuncType::new(
[OUTER_BOUND.into()],
FunctionType::new_endo(vec![Type::new_var_use(0, TypeBound::Any)]),
),
)?;
let inner = outer.define_function(
"inner",
PolyFixedFunc::new([INNER_BOUND.into()], FunctionType::new_endo(vec![t])),
PolyFuncType::new([INNER_BOUND.into()], FunctionType::new_endo(vec![t])),
)?;
let [w] = inner.input_wires_arr();
inner.finish_with_outputs([w])?;
Expand Down Expand Up @@ -519,7 +519,7 @@ fn no_polymorphic_consts() -> Result<(), Box<dyn std::error::Error>> {
let reg = ExtensionRegistry::try_new([collections::EXTENSION.to_owned()]).unwrap();
let mut def = FunctionBuilder::new(
"myfunc",
PolyFixedFunc::new(
PolyFuncType::new(
[BOUND],
FunctionType::new(type_row![], vec![list_of_var.clone()])
.with_extension_delta(collections::EXTENSION_NAME),
Expand Down Expand Up @@ -550,7 +550,7 @@ fn inner_row_variables() -> Result<(), Box<dyn std::error::Error>> {
let inner_ft = Type::new_function(FuncTypeVarLen::new_endo(vec![tv]));
let mut fb = FunctionBuilder::new(
"id",
PolyFixedFunc::new(
PolyFuncType::new(
[TypeParam::List {
param: Box::new(TypeParam::Type { b: TypeBound::Any }),
}],
Expand All @@ -569,7 +569,7 @@ fn no_outer_row_variables() -> Result<(), Box<dyn std::error::Error>> {
let tv = Type::new_var_use(0, TypeBound::Any);
let fb = FunctionBuilder::new(
"impossible_id_of_unknown_arity",
PolyFixedFunc::new(
PolyFuncType::new(
[TypeParam::List {
param: Box::new(TypeParam::Type { b: TypeBound::Any }),
}],
Expand All @@ -596,7 +596,7 @@ fn test_polymorphic_call() -> Result<(), Box<dyn std::error::Error>> {
let mut m = ModuleBuilder::new();
let id = m.declare(
"id",
PolyFixedFunc::new(
PolyFuncType::new(
vec![TypeBound::Any.into()],
FunctionType::new_endo(vec![Type::new_var_use(0, TypeBound::Any)]),
),
Expand Down
6 changes: 3 additions & 3 deletions quantinuum-hugr/src/hugr/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::ops::handle::NodeHandle;
use crate::ops::{OpParent, OpTag, OpTrait, OpType};

use crate::types::Type;
use crate::types::{EdgeKind, FunctionType, PolyFixedFunc};
use crate::types::{EdgeKind, FunctionType, PolyFuncType};
use crate::{Direction, IncomingPort, Node, OutgoingPort, Port};

use itertools::Either;
Expand Down Expand Up @@ -351,12 +351,12 @@ pub trait HugrView: sealed::HugrInternals {
/// operation, report the signature of the inner dataflow sibling graph.
///
/// Otherwise, returns `None`.
fn get_function_type(&self) -> Option<PolyFixedFunc> {
fn get_function_type(&self) -> Option<PolyFuncType> {
let op = self.get_optype(self.root());
match op {
OpType::FuncDecl(decl) => Some(decl.signature.clone()),
OpType::FuncDefn(defn) => Some(defn.signature.clone()),
_ => op.inner_function_type().map(PolyFixedFunc::from),
_ => op.inner_function_type().map(PolyFuncType::from),
}
}

Expand Down
10 changes: 5 additions & 5 deletions quantinuum-hugr/src/ops/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{impl_op_name, OpTag, OpTrait};

use crate::extension::{ExtensionRegistry, ExtensionSet, SignatureError};
use crate::ops::StaticTag;
use crate::types::{EdgeKind, FunctionType, PolyFixedFunc, Type, TypeArg, TypeRow};
use crate::types::{EdgeKind, FunctionType, PolyFuncType, Type, TypeArg, TypeRow};
use crate::IncomingPort;

pub(crate) trait DataflowOpTrait {
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<T: DataflowOpTrait> StaticTag for T {
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct Call {
/// Signature of function being called
func_sig: PolyFixedFunc,
func_sig: PolyFuncType,
type_args: Vec<TypeArg>,
instantiation: FunctionType, // Cache, so we can fail in try_new() not in signature()
}
Expand Down Expand Up @@ -181,7 +181,7 @@ impl Call {
///
/// [TypeParam]: crate::types::type_param::TypeParam
pub fn try_new(
func_sig: PolyFixedFunc,
func_sig: PolyFuncType,
type_args: impl Into<Vec<TypeArg>>,
exts: &ExtensionRegistry,
) -> Result<Self, SignatureError> {
Expand All @@ -196,7 +196,7 @@ impl Call {

#[inline]
/// Return the signature of the function called by this op.
pub fn called_function_type(&self) -> &PolyFixedFunc {
pub fn called_function_type(&self) -> &PolyFuncType {
&self.func_sig
}

Expand Down Expand Up @@ -246,7 +246,7 @@ impl DataflowOpTrait for CallIndirect {
let mut s = self.signature.clone();
s.input.to_mut().insert(
0,
Type::new_function(PolyFixedFunc::from(self.signature.clone())),
Type::new_function(PolyFuncType::from(self.signature.clone())),
);
s
}
Expand Down
6 changes: 3 additions & 3 deletions quantinuum-hugr/src/ops/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use smol_str::SmolStr;

use crate::types::{EdgeKind, FunctionType, PolyFixedFunc};
use crate::types::{EdgeKind, FunctionType, PolyFuncType};
use crate::types::{Type, TypeBound};

use super::dataflow::DataflowParent;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub struct FuncDefn {
/// Name of function
pub name: String,
/// Signature of the function
pub signature: PolyFixedFunc,
pub signature: PolyFuncType,
}

impl_op_name!(FuncDefn);
Expand Down Expand Up @@ -71,7 +71,7 @@ pub struct FuncDecl {
/// Name of function
pub name: String,
/// Signature of the function
pub signature: PolyFixedFunc,
pub signature: PolyFuncType,
}

impl_op_name!(FuncDecl);
Expand Down
2 changes: 1 addition & 1 deletion quantinuum-hugr/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use crate::ops::constant::{ConstTypeError, CustomCheckFailure};
use crate::utils::display_list_with_separator;
pub use check::SumTypeError;
pub use custom::CustomType;
pub use poly_func::{PolyFixedFunc, PolyFuncVarLen};
pub use poly_func::{PolyFuncType, PolyFuncVarLen};
pub use signature::{FuncTypeVarLen, FunctionType};
use smol_str::SmolStr;
pub use type_param::TypeArg;
Expand Down
8 changes: 5 additions & 3 deletions quantinuum-hugr/src/types/poly_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ where
/// Type of a function polymorphic over some variables,
/// which may include row variables.
pub type PolyFuncVarLen = PolyFuncBase<RowVarOrType>;
pub type PolyFixedFunc = PolyFuncBase<Type>;

/// Type of a function polymorphic only over types; i.e. fixed arity.
pub type PolyFuncType = PolyFuncBase<Type>;

impl<T: TypeRowElem> From<FuncTypeBase<T>> for PolyFuncBase<T>
where
Expand All @@ -60,8 +62,8 @@ where
}
}

impl From<PolyFixedFunc> for PolyFuncVarLen {
fn from(value: PolyFixedFunc) -> Self {
impl From<PolyFuncType> for PolyFuncVarLen {
fn from(value: PolyFuncType) -> Self {
Self {
params: value.params,
body: value.body.into(),
Expand Down

0 comments on commit c36780e

Please sign in to comment.