Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: getter for PolyFuncType::body #727

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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