Skip to content

Commit

Permalink
feat: don't include empty type args in Display (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Mar 4, 2024
1 parent 065f675 commit 697e7d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
source: src/hugr/views/tests.rs
expression: h.dot_string()
---
"digraph {\n0 [shape=plain label=<<table border=\"1\"><tr><td align=\"text\" border=\"0\" colspan=\"1\">(0) DFG</td></tr></table>>]\n1 [shape=plain label=<<table border=\"1\"><tr><td align=\"text\" border=\"0\" colspan=\"2\">(1) Input</td></tr><tr><td port=\"out0\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >0: qubit([])</td><td port=\"out1\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >1: qubit([])</td></tr></table>>]\n1:out0 -> 3:in0 [style=\"\"]\n1:out1 -> 3:in1 [style=\"\"]\n2 [shape=plain label=<<table border=\"1\"><tr><td port=\"in0\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >0: qubit([])</td><td port=\"in1\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >1: qubit([])</td></tr><tr><td align=\"text\" border=\"0\" colspan=\"2\">(2) Output</td></tr></table>>]\n3 [shape=plain label=<<table border=\"1\"><tr><td port=\"in0\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >0: qubit([])</td><td port=\"in1\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >1: qubit([])</td></tr><tr><td align=\"text\" border=\"0\" colspan=\"6\">(3) test.quantum.CX</td></tr><tr><td port=\"out0\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >0: qubit([])</td><td port=\"out1\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >1: qubit([])</td><td port=\"out2\" align=\"text\" colspan=\"2\" cellpadding=\"1\" border=\"0\"></td></tr></table>>]\n3:out0 -> 4:in1 [style=\"\"]\n3:out1 -> 4:in0 [style=\"\"]\n3:out2 -> 4:in2 [style=\"dotted\"]\n4 [shape=plain label=<<table border=\"1\"><tr><td port=\"in0\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >0: qubit([])</td><td port=\"in1\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >1: qubit([])</td><td port=\"in2\" align=\"text\" colspan=\"2\" cellpadding=\"1\" border=\"0\"></td></tr><tr><td align=\"text\" border=\"0\" colspan=\"6\">(4) test.quantum.CX</td></tr><tr><td port=\"out0\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >0: qubit([])</td><td port=\"out1\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >1: qubit([])</td></tr></table>>]\n4:out0 -> 2:in0 [style=\"\"]\n4:out1 -> 2:in1 [style=\"\"]\nhier0 [shape=plain label=\"0\"]\nhier0 -> hier1 [style = \"dashed\"] \nhier0 -> hier2 [style = \"dashed\"] \nhier0 -> hier3 [style = \"dashed\"] \nhier0 -> hier4 [style = \"dashed\"] \nhier1 [shape=plain label=\"1\"]\nhier2 [shape=plain label=\"2\"]\nhier3 [shape=plain label=\"3\"]\nhier4 [shape=plain label=\"4\"]\n}\n"
"digraph {\n0 [shape=plain label=<<table border=\"1\"><tr><td align=\"text\" border=\"0\" colspan=\"1\">(0) DFG</td></tr></table>>]\n1 [shape=plain label=<<table border=\"1\"><tr><td align=\"text\" border=\"0\" colspan=\"2\">(1) Input</td></tr><tr><td port=\"out0\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >0: qubit</td><td port=\"out1\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >1: qubit</td></tr></table>>]\n1:out0 -> 3:in0 [style=\"\"]\n1:out1 -> 3:in1 [style=\"\"]\n2 [shape=plain label=<<table border=\"1\"><tr><td port=\"in0\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >0: qubit</td><td port=\"in1\" align=\"text\" colspan=\"1\" cellpadding=\"1\" >1: qubit</td></tr><tr><td align=\"text\" border=\"0\" colspan=\"2\">(2) Output</td></tr></table>>]\n3 [shape=plain label=<<table border=\"1\"><tr><td port=\"in0\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >0: qubit</td><td port=\"in1\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >1: qubit</td></tr><tr><td align=\"text\" border=\"0\" colspan=\"6\">(3) test.quantum.CX</td></tr><tr><td port=\"out0\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >0: qubit</td><td port=\"out1\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >1: qubit</td><td port=\"out2\" align=\"text\" colspan=\"2\" cellpadding=\"1\" border=\"0\"></td></tr></table>>]\n3:out0 -> 4:in1 [style=\"\"]\n3:out1 -> 4:in0 [style=\"\"]\n3:out2 -> 4:in2 [style=\"dotted\"]\n4 [shape=plain label=<<table border=\"1\"><tr><td port=\"in0\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >0: qubit</td><td port=\"in1\" align=\"text\" colspan=\"2\" cellpadding=\"1\" >1: qubit</td><td port=\"in2\" align=\"text\" colspan=\"2\" cellpadding=\"1\" border=\"0\"></td></tr><tr><td align=\"text\" border=\"0\" colspan=\"6\">(4) test.quantum.CX</td></tr><tr><td port=\"out0\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >0: qubit</td><td port=\"out1\" align=\"text\" colspan=\"3\" cellpadding=\"1\" >1: qubit</td></tr></table>>]\n4:out0 -> 2:in0 [style=\"\"]\n4:out1 -> 2:in1 [style=\"\"]\nhier0 [shape=plain label=\"0\"]\nhier0 -> hier1 [style = \"dashed\"] \nhier0 -> hier2 [style = \"dashed\"] \nhier0 -> hier3 [style = \"dashed\"] \nhier0 -> hier4 [style = \"dashed\"] \nhier1 [shape=plain label=\"1\"]\nhier2 [shape=plain label=\"2\"]\nhier3 [shape=plain label=\"3\"]\nhier4 [shape=plain label=\"4\"]\n}\n"

3 changes: 1 addition & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ pub(crate) mod test {
]);
assert_eq!(
t.to_string(),
"Tuple([usize([]), Function(forall . [[]][]), my_custom([]), Alias(my_alias)])"
.to_string()
"Tuple([usize, Function(forall . [[]][]), my_custom, Alias(my_alias)])".to_string()
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/types/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ impl CustomType {

impl Display for CustomType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}({:?})", self.id, self.args)
if self.args.is_empty() {
write!(f, "{}", self.id)
} else {
write!(f, "{}({:?})", self.id, self.args)
}
}
}

0 comments on commit 697e7d7

Please sign in to comment.