From 548188cf20a52473b11ec6a05f1b74f5dbc04e49 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Thu, 30 Nov 2023 17:39:42 +0000 Subject: [PATCH] feat: getter for `PolyFuncType::body` --- src/builder/build_traits.rs | 2 +- src/builder/dataflow.rs | 2 +- src/builder/module.rs | 2 +- src/ops/validate.rs | 2 +- src/types/poly_func.rs | 7 ++++++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/builder/build_traits.rs b/src/builder/build_traits.rs index 9f467426a..833e456c8 100644 --- a/src/builder/build_traits.rs +++ b/src/builder/build_traits.rs @@ -92,7 +92,7 @@ pub trait Container { name: impl Into, signature: PolyFuncType, ) -> Result, 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(), diff --git a/src/builder/dataflow.rs b/src/builder/dataflow.rs index 4761696c7..879b43f93 100644 --- a/src/builder/dataflow.rs +++ b/src/builder/dataflow.rs @@ -147,7 +147,7 @@ impl FunctionBuilder { /// /// Error in adding DFG child nodes. pub fn new(name: impl Into, signature: PolyFuncType) -> Result { - let body = signature.body.clone(); + let body = signature.body().clone(); let op = ops::FuncDefn { signature, name: name.into(), diff --git a/src/builder/module.rs b/src/builder/module.rs index 09ac47da3..174b8028f 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -84,7 +84,7 @@ impl + AsRef> ModuleBuilder { 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 }), diff --git a/src/ops/validate.rs b/src/ops/validate.rs index ae31b8e28..1d6500430 100644 --- a/src/ops/validate.rs +++ b/src/ops/validate.rs @@ -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) } } diff --git a/src/types/poly_func.rs b/src/types/poly_func.rs index 31114ced6..98d2ac1ed 100644 --- a/src/types/poly_func.rs +++ b/src/types/poly_func.rs @@ -31,7 +31,7 @@ pub struct PolyFuncType { /// [TypeArg]: super::type_param::TypeArg params: Vec, /// Template for the function. May contain variables up to length of [Self::params] - pub(crate) body: FunctionType, + body: FunctionType, } impl From for PolyFuncType { @@ -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>, body: FunctionType) -> Self {