diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ff1886..9f03b4f4 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 d10d2ccb..0c252c98 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 e82f7852..6ddc0931 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/"] diff --git a/src/fun/transform/expand_main.rs b/src/fun/transform/expand_main.rs new file mode 100644 index 00000000..8bf3d418 --- /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 de697709..19d1390f 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 e4d4ced2..a73b9934 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 f3df4c23..4e985d6b 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 00000000..22451dab --- /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 29e6a163..980463d4 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 e350dcc2..713942c3 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 f7a24a7e..5f3bf79b 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 b440b766..15fe9208 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 a3ad9dc1..2e3952c4 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 ff7d1150..951ea456 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 82c39660..33590b7f 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 063566ad..1b4a1513 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 c2b50647..a714134e 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 a409b577..54485b83 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 2f68d329..5fa462c8 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 a9b2566e..bd11c975 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 c2e8a7af..dc5e8947 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 33580e7b..4824d065 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 2f446d65..a16b23d8 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 d98385eb..756a2121 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 f2b2bafa..a129e55f 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 4a86caa2..062c76b8 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 400e6f9e..77deacbb 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 799c5958..8da05b3e 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 083a10aa..eb850cbe 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 9ff28da8..8a2c6c3c 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 5d6ea8c2..3425e795 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 dd87e36d..c565c0ad 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 811346f8..08a2fe27 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 504717b0..ca80eb03 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 41fa2fbe..cdf2ef9f 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 640e0997..c9140aa3 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 c1aa0101..b6d8ff9f 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 841ff169..ba6ffeec 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 3bb1042d..6825e268 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 f9a7e596..cd9cfdff 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 00000000..291f0b91 --- /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]