From ddfff57b91a701e2f1d99f0bf2d80d2441b360b8 Mon Sep 17 00:00:00 2001 From: Nicolas Abril Date: Tue, 6 Aug 2024 14:00:09 +0200 Subject: [PATCH] Fix readback when hvm net has `a{n}` or `x{n}` vars --- CHANGELOG.md | 2 ++ src/net/hvm_to_net.rs | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8a582ff6..7d57b3307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project does not currently adhere to a particular versioning scheme. - Fix local definitions not being desugared properly. ([#623][gh-623]) - Expand references to functions generated by the `float_combinators` pass inside the main function. ([#642][gh-642]) - Expand references inside constructors in the main function. ([#643][gh-643]) +- Fix readback when hvm net has `a{n}` or `x{n}` vars. ([#659][gh-659]) ### Added @@ -416,4 +417,5 @@ and this project does not currently adhere to a particular versioning scheme. [gh-642]: https://github.com/HigherOrderCO/Bend/issues/642 [gh-643]: https://github.com/HigherOrderCO/Bend/issues/643 [gh-648]: https://github.com/HigherOrderCO/Bend/issues/648 +[gh-659]: https://github.com/HigherOrderCO/Bend/pull/659 [Unreleased]: https://github.com/HigherOrderCO/Bend/compare/0.2.36...HEAD diff --git a/src/net/hvm_to_net.rs b/src/net/hvm_to_net.rs index 18f7c189a..047ba2dd7 100644 --- a/src/net/hvm_to_net.rs +++ b/src/net/hvm_to_net.rs @@ -23,7 +23,8 @@ fn hvm_to_inodes(net: &Net) -> INodes { // Convert all the trees forming active pairs. for (i, (_, tree1, tree2)) in net.rbag.iter().enumerate() { - let tree_root = format!("a{i}"); + // This name cannot appear anywhere in the original net + let tree_root = format!("%a{i}"); let mut tree1 = tree_to_inodes(tree1, tree_root.clone(), net_root, &mut n_vars); inodes.append(&mut tree1); let mut tree2 = tree_to_inodes(tree2, tree_root, net_root, &mut n_vars); @@ -33,7 +34,8 @@ fn hvm_to_inodes(net: &Net) -> INodes { } fn new_var(n_vars: &mut NodeId) -> String { - let new_var = format!("x{n_vars}"); + // This name cannot appear anywhere in the original net + let new_var = format!("%x{n_vars}"); *n_vars += 1; new_var } @@ -46,7 +48,6 @@ fn tree_to_inodes(tree: &Tree, tree_root: String, net_root: &str, n_vars: &mut N n_vars: &mut NodeId, ) -> String { if let Tree::Var { nam } = subtree { - // if nam == net_root { "_".to_string() } else {