From 94cada901d95d6218bd5a20a591a465da986b558 Mon Sep 17 00:00:00 2001 From: Nicolas Abril Date: Wed, 5 Jun 2024 19:02:44 +0200 Subject: [PATCH 1/2] Expand refs in main, don't float combinators in main --- src/fun/transform/expand_main.rs | 121 ++++++++++++++++++ src/fun/transform/float_combinators.rs | 9 ++ src/fun/transform/mod.rs | 1 + src/lib.rs | 2 + .../run_file/unused_main_var.bend | 15 +++ tests/snapshots/cli__compile_all.bend.snap | 8 +- .../cli__desugar_bool_scott.bend.snap | 2 +- .../cli__desugar_float_combinators.bend.snap | 6 +- tests/snapshots/cli__desugar_merge.bend.snap | 2 +- .../cli__no_check_net_size.bend.snap | 16 +-- tests/snapshots/cli__run_pretty.bend.snap | 4 +- .../compile_file__addition.bend.snap | 6 +- .../compile_file__church_one.bend.snap | 6 +- tests/snapshots/compile_file__elif.bend.snap | 19 +-- .../snapshots/compile_file__fst_snd.bend.snap | 12 +- tests/snapshots/compile_file__lets.bend.snap | 14 +- .../compile_file__ref_to_ref.bend.snap | 2 +- ...mpile_file__switch_in_switch_arg.bend.snap | 4 +- .../compile_file__vicious_circles.bend.snap | 2 + .../compile_file_o_all__addition.bend.snap | 6 +- .../compile_file_o_all__ex2.bend.snap | 6 +- .../compile_file_o_all__exp.bend.snap | 8 +- ...pile_file_o_all__linearize_match.bend.snap | 4 +- ...pile_file_o_all__list_merge_sort.bend.snap | 8 +- ..._o_all__match_mult_linearization.bend.snap | 6 +- .../desugar_file__bind_syntax.bend.snap | 10 +- .../desugar_file__combinators.bend.snap | 2 +- .../desugar_file__mapper_syntax.bend.snap | 20 +-- .../desugar_file__switch_with_use.bend.snap | 4 +- .../run_file__adt_option_and.bend.snap | 4 +- tests/snapshots/run_file__exp.bend.snap | 15 ++- .../run_file__imp_empty_literals.bend.snap | 4 +- .../run_file__linearize_match.bend.snap | 12 +- .../run_file__mapper_syntax.bend.snap | 4 +- ...n_file__match_mult_linearization.bend.snap | 12 +- ...run_file__match_num_succ_complex.bend.snap | 4 +- tests/snapshots/run_file__queue.bend.snap | 4 +- .../run_file__unused_main_var.bend.snap | 9 ++ 38 files changed, 250 insertions(+), 143 deletions(-) create mode 100644 src/fun/transform/expand_main.rs create mode 100644 tests/golden_tests/run_file/unused_main_var.bend create mode 100644 tests/snapshots/run_file__unused_main_var.bend.snap diff --git a/src/fun/transform/expand_main.rs b/src/fun/transform/expand_main.rs new file mode 100644 index 000000000..8bf3d418d --- /dev/null +++ b/src/fun/transform/expand_main.rs @@ -0,0 +1,121 @@ +use crate::{ + fun::{Book, Name, Pattern, Term}, + maybe_grow, +}; +use std::collections::HashMap; + +impl Book { + /// Expands the main function so that it is not just a reference. + /// While technically correct, directly returning a reference is never what users want. + pub fn expand_main(&mut self) { + if self.entrypoint.is_none() { + return; + } + + let main = self.defs.get_mut(self.entrypoint.as_ref().unwrap()).unwrap(); + let mut main_bod = std::mem::take(&mut main.rule_mut().body); + + let mut seen = vec![self.entrypoint.as_ref().unwrap().clone()]; + main_bod.expand_ref_return(self, &mut seen, &mut 0); + + let main = self.defs.get_mut(self.entrypoint.as_ref().unwrap()).unwrap(); + main.rule_mut().body = main_bod; + } +} + +impl Term { + /// Expands references in the main function that are in "return" position. + /// + /// This applies to: + /// - When main returns a reference. + /// - When main returns a lambda whose body is a reference. + /// - When main returns a pair or superposition and one of its elements is a reference. + /// + /// Only expand recursive functions once. + pub fn expand_ref_return(&mut self, book: &Book, seen: &mut Vec, globals_count: &mut usize) { + maybe_grow(|| match self { + Term::Ref { nam } => { + if seen.contains(nam) { + // Don't expand recursive references + } else { + seen.push(nam.clone()); + let mut body = book.defs.get(nam).unwrap().rule().body.clone(); + body.rename_unscoped(globals_count, &mut HashMap::new()); + *self = body; + self.expand_ref_return(book, seen, globals_count); + seen.pop().unwrap(); + } + } + Term::Fan { els, .. } | Term::List { els } => { + for el in els { + el.expand_ref_return(book, seen, globals_count); + } + } + Term::Lam { bod: nxt, .. } + | Term::With { bod: nxt, .. } + | Term::Open { bod: nxt, .. } + | Term::Let { nxt, .. } + | Term::Ask { nxt, .. } + | Term::Use { nxt, .. } => nxt.expand_ref_return(book, seen, globals_count), + Term::Var { .. } + | Term::Link { .. } + | Term::App { .. } + | Term::Num { .. } + | Term::Nat { .. } + | Term::Str { .. } + | Term::Oper { .. } + | Term::Mat { .. } + | Term::Swt { .. } + | Term::Fold { .. } + | Term::Bend { .. } + | Term::Era + | Term::Err => {} + }) + } +} + +impl Term { + /// Since expanded functions can contain unscoped variables, and + /// unscoped variable names must be unique, we need to rename them + /// to avoid conflicts. + fn rename_unscoped(&mut self, unscoped_count: &mut usize, unscoped_map: &mut HashMap) { + match self { + Term::Let { pat, .. } | Term::Lam { pat, .. } => pat.rename_unscoped(unscoped_count, unscoped_map), + Term::Link { nam } => rename_unscoped(nam, unscoped_count, unscoped_map), + _ => { + // Isn't an unscoped bind or use, do nothing, just recurse. + } + } + for child in self.children_mut() { + child.rename_unscoped(unscoped_count, unscoped_map); + } + } +} + +impl Pattern { + fn rename_unscoped(&mut self, unscoped_count: &mut usize, unscoped_map: &mut HashMap) { + maybe_grow(|| { + match self { + Pattern::Chn(nam) => rename_unscoped(nam, unscoped_count, unscoped_map), + _ => { + // Pattern isn't an unscoped bind, just recurse. + } + } + for child in self.children_mut() { + child.rename_unscoped(unscoped_count, unscoped_map); + } + }) + } +} + +/// Generates a new name for an unscoped variable. +fn rename_unscoped(nam: &mut Name, unscoped_count: &mut usize, unscoped_map: &mut HashMap) { + if let Some(new_nam) = unscoped_map.get(nam) { + *nam = new_nam.clone(); + } else { + let new_nam = Name::new(format!("{nam}%{}", unscoped_count)); + unscoped_map.insert(nam.clone(), new_nam.clone()); + *unscoped_count += 1; + *nam = new_nam; + } +} diff --git a/src/fun/transform/float_combinators.rs b/src/fun/transform/float_combinators.rs index de6977091..19d1390f7 100644 --- a/src/fun/transform/float_combinators.rs +++ b/src/fun/transform/float_combinators.rs @@ -33,6 +33,15 @@ impl Book { let mut ctx = FloatCombinatorsCtx::new(&book, max_size); for (def_name, def) in self.defs.iter_mut() { + // Don't float combinators in the main entrypoint. + // This avoids making programs unexpectedly too lazy, + // returning just a reference without executing anything. + if let Some(main) = self.entrypoint.as_ref() { + if def_name == main { + continue; + } + } + let builtin = def.builtin; let body = &mut def.rule_mut().body; ctx.reset(); diff --git a/src/fun/transform/mod.rs b/src/fun/transform/mod.rs index e4d4ced2d..a73b99346 100644 --- a/src/fun/transform/mod.rs +++ b/src/fun/transform/mod.rs @@ -10,6 +10,7 @@ pub mod desugar_with_blocks; pub mod encode_adts; pub mod encode_match_terms; pub mod expand_generated; +pub mod expand_main; pub mod fix_match_defs; pub mod fix_match_terms; pub mod float_combinators; diff --git a/src/lib.rs b/src/lib.rs index f3df4c238..4e985d6be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,6 +148,8 @@ pub fn desugar_book( ctx.book.merge_definitions(); } + ctx.book.expand_main(); + ctx.book.make_var_names_unique(); if !ctx.info.has_errors() { diff --git a/tests/golden_tests/run_file/unused_main_var.bend b/tests/golden_tests/run_file/unused_main_var.bend new file mode 100644 index 000000000..22451dab0 --- /dev/null +++ b/tests/golden_tests/run_file/unused_main_var.bend @@ -0,0 +1,15 @@ +# Despite having an unused variable in main, `map(tt,l)` should not be extracted into a new definition. +def map(fn, list): + fold list: + case List/Cons: + return List/Cons(fn(list.head), list.tail) + case List/Nil: + return [] + +def tt(x): + return x*2 + +def main(): + l = [5,6,7,8] + k = [1,2,3,4] + return map(tt,l) \ No newline at end of file diff --git a/tests/snapshots/cli__compile_all.bend.snap b/tests/snapshots/cli__compile_all.bend.snap index 29e6a1633..980463d45 100644 --- a/tests/snapshots/cli__compile_all.bend.snap +++ b/tests/snapshots/cli__compile_all.bend.snap @@ -10,8 +10,6 @@ input_file: tests/golden_tests/cli/compile_all.bend @Pair/Pair = (a (b ((0 (a (b c))) c))) -@main = b - & @Pair.get ~ (@main__C0 (a b)) - & @Pair/Pair ~ (40 (2 a)) - -@main__C0 = ($([+] $(a b)) (a b)) +@main = d + & @Pair.get ~ (($([+] $(a b)) (a b)) (c d)) + & @Pair/Pair ~ (40 (2 c)) diff --git a/tests/snapshots/cli__desugar_bool_scott.bend.snap b/tests/snapshots/cli__desugar_bool_scott.bend.snap index e350dcc25..713942c37 100644 --- a/tests/snapshots/cli__desugar_bool_scott.bend.snap +++ b/tests/snapshots/cli__desugar_bool_scott.bend.snap @@ -2,7 +2,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/cli/desugar_bool_scott.bend --- -(main) = Boolean/True +(main) = λa λ* a (Boolean/True) = λa λ* a diff --git a/tests/snapshots/cli__desugar_float_combinators.bend.snap b/tests/snapshots/cli__desugar_float_combinators.bend.snap index f7a24a7e9..5f3bf79b8 100644 --- a/tests/snapshots/cli__desugar_float_combinators.bend.snap +++ b/tests/snapshots/cli__desugar_float_combinators.bend.snap @@ -8,10 +8,6 @@ input_file: tests/golden_tests/cli/desugar_float_combinators.bend (get) = λa (a get__C0 0) -(main) = (get main__C1) +(main) = (get (S (S Z))) (get__C0) = λa (+ a 1) - -(main__C0) = (S Z) - -(main__C1) = (S main__C0) diff --git a/tests/snapshots/cli__desugar_merge.bend.snap b/tests/snapshots/cli__desugar_merge.bend.snap index b440b766f..15fe92082 100644 --- a/tests/snapshots/cli__desugar_merge.bend.snap +++ b/tests/snapshots/cli__desugar_merge.bend.snap @@ -8,4 +8,4 @@ input_file: tests/golden_tests/cli/desugar_merge.bend (F__M_Z) = λ* λa a -(main) = F__M_Z +(main) = λ* λa a diff --git a/tests/snapshots/cli__no_check_net_size.bend.snap b/tests/snapshots/cli__no_check_net_size.bend.snap index a3ad9dc19..2e3952c42 100644 --- a/tests/snapshots/cli__no_check_net_size.bend.snap +++ b/tests/snapshots/cli__no_check_net_size.bend.snap @@ -27,15 +27,6 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend &!@Gen.go ~ (a (b c)) &!@Gen.go ~ (d (e f)) -@Main__C0 = a - & @Gen ~ (4 a) - -@Main__C1 = a - & @Reverse ~ (@Main__C0 a) - -@Main__C2 = a - & @Sort ~ (@Main__C1 a) - @Map_/Both = (a (b ((@Map_/Both/tag (a (b c))) c))) @Map_/Both/tag = 2 @@ -173,5 +164,8 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend @ToMap__C3 = (?((@Map_/Free @ToMap__C2) a) a) -@main = a - & @Sum ~ (@Main__C2 a) +@main = d + & @Sum ~ (c d) + & @Sort ~ (b c) + & @Reverse ~ (a b) + & @Gen ~ (4 a) diff --git a/tests/snapshots/cli__run_pretty.bend.snap b/tests/snapshots/cli__run_pretty.bend.snap index ff7d1150c..951ea456e 100644 --- a/tests/snapshots/cli__run_pretty.bend.snap +++ b/tests/snapshots/cli__run_pretty.bend.snap @@ -4,9 +4,9 @@ input_file: tests/golden_tests/cli/run_pretty.bend --- Result: λa switch a = a { - 0: λa switch a { + 0: λb switch b = b { 0: "ba"; - _: λ* "ta"; + _: "ta"; }; _: λ* "ata"; } diff --git a/tests/snapshots/compile_file__addition.bend.snap b/tests/snapshots/compile_file__addition.bend.snap index 82c396601..33590b7f5 100644 --- a/tests/snapshots/compile_file__addition.bend.snap +++ b/tests/snapshots/compile_file__addition.bend.snap @@ -2,8 +2,6 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file/addition.bend --- -@main = a - & @main__C0 ~ (8 a) - -@main__C0 = (a b) +@main = c + & (a b) ~ (8 c) & $(1 $([+] $(a b))) ~ [+1] diff --git a/tests/snapshots/compile_file__church_one.bend.snap b/tests/snapshots/compile_file__church_one.bend.snap index 063566ad8..1b4a15134 100644 --- a/tests/snapshots/compile_file__church_one.bend.snap +++ b/tests/snapshots/compile_file__church_one.bend.snap @@ -2,7 +2,5 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file/church_one.bend --- -@main = b - & @main__C0 ~ ((* (a a)) b) - -@main__C0 = ((a (b c)) ({(c d) a} (b d))) +@main = f + & ((a (b c)) ({(c d) a} (b d))) ~ ((* (e e)) f) diff --git a/tests/snapshots/compile_file__elif.bend.snap b/tests/snapshots/compile_file__elif.bend.snap index c2b506478..a714134ec 100644 --- a/tests/snapshots/compile_file__elif.bend.snap +++ b/tests/snapshots/compile_file__elif.bend.snap @@ -2,17 +2,8 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file/elif.bend --- -@main = d - & @main__C3 ~ (a (b (c d))) - & $(1 a) ~ [<2] - & $(2 b) ~ [>3] - & $(2 c) ~ [=2] - -@main__C0 = (?((0 (* 2)) a) a) - -@main__C1 = (a (?((@main__C0 (* (* 3))) (a b)) b)) - -@main__C2 = (a (b (?((@main__C1 (* (* (* 4)))) (a (b c))) c))) - -@main__C3 = a - & $(2 ?((@main__C2 (* (* (* (* 1))))) a)) ~ [=1] +@main = j + & $(2 ?(((d (e (?(((b (?(((?((0 (* 2)) a) a) (* (* 3))) (b c)) c)) (* (* (* 4)))) (d (e f))) f))) (* (* (* (* 1))))) (g (h (i j))))) ~ [=1] + & $(1 g) ~ [<2] + & $(2 h) ~ [>3] + & $(2 i) ~ [=2] diff --git a/tests/snapshots/compile_file__fst_snd.bend.snap b/tests/snapshots/compile_file__fst_snd.bend.snap index a409b577c..54485b834 100644 --- a/tests/snapshots/compile_file__fst_snd.bend.snap +++ b/tests/snapshots/compile_file__fst_snd.bend.snap @@ -2,12 +2,6 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file/fst_snd.bend --- -@main = a - & @main__C2 ~ (@main__C1 a) - -@main__C0 = ((a *) a) - -@main__C1 = a - & @main__C0 ~ (((1 3) 2) a) - -@main__C2 = ((* a) a) +@main = d + & ((* a) a) ~ (c d) + & ((b *) b) ~ (((1 3) 2) c) diff --git a/tests/snapshots/compile_file__lets.bend.snap b/tests/snapshots/compile_file__lets.bend.snap index 2f68d3296..5fa462c8a 100644 --- a/tests/snapshots/compile_file__lets.bend.snap +++ b/tests/snapshots/compile_file__lets.bend.snap @@ -2,11 +2,9 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file/lets.bend --- -@main = @main__C0 - & (a a) ~ * - -@main__C0 = n - & (a a) ~ (f (i (m n))) - & (d d) ~ {(e f) e} - & (c c) ~ {(g (h i)) {g h}} - & (b b) ~ {(j (k (l m))) {j {k l}}} +@main = o + & (a a) ~ (g (j (n o))) + & (e e) ~ * + & (d d) ~ {(f g) f} + & (c c) ~ {(h (i j)) {h i}} + & (b b) ~ {(k (l (m n))) {k {l m}}} diff --git a/tests/snapshots/compile_file__ref_to_ref.bend.snap b/tests/snapshots/compile_file__ref_to_ref.bend.snap index a9b2566e3..bd11c9754 100644 --- a/tests/snapshots/compile_file__ref_to_ref.bend.snap +++ b/tests/snapshots/compile_file__ref_to_ref.bend.snap @@ -18,4 +18,4 @@ input_file: tests/golden_tests/compile_file/ref_to_ref.bend @C1 = @B4 -@main = ((@A1 @B1) @C1) +@main = ((1 2) 2) diff --git a/tests/snapshots/compile_file__switch_in_switch_arg.bend.snap b/tests/snapshots/compile_file__switch_in_switch_arg.bend.snap index c2e8a7afd..dc5e89478 100644 --- a/tests/snapshots/compile_file__switch_in_switch_arg.bend.snap +++ b/tests/snapshots/compile_file__switch_in_switch_arg.bend.snap @@ -2,6 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file/switch_in_switch_arg.bend --- -@main = (?((0 (a a)) ?((0 @main__C0) b)) b) - -@main__C0 = ($([+1] a) a) +@main = (?((0 (a a)) ?((0 ($([+1] b) b)) c)) c) diff --git a/tests/snapshots/compile_file__vicious_circles.bend.snap b/tests/snapshots/compile_file__vicious_circles.bend.snap index 33580e7ba..4824d0655 100644 --- a/tests/snapshots/compile_file__vicious_circles.bend.snap +++ b/tests/snapshots/compile_file__vicious_circles.bend.snap @@ -7,3 +7,5 @@ input_file: tests/golden_tests/compile_file/vicious_circles.bend Found term that compiles into an inet with a vicious cycle In compiled inet 'dup_self': Found term that compiles into an inet with a vicious cycle +In compiled inet 'main': + Found term that compiles into an inet with a vicious cycle diff --git a/tests/snapshots/compile_file_o_all__addition.bend.snap b/tests/snapshots/compile_file_o_all__addition.bend.snap index 2f446d652..a16b23d82 100644 --- a/tests/snapshots/compile_file_o_all__addition.bend.snap +++ b/tests/snapshots/compile_file_o_all__addition.bend.snap @@ -2,8 +2,6 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file_o_all/addition.bend --- -@main = a - & @main__C0 ~ (8 a) - -@main__C0 = (a b) +@main = c + & (a b) ~ (8 c) & $(1 $([+] $(a b))) ~ [+1] diff --git a/tests/snapshots/compile_file_o_all__ex2.bend.snap b/tests/snapshots/compile_file_o_all__ex2.bend.snap index d98385eb0..756a2121b 100644 --- a/tests/snapshots/compile_file_o_all__ex2.bend.snap +++ b/tests/snapshots/compile_file_o_all__ex2.bend.snap @@ -29,10 +29,8 @@ input_file: tests/golden_tests/compile_file_o_all/ex2.bend & @O ~ (b c) & @O ~ (a b) -@main = a - & @run ~ (@main__C0 a) - -@main__C0 = a +@main = b + & @run ~ (a b) & @c2 ~ (@I (@E a)) @run = ((@runO (@runI (@E a))) a) diff --git a/tests/snapshots/compile_file_o_all__exp.bend.snap b/tests/snapshots/compile_file_o_all__exp.bend.snap index f2b2bafa0..a129e55fd 100644 --- a/tests/snapshots/compile_file_o_all__exp.bend.snap +++ b/tests/snapshots/compile_file_o_all__exp.bend.snap @@ -2,9 +2,5 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file_o_all/exp.bend --- -@main = a - & @main__C1 ~ (@main__C0 a) - -@main__C0 = ({(b c) (a b)} (a c)) - -@main__C1 = ({(b c) (a b)} (a c)) +@main = g + & ({(b c) (a b)} (a c)) ~ (({(e f) (d e)} (d f)) g) diff --git a/tests/snapshots/compile_file_o_all__linearize_match.bend.snap b/tests/snapshots/compile_file_o_all__linearize_match.bend.snap index 4a86caa2f..062c76b87 100644 --- a/tests/snapshots/compile_file_o_all__linearize_match.bend.snap +++ b/tests/snapshots/compile_file_o_all__linearize_match.bend.snap @@ -2,6 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file_o_all/linearize_match.bend --- -@main = (?(((a a) @main__C0) b) b) - -@main__C0 = ($([+] $(a b)) (a b)) +@main = (?(((a a) ($([+] $(b c)) (b c))) d) d) diff --git a/tests/snapshots/compile_file_o_all__list_merge_sort.bend.snap b/tests/snapshots/compile_file_o_all__list_merge_sort.bend.snap index 400e6f9e5..77deacbb5 100644 --- a/tests/snapshots/compile_file_o_all__list_merge_sort.bend.snap +++ b/tests/snapshots/compile_file_o_all__list_merge_sort.bend.snap @@ -36,10 +36,6 @@ input_file: tests/golden_tests/compile_file_o_all/list_merge_sort.bend @MergePair__C4 = (?((@MergePair__C3 (* (* @List_/Nil))) a) a) -@MergeSort = (a (b d)) - & @Unpack ~ (a (c d)) - & @Map ~ (b (@Pure c)) - @Merge__C0 = ({b {g l}} ({h q} ({(a (b c)) {e m}} ({a {d n}} ({f o} t))))) & @If ~ (c (k (s t))) & @List_/Cons ~ (d (j k)) @@ -75,4 +71,6 @@ input_file: tests/golden_tests/compile_file_o_all/list_merge_sort.bend @Unpack__C3 = (?((@Unpack__C2 (* (* @List_/Nil))) a) a) -@main = @MergeSort +@main = (a (b d)) + & @Unpack ~ (a (c d)) + & @Map ~ (b (@Pure c)) diff --git a/tests/snapshots/compile_file_o_all__match_mult_linearization.bend.snap b/tests/snapshots/compile_file_o_all__match_mult_linearization.bend.snap index 799c59582..8da05b3ed 100644 --- a/tests/snapshots/compile_file_o_all__match_mult_linearization.bend.snap +++ b/tests/snapshots/compile_file_o_all__match_mult_linearization.bend.snap @@ -2,8 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/compile_file_o_all/match_mult_linearization.bend --- -@main = (?((@main__C0 @main__C1) a) a) - -@main__C0 = ($([+] $(a $([+] $(b c)))) (a (b c))) - -@main__C1 = ($([+] $(a $([+] $(b $([+] $(c d)))))) (a (b (c d)))) +@main = (?((($([+] $(a $([+] $(b c)))) (a (b c))) ($([+] $(d $([+] $(e $([+] $(f g)))))) (d (e (f g))))) h) h) diff --git a/tests/snapshots/desugar_file__bind_syntax.bend.snap b/tests/snapshots/desugar_file__bind_syntax.bend.snap index 083a10aab..eb850cbe9 100644 --- a/tests/snapshots/desugar_file__bind_syntax.bend.snap +++ b/tests/snapshots/desugar_file__bind_syntax.bend.snap @@ -10,7 +10,7 @@ input_file: tests/golden_tests/desugar_file/bind_syntax.bend (safe_rem) = λa λb (switch b { 0: λ* (Result/Err (String/Cons 77 (String/Cons 111 (String/Cons 100 (String/Cons 32 (String/Cons 98 (String/Cons 121 (String/Cons 32 (String/Cons 48 String/Nil))))))))); _: safe_rem__C0; } a) -(Main) = (Result/bind Main__C3 Main__C2) +(Main) = (Result/bind (safe_div 3 2) λa (a λb (Result/bind (safe_rem b 0) λc (c λd d)))) (String/Nil) = λa (a String/Nil/tag) @@ -28,14 +28,6 @@ input_file: tests/golden_tests/desugar_file/bind_syntax.bend (Result/Err/tag) = 1 -(Main__C0) = λa (a λb b) - -(Main__C1) = λa (Result/bind (safe_rem a 0) Main__C0) - -(Main__C2) = λa (a Main__C1) - -(Main__C3) = (safe_div 3 2) - (Result/bind__C0) = λa λb (undefer b a) (Result/bind__C1) = λ* λa λ* (Result/Err a) diff --git a/tests/snapshots/desugar_file__combinators.bend.snap b/tests/snapshots/desugar_file__combinators.bend.snap index 9ff28da8d..8a2c6c3cd 100644 --- a/tests/snapshots/desugar_file__combinators.bend.snap +++ b/tests/snapshots/desugar_file__combinators.bend.snap @@ -22,7 +22,7 @@ input_file: tests/golden_tests/desugar_file/combinators.bend (B) = λa (B__C0 a) -(Main) = list +(Main) = (List/Cons 0 list__C0) (List/Nil) = λa (a List/Nil/tag) diff --git a/tests/snapshots/desugar_file__mapper_syntax.bend.snap b/tests/snapshots/desugar_file__mapper_syntax.bend.snap index 5d6ea8c29..3425e7951 100644 --- a/tests/snapshots/desugar_file__mapper_syntax.bend.snap +++ b/tests/snapshots/desugar_file__mapper_syntax.bend.snap @@ -10,7 +10,7 @@ input_file: tests/golden_tests/desugar_file/mapper_syntax.bend (Map/map) = λa λb λc (a Map/map__C5 b c) -(main) = let (a, b) = main__C8; let (c, *) = (Map/get b 0); (main__C7, a, c) +(main) = let (c, d) = (Map/get (Map/map (Map/map (Map/set (Map/set Map/empty 0 3) 1 4) 1 λa (+ a 1)) 1 λb (* b 2)) 1); let (e, *) = (Map/get d 0); ((λf (+ f 1) 1), c, e) (Map/Node) = λa λb λc λd (d Map/Node/tag a b c) @@ -65,21 +65,3 @@ input_file: tests/golden_tests/desugar_file/mapper_syntax.bend (Map/set__C8) = λa λb λc λd λe let {f g} = e; (switch (== 0 f) { 0: Map/set__C2; _: Map/set__C3; } d g a b c) (Map/set__C9) = λ* λa λb let {c d} = b; (switch (== 0 c) { 0: Map/set__C6; _: Map/set__C7; } a d) - -(main__C0) = (Map/set Map/empty 0 3) - -(main__C1) = λa (+ a 1) - -(main__C2) = (Map/set main__C0 1 4) - -(main__C3) = λa (* a 2) - -(main__C4) = (Map/map main__C2 1 main__C1) - -(main__C5) = (Map/map main__C4 1 main__C3) - -(main__C6) = λa (+ a 1) - -(main__C7) = (main__C6 1) - -(main__C8) = (Map/get main__C5 1) diff --git a/tests/snapshots/desugar_file__switch_with_use.bend.snap b/tests/snapshots/desugar_file__switch_with_use.bend.snap index dd87e36de..c565c0ade 100644 --- a/tests/snapshots/desugar_file__switch_with_use.bend.snap +++ b/tests/snapshots/desugar_file__switch_with_use.bend.snap @@ -2,6 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/desugar_file/switch_with_use.bend --- -(main) = λa λb λc λ* λ* (switch c { 0: λd d; _: main__C0; } (a b)) - -(main__C0) = λa λb (a b) +(main) = λa λb λc λ* λ* (switch c { 0: λd d; _: λe λf (e f); } (a b)) diff --git a/tests/snapshots/run_file__adt_option_and.bend.snap b/tests/snapshots/run_file__adt_option_and.bend.snap index 811346f84..08a2fe276 100644 --- a/tests/snapshots/run_file__adt_option_and.bend.snap +++ b/tests/snapshots/run_file__adt_option_and.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/adt_option_and.bend --- NumScott: -λa (a λa switch a { 0: λa λb (b λa switch a { 0: λa λb (Option/Some (b, a)); _: λ* λ* Option/None; } a); _: λ* λ* Option/None; }) +λa (a λb switch b = b { 0: λc λd (d λe switch e = e { 0: λf λg λh (h Option/Some/tag λi f); _: λ* Option/None; } c); _: λ* Option/None; }) Scott: -λa (a λa λb (b λa λb (Option/Some (b, a)) λ* Option/None a) λ* Option/None) +λa (a λb λc (c λd λe λf λ* (f λg d) λ* Option/None b) λ* Option/None) diff --git a/tests/snapshots/run_file__exp.bend.snap b/tests/snapshots/run_file__exp.bend.snap index 504717b00..ca80eb038 100644 --- a/tests/snapshots/run_file__exp.bend.snap +++ b/tests/snapshots/run_file__exp.bend.snap @@ -2,5 +2,16 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/exp.bend --- -Errors: -Failed to parse result from HVM. +NumScott: +Warnings: +During readback: + Unable to interpret the HVM result as a valid Bend term. (Reached Root) + +λa λb ( λ$c $c $c) + +Scott: +Warnings: +During readback: + Unable to interpret the HVM result as a valid Bend term. (Reached Root) + +λa λb ( λ$c $c $c) diff --git a/tests/snapshots/run_file__imp_empty_literals.bend.snap b/tests/snapshots/run_file__imp_empty_literals.bend.snap index 41fa2fbe3..cdf2ef9fc 100644 --- a/tests/snapshots/run_file__imp_empty_literals.bend.snap +++ b/tests/snapshots/run_file__imp_empty_literals.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/imp_empty_literals.bend --- NumScott: -[] +λa (a List/Nil/tag) Scott: -[] +λa λ* a diff --git a/tests/snapshots/run_file__linearize_match.bend.snap b/tests/snapshots/run_file__linearize_match.bend.snap index 640e0997b..c9140aa3d 100644 --- a/tests/snapshots/run_file__linearize_match.bend.snap +++ b/tests/snapshots/run_file__linearize_match.bend.snap @@ -3,7 +3,15 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/linearize_match.bend --- NumScott: -λa switch a = a { 0: λb b; _: λb (+ a-1 b); } +Warnings: +During readback: + Encountered an invalid numeric operation. + +λa switch a = a { 0: λb b; _: λd ; } Scott: -λa switch a = a { 0: λb b; _: λb (+ a-1 b); } +Warnings: +During readback: + Encountered an invalid numeric operation. + +λa switch a = a { 0: λb b; _: λd ; } diff --git a/tests/snapshots/run_file__mapper_syntax.bend.snap b/tests/snapshots/run_file__mapper_syntax.bend.snap index c1aa01012..b6d8ff9f5 100644 --- a/tests/snapshots/run_file__mapper_syntax.bend.snap +++ b/tests/snapshots/run_file__mapper_syntax.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/mapper_syntax.bend --- NumScott: -((λa (+ a 1) 1), (10, 3)) +(2, (10, 3)) Scott: -((λa (+ a 1) 1), (10, 3)) +(2, (10, 3)) diff --git a/tests/snapshots/run_file__match_mult_linearization.bend.snap b/tests/snapshots/run_file__match_mult_linearization.bend.snap index 841ff169d..ba6ffeec6 100644 --- a/tests/snapshots/run_file__match_mult_linearization.bend.snap +++ b/tests/snapshots/run_file__match_mult_linearization.bend.snap @@ -3,7 +3,15 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/match_mult_linearization.bend --- NumScott: -λa switch a = a { 0: λa λb λc (+ (+ a b) c); _: λb λc λd (+ (+ (+ a-1 b) c) d); } +Warnings: +During readback: + Encountered an invalid numeric operation. (2 occurrences) + +λa switch a = a { 0: λb λc λd ; _: λf λg λh ; } Scott: -λa switch a = a { 0: λa λb λc (+ (+ a b) c); _: λb λc λd (+ (+ (+ a-1 b) c) d); } +Warnings: +During readback: + Encountered an invalid numeric operation. (2 occurrences) + +λa switch a = a { 0: λb λc λd ; _: λf λg λh ; } diff --git a/tests/snapshots/run_file__match_num_succ_complex.bend.snap b/tests/snapshots/run_file__match_num_succ_complex.bend.snap index 3bb1042db..6825e2680 100644 --- a/tests/snapshots/run_file__match_num_succ_complex.bend.snap +++ b/tests/snapshots/run_file__match_num_succ_complex.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/match_num_succ_complex.bend --- NumScott: -[[5, 5, 0, 12, 0, 6], [5, 5, 0, 12, 0, 6]] +[[5, 5, *, *, *, *], [5, 5, *, *, *, *]] Scott: -[[5, 5, 0, 12, 0, 6], [5, 5, 0, 12, 0, 6]] +[[5, 5, *, *, *, *], [5, 5, *, *, *, *]] diff --git a/tests/snapshots/run_file__queue.bend.snap b/tests/snapshots/run_file__queue.bend.snap index f9a7e596b..cd9cfdffd 100644 --- a/tests/snapshots/run_file__queue.bend.snap +++ b/tests/snapshots/run_file__queue.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/queue.bend --- NumScott: -λa λ* (a 1 (Cons 2 (Cons 3 Nil))) +λa λ* (a 1 λb λ* (b 2 λc λ* (c 3 Nil))) Scott: -λa λ* (a 1 (Cons 2 (Cons 3 Nil))) +λa λ* (a 1 λb λ* (b 2 λc λ* (c 3 Nil))) diff --git a/tests/snapshots/run_file__unused_main_var.bend.snap b/tests/snapshots/run_file__unused_main_var.bend.snap new file mode 100644 index 000000000..291f0b91d --- /dev/null +++ b/tests/snapshots/run_file__unused_main_var.bend.snap @@ -0,0 +1,9 @@ +--- +source: tests/golden_tests.rs +input_file: tests/golden_tests/run_file/unused_main_var.bend +--- +NumScott: +[10, 12, 14, 16] + +Scott: +[10, 12, 14, 16] From 4bb520442a58f10d72ae292c3169f1ea1700637d Mon Sep 17 00:00:00 2001 From: Nicolas Abril Date: Wed, 5 Jun 2024 19:18:31 +0200 Subject: [PATCH 2/2] Increase the version to 0.2.33 --- CHANGELOG.md | 9 ++++++--- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ff18863..9f03b4f4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ # Changelog -## 0.2.32 +## 0.2.33 +- Added `expand_main`, a compilation pass that expands references in the entry point function. (#424) +- Changed the `float_combinators` pass to not extract in the entry point function. (#424) -- Added the built-in `Tree` datatype. -- Added `![]` and `!` syntax for `Tree` literals. +## 0.2.32 +- Added the built-in `Tree` datatype. (#528) +- Added `![]` and `!` syntax for `Tree` literals. (#528) - Moved the builtins documentation to `/docs`. - Created the changelog. diff --git a/Cargo.lock b/Cargo.lock index d10d2ccbd..0c252c98e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ dependencies = [ [[package]] name = "bend-lang" -version = "0.2.32" +version = "0.2.33" dependencies = [ "TSPL", "clap", diff --git a/Cargo.toml b/Cargo.toml index e82f7852d..6ddc0931a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "bend-lang" description = "A high-level, massively parallel programming language" license = "Apache-2.0" -version = "0.2.32" +version = "0.2.33" edition = "2021" rust-version = "1.74" exclude = ["tests/"]