Skip to content

Commit

Permalink
Fix poly_func display impl
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 17, 2024
1 parent a0a986a commit 6204324
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: hugr-core/src/hugr/views/tests.rs
expression: h.dot_string()
---
digraph {
0 [shape=plain label=<<table border="1"><tr><td align="text" border="0" colspan="1">(0) FuncDefn: "test"</td></tr></table>>]
0 [shape=plain label=<<table border="1"><tr><td align="text" border="0" colspan="1">(0) FuncDefn: "test"</td></tr><tr><td port="out0" align="text" colspan="1" cellpadding="1" >0: [[]+[]] -&gt; [[]][[]+[]]</td></tr></table>>]
1 [shape=plain label=<<table border="1"><tr><td align="text" border="0" colspan="1">(1) Input</td></tr><tr><td port="out0" align="text" colspan="1" cellpadding="1" >0: []+[]</td></tr></table>>]
1:out0 -> 2:in0 [style=""]
2 [shape=plain label=<<table border="1"><tr><td port="in0" align="text" colspan="1" cellpadding="1" >0: []+[]</td></tr><tr><td align="text" border="0" colspan="1">(2) Output</td></tr></table>>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: h.dot_string()
---
digraph {
0 [shape=plain label=<<table border="1"><tr><td align="text" border="0" colspan="1">(0) Module</td></tr></table>>]
1 [shape=plain label=<<table border="1"><tr><td align="text" border="0" colspan="1">(1) FuncDecl: "test"</td></tr><tr><td port="out0" align="text" colspan="1" cellpadding="1" >0: forall params.iter().map(ToString::to_string).join(" "). body</td></tr></table>>]
1 [shape=plain label=<<table border="1"><tr><td align="text" border="0" colspan="1">(1) FuncDecl: "test"</td></tr><tr><td port="out0" align="text" colspan="1" cellpadding="1" >0: [[]+[]] -&gt; [[]][[]+[]]</td></tr></table>>]
hier0 [shape=plain label="0"]
hier0 -> hier1 [style = "dashed"]
hier1 [shape=plain label="1"]
Expand Down
19 changes: 14 additions & 5 deletions hugr-core/src/types/poly_func.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Polymorphic Function Types
use itertools::Itertools;

use crate::extension::{ExtensionRegistry, SignatureError};
#[cfg(test)]
use {
Expand All @@ -22,11 +24,7 @@ use super::{signature::FuncTypeBase, MaybeRV, NoRV, RowVariable};
Clone, PartialEq, Debug, Eq, Hash, derive_more::Display, serde::Serialize, serde::Deserialize,
)]
#[cfg_attr(test, derive(Arbitrary), proptest(params = "RecursionDepth"))]
#[display(
"forall {}. {}",
"params.iter().map(ToString::to_string).join(\" \")",
"body"
)]
#[display("{}{body}", self.display_params())]
pub struct PolyFuncTypeBase<RV: MaybeRV> {
/// The declared type parameters, i.e., these must be instantiated with
/// the same number of [TypeArg]s before the function can be called. This
Expand Down Expand Up @@ -136,6 +134,17 @@ impl<RV: MaybeRV> PolyFuncTypeBase<RV> {
// TODO https://github.com/CQCL/hugr/issues/624 validate TypeParams declared here, too
self.body.validate(reg, &self.params)
}

/// Helper function for the Display implementation
fn display_params(&self) -> String {
if self.params.is_empty() {
return String::new();
}
format!(
"forall {}. ",
self.params.iter().map(ToString::to_string).join(" ")
)
}
}

#[cfg(test)]
Expand Down

0 comments on commit 6204324

Please sign in to comment.