diff --git a/src/fun/net_to_term.rs b/src/fun/net_to_term.rs index d1273d09..3b8f80bb 100644 --- a/src/fun/net_to_term.rs +++ b/src/fun/net_to_term.rs @@ -19,6 +19,7 @@ pub fn net_to_term( net, labels, book, + recursive_defs: &book.recursive_defs(), dup_paths: if linear { None } else { Some(Default::default()) }, scope: Default::default(), seen_fans: Default::default(), @@ -72,6 +73,8 @@ pub struct Reader<'a> { seen_fans: Scope, seen: HashSet, errors: Vec, + // + recursive_defs: &'a BTreeSet, } impl Reader<'_> { @@ -140,6 +143,8 @@ impl Reader<'_> { let zero_term = self.read_term(self.net.enter_port(Port(sel_node, 1))); let mut succ_term = self.read_term(self.net.enter_port(Port(sel_node, 2))); + // Call expand_generated in case of succ_term be a lifted term + succ_term.expand_generated(&self.book, &self.recursive_defs); // Succ term should be a lambda let (zero, succ) = match &mut succ_term { diff --git a/src/lib.rs b/src/lib.rs index fc58055b..f3df4c23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,8 +191,8 @@ pub fn readback_hvm_net( let mut diags = Diagnostics::default(); let net = hvm_to_net(net); let mut term = net_to_term(&net, book, labels, linear, &mut diags); - let recursive_cycles = book.recursive_defs(); - term.expand_generated(book, &recursive_cycles); + let recursive_defs = book.recursive_defs(); + term.expand_generated(book, &recursive_defs); term.resugar_strings(adt_encoding); term.resugar_lists(adt_encoding); (term, diags) diff --git a/tests/snapshots/run_file__linearize_match.bend.snap b/tests/snapshots/run_file__linearize_match.bend.snap index 2b91e28e..640e0997 100644 --- a/tests/snapshots/run_file__linearize_match.bend.snap +++ b/tests/snapshots/run_file__linearize_match.bend.snap @@ -3,15 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/linearize_match.bend --- NumScott: -Warnings: -During readback: - Encountered an invalid 'switch'. - -λa switch a = a { 0: λb b; _: λa λb (+ a b); } +λa switch a = a { 0: λb b; _: λb (+ a-1 b); } Scott: -Warnings: -During readback: - Encountered an invalid 'switch'. - -λa switch a = a { 0: λb b; _: λa λb (+ a b); } +λa switch a = a { 0: λb b; _: λb (+ a-1 b); } diff --git a/tests/snapshots/run_file__match_mult_linearization.bend.snap b/tests/snapshots/run_file__match_mult_linearization.bend.snap index b2915107..841ff169 100644 --- a/tests/snapshots/run_file__match_mult_linearization.bend.snap +++ b/tests/snapshots/run_file__match_mult_linearization.bend.snap @@ -3,15 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/match_mult_linearization.bend --- NumScott: -Warnings: -During readback: - Encountered an invalid 'switch'. - -λa switch a = a { 0: λa λb λc (+ (+ a b) c); _: λa λb λc λd (+ (+ (+ a b) c) d); } +λa switch a = a { 0: λa λb λc (+ (+ a b) c); _: λb λc λd (+ (+ (+ a-1 b) c) d); } Scott: -Warnings: -During readback: - Encountered an invalid 'switch'. - -λa switch a = a { 0: λa λb λc (+ (+ a b) c); _: λa λb λc λd (+ (+ (+ a b) c) d); } +λa switch a = a { 0: λa λb λc (+ (+ a b) c); _: λb λc λd (+ (+ (+ a-1 b) c) d); }