Skip to content

Commit

Permalink
feat: getter for PolyFuncType::body (#727)
Browse files Browse the repository at this point in the history
required to update tket2 to latest hugr commits
  • Loading branch information
ss2165 authored Dec 1, 2023
1 parent 42d0197 commit 5e549f2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub trait Container {
name: impl Into<String>,
signature: PolyFuncType,
) -> Result<FunctionBuilder<&mut Hugr>, BuildError> {
let body = signature.body.clone();
let body = signature.body().clone();
let f_node = self.add_child_node(NodeType::new(
ops::FuncDefn {
name: name.into(),
Expand Down
2 changes: 1 addition & 1 deletion src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl FunctionBuilder<Hugr> {
///
/// Error in adding DFG child nodes.
pub fn new(name: impl Into<String>, signature: PolyFuncType) -> Result<Self, BuildError> {
let body = signature.body.clone();
let body = signature.body().clone();
let op = ops::FuncDefn {
signature,
name: name.into(),
Expand Down
2 changes: 1 addition & 1 deletion src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<T: AsMut<Hugr> + AsRef<Hugr>> ModuleBuilder<T> {
op_desc: "crate::ops::OpType::FuncDecl",
})?
.clone();
let body = signature.body.clone();
let body = signature.body().clone();
self.hugr_mut().replace_op(
f_node,
NodeType::new_pure(ops::FuncDefn { name, signature }),
Expand Down
2 changes: 1 addition & 1 deletion src/ops/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl ValidateOp for super::FuncDefn {
) -> Result<(), ChildrenValidationError> {
// We check type-variables are declared in `validate_subtree`, so here
// we can just assume all type variables are valid regardless of binders.
let FunctionType { input, output, .. } = &self.signature.body;
let FunctionType { input, output, .. } = self.signature.body();
validate_io_nodes(input, output, "function definition", children)
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/types/poly_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct PolyFuncType {
/// [TypeArg]: super::type_param::TypeArg
params: Vec<TypeParam>,
/// Template for the function. May contain variables up to length of [Self::params]
pub(crate) body: FunctionType,
body: FunctionType,
}

impl From<FunctionType> for PolyFuncType {
Expand All @@ -49,6 +49,11 @@ impl PolyFuncType {
&self.params
}

/// The body of the type, a function type.
pub fn body(&self) -> &FunctionType {
&self.body
}

/// Create a new PolyFuncType given the kinds of the variables it declares
/// and the underlying [FunctionType].
pub fn new(params: impl Into<Vec<TypeParam>>, body: FunctionType) -> Self {
Expand Down

0 comments on commit 5e549f2

Please sign in to comment.