Merge branch 'trunk' into str_trim_left

This commit is contained in:
Michael Downey 2021-11-09 19:43:26 -05:00 committed by GitHub
commit 07cd3850d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 3288 additions and 7733 deletions

View file

@ -1,196 +1,218 @@
#[cfg(test)]
mod gen_compare {
use crate::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
#![cfg(not(feature = "gen-wasm"))]
#[test]
fn eq_i64() {
assert_evals_to!(
indoc!(
r#"
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn eq_i64() {
assert_evals_to!(
indoc!(
r#"
i : I64
i = 1
i == i
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_i64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_i64() {
assert_evals_to!(
indoc!(
r#"
i : I64
i = 1
i != i
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_u64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn eq_u64() {
assert_evals_to!(
indoc!(
r#"
i : U64
i = 1
i == i
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_u64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_u64() {
assert_evals_to!(
indoc!(
r#"
i : U64
i = 1
i != i
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_f64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_f64() {
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1
i == i
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_f64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_f64() {
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1
i != i
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
true : Bool
true = True
true == True
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
true : Bool
true = True
true == False
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn empty_record() {
assert_evals_to!("{} == {}", true, bool);
assert_evals_to!("{} != {}", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn empty_record() {
assert_evals_to!("{} == {}", true, bool);
assert_evals_to!("{} != {}", false, bool);
}
#[test]
fn unit() {
assert_evals_to!("Unit == Unit", true, bool);
assert_evals_to!("Unit != Unit", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unit() {
assert_evals_to!("Unit == Unit", true, bool);
assert_evals_to!("Unit != Unit", false, bool);
}
#[test]
fn newtype() {
assert_evals_to!("Identity 42 == Identity 42", true, bool);
assert_evals_to!("Identity 42 != Identity 42", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn newtype() {
assert_evals_to!("Identity 42 == Identity 42", true, bool);
assert_evals_to!("Identity 42 != Identity 42", false, bool);
}
#[test]
fn small_str() {
assert_evals_to!("\"aaa\" == \"aaa\"", true, bool);
assert_evals_to!("\"aaa\" == \"bbb\"", false, bool);
assert_evals_to!("\"aaa\" != \"aaa\"", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn small_str() {
assert_evals_to!("\"aaa\" == \"aaa\"", true, bool);
assert_evals_to!("\"aaa\" == \"bbb\"", false, bool);
assert_evals_to!("\"aaa\" != \"aaa\"", false, bool);
}
#[test]
fn large_str() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn large_str() {
assert_evals_to!(
indoc!(
r#"
x = "Unicode can represent text values which span multiple languages"
y = "Unicode can represent text values which span multiple languages"
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
x = "Unicode can represent text values which span multiple languages"
y = "Here are some valid Roc strings"
x != y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_result_tag_true() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_result_tag_true() {
assert_evals_to!(
indoc!(
r#"
x : Result I64 I64
x = Ok 1
@ -199,17 +221,18 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_result_tag_false() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_result_tag_false() {
assert_evals_to!(
indoc!(
r#"
x : Result I64 I64
x = Ok 1
@ -218,17 +241,18 @@ mod gen_compare {
x == y
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_expr() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_expr() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Var I64 ]
x : Expr
@ -239,17 +263,18 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_linked_list() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_linked_list() {
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -260,14 +285,14 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -278,14 +303,14 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -296,17 +321,18 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_linked_list_false() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_linked_list_false() {
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -317,17 +343,18 @@ mod gen_compare {
y == x
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_nullable_expr() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_nullable_expr() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Empty ]
x : Expr
@ -338,17 +365,18 @@ mod gen_compare {
x != y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_rosetree() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_rosetree() {
assert_evals_to!(
indoc!(
r#"
Rose a : [ Rose (List (Rose a)) ]
x : Rose I64
@ -359,14 +387,14 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
Rose a : [ Rose (List (Rose a)) ]
x : Rose I64
@ -377,20 +405,21 @@ mod gen_compare {
x != y
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
#[ignore]
fn rosetree_with_tag() {
// currently stack overflows in type checking
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn rosetree_with_tag() {
// currently stack overflows in type checking
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
Rose a : [ Rose (Result (List (Rose a)) I64) ]
x : Rose I64
@ -401,53 +430,60 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn list_eq_empty() {
assert_evals_to!("[] == []", true, bool);
assert_evals_to!("[] != []", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_empty() {
assert_evals_to!("[] == []", true, bool);
assert_evals_to!("[] != []", false, bool);
}
#[test]
fn list_eq_by_length() {
assert_evals_to!("[1] == []", false, bool);
assert_evals_to!("[] == [1]", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_by_length() {
assert_evals_to!("[1] == []", false, bool);
assert_evals_to!("[] == [1]", false, bool);
}
#[test]
fn list_eq_compare_pointwise() {
assert_evals_to!("[1] == [1]", true, bool);
assert_evals_to!("[2] == [1]", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_compare_pointwise() {
assert_evals_to!("[1] == [1]", true, bool);
assert_evals_to!("[2] == [1]", false, bool);
}
#[test]
fn list_eq_nested() {
assert_evals_to!("[[1]] == [[1]]", true, bool);
assert_evals_to!("[[2]] == [[1]]", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_nested() {
assert_evals_to!("[[1]] == [[1]]", true, bool);
assert_evals_to!("[[2]] == [[1]]", false, bool);
}
#[test]
fn list_neq_compare_pointwise() {
assert_evals_to!("[1] != [1]", false, bool);
assert_evals_to!("[2] != [1]", true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_neq_compare_pointwise() {
assert_evals_to!("[1] != [1]", false, bool);
assert_evals_to!("[2] != [1]", true, bool);
}
#[test]
fn list_neq_nested() {
assert_evals_to!("[[1]] != [[1]]", false, bool);
assert_evals_to!("[[2]] != [[1]]", true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_neq_nested() {
assert_evals_to!("[[1]] != [[1]]", false, bool);
assert_evals_to!("[[2]] != [[1]]", true, bool);
}
#[test]
fn compare_union_same_content() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn compare_union_same_content() {
assert_evals_to!(
indoc!(
r#"
Foo : [ A I64, B I64 ]
a : Foo
@ -458,17 +494,18 @@ mod gen_compare {
a == b
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn compare_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn compare_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val1 I64, Val2 I64 ]
v1 : Expr
@ -479,17 +516,18 @@ mod gen_compare {
v1 == v2
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn compare_nullable_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn compare_nullable_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val1 I64, Val2 I64, Empty ]
v1 : Expr
@ -500,9 +538,8 @@ mod gen_compare {
v1 == v2
"#
),
false,
bool
);
}
),
false,
bool
);
}

View file

@ -1,10 +1,19 @@
#![cfg(test)]
#![cfg(feature = "gen-llvm")]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
// #[cfg(feature = "gen-dev")]
// use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to;
use crate::assert_evals_to;
use indoc::indoc;
use roc_std::{RocList, RocStr};
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_empty_len() {
assert_evals_to!(
indoc!(
@ -18,6 +27,7 @@ fn dict_empty_len() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_insert_empty() {
assert_evals_to!(
indoc!(
@ -32,6 +42,7 @@ fn dict_insert_empty() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_empty_contains() {
assert_evals_to!(
indoc!(
@ -48,6 +59,7 @@ fn dict_empty_contains() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_nonempty_contains() {
assert_evals_to!(
indoc!(
@ -64,6 +76,7 @@ fn dict_nonempty_contains() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_empty_remove() {
assert_evals_to!(
indoc!(
@ -82,6 +95,7 @@ fn dict_empty_remove() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_nonempty_remove() {
assert_evals_to!(
indoc!(
@ -100,6 +114,7 @@ fn dict_nonempty_remove() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn dict_nonempty_get() {
assert_evals_to!(
indoc!(
@ -142,6 +157,7 @@ fn dict_nonempty_get() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn keys() {
assert_evals_to!(
indoc!(
@ -163,6 +179,7 @@ fn keys() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn values() {
assert_evals_to!(
indoc!(
@ -184,6 +201,7 @@ fn values() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn from_list_with_fold() {
assert_evals_to!(
indoc!(
@ -226,6 +244,7 @@ fn from_list_with_fold() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn small_str_keys() {
assert_evals_to!(
indoc!(
@ -247,6 +266,7 @@ fn small_str_keys() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn big_str_keys() {
assert_evals_to!(
indoc!(
@ -272,6 +292,7 @@ fn big_str_keys() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn big_str_values() {
assert_evals_to!(
indoc!(
@ -296,6 +317,7 @@ fn big_str_values() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unit_values() {
assert_evals_to!(
indoc!(
@ -317,6 +339,7 @@ fn unit_values() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn single() {
assert_evals_to!(
indoc!(
@ -334,6 +357,7 @@ fn single() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn union() {
assert_evals_to!(
indoc!(
@ -351,6 +375,7 @@ fn union() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn union_prefer_first() {
assert_evals_to!(
indoc!(
@ -368,6 +393,7 @@ fn union_prefer_first() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn intersection() {
assert_evals_to!(
indoc!(
@ -398,6 +424,7 @@ fn intersection() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn intersection_prefer_first() {
assert_evals_to!(
indoc!(
@ -428,6 +455,7 @@ fn intersection_prefer_first() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn difference() {
assert_evals_to!(
indoc!(
@ -458,6 +486,7 @@ fn difference() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn difference_prefer_first() {
assert_evals_to!(
indoc!(
@ -488,6 +517,7 @@ fn difference_prefer_first() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn walk_sum_keys() {
assert_evals_to!(
indoc!(

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,22 +1,42 @@
#![cfg(test)]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_llvm_evals_to;
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_non_opt_evals_to;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-dev")]
// use crate::helpers::dev::assert_evals_to as assert_llvm_evals_to;
// #[cfg(feature = "gen-dev")]
// use crate::helpers::dev::assert_evals_to as assert_non_opt_evals_to;
#[cfg(feature = "gen-wasm")]
use crate::helpers::wasm::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to as assert_llvm_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to as assert_non_opt_evals_to;
use crate::assert_evals_to;
use crate::assert_llvm_evals_to;
use crate::assert_non_opt_evals_to;
use indoc::indoc;
#[allow(unused_imports)]
use roc_std::RocStr;
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn basic_int() {
assert_evals_to!("123", 123, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn basic_float() {
assert_evals_to!("1234.0", 1234.0, f64);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn branch_first_float() {
assert_evals_to!(
indoc!(
@ -32,6 +52,7 @@ fn branch_first_float() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn branch_second_float() {
assert_evals_to!(
indoc!(
@ -47,6 +68,7 @@ fn branch_second_float() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn branch_third_float() {
assert_evals_to!(
indoc!(
@ -63,6 +85,7 @@ fn branch_third_float() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn branch_first_int() {
assert_evals_to!(
indoc!(
@ -78,6 +101,7 @@ fn branch_first_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn branch_second_int() {
assert_evals_to!(
indoc!(
@ -93,6 +117,7 @@ fn branch_second_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn branch_third_int() {
assert_evals_to!(
indoc!(
@ -109,6 +134,7 @@ fn branch_third_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn branch_store_variable() {
assert_evals_to!(
indoc!(
@ -124,6 +150,7 @@ fn branch_store_variable() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn when_one_element_tag() {
assert_evals_to!(
indoc!(
@ -141,6 +168,7 @@ fn when_one_element_tag() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_two_element_tag_first() {
assert_evals_to!(
indoc!(
@ -159,6 +187,7 @@ fn when_two_element_tag_first() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_two_element_tag_second() {
assert_evals_to!(
indoc!(
@ -177,6 +206,7 @@ fn when_two_element_tag_second() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn gen_when_one_branch() {
assert_evals_to!(
indoc!(
@ -191,6 +221,7 @@ fn gen_when_one_branch() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn gen_large_when_int() {
assert_evals_to!(
indoc!(
@ -213,6 +244,7 @@ fn gen_large_when_int() {
}
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn gen_large_when_float() {
// assert_evals_to!(
// indoc!(
@ -235,6 +267,7 @@ fn gen_large_when_int() {
// }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn or_pattern() {
assert_evals_to!(
indoc!(
@ -250,6 +283,7 @@ fn or_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn apply_identity() {
assert_evals_to!(
indoc!(
@ -265,6 +299,7 @@ fn apply_identity() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn apply_unnamed_identity() {
assert_evals_to!(
indoc!(
@ -281,6 +316,7 @@ fn apply_unnamed_identity() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn return_unnamed_fn() {
assert_evals_to!(
indoc!(
@ -301,6 +337,7 @@ fn return_unnamed_fn() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn gen_when_fn() {
assert_evals_to!(
indoc!(
@ -320,6 +357,7 @@ fn gen_when_fn() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn gen_basic_def() {
assert_evals_to!(
indoc!(
@ -347,6 +385,7 @@ fn gen_basic_def() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn gen_multiple_defs() {
assert_evals_to!(
indoc!(
@ -380,6 +419,7 @@ fn gen_multiple_defs() {
// These tests caught a bug in how Defs are converted to the mono IR
// but they have UnusedDef or UnusedArgument problems, and don't run any more
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn gen_chained_defs() {
// assert_evals_to!(
// indoc!(
@ -399,6 +439,7 @@ fn gen_multiple_defs() {
// }
//
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn gen_nested_defs_old() {
// assert_evals_to!(
// indoc!(
@ -440,6 +481,7 @@ fn gen_multiple_defs() {
// }
//
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn let_x_in_x() {
// assert_evals_to!(
// indoc!(
@ -462,6 +504,7 @@ fn gen_multiple_defs() {
// }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn factorial() {
assert_evals_to!(
indoc!(
@ -483,6 +526,7 @@ fn factorial() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn peano1() {
assert_non_opt_evals_to!(
indoc!(
@ -503,6 +547,7 @@ fn peano1() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn peano2() {
assert_non_opt_evals_to!(
indoc!(
@ -524,6 +569,7 @@ fn peano2() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn top_level_constant() {
assert_evals_to!(
indoc!(
@ -542,6 +588,7 @@ fn top_level_constant() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_len_0() {
assert_non_opt_evals_to!(
indoc!(
@ -569,6 +616,7 @@ fn linked_list_len_0() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_len_twice_0() {
assert_non_opt_evals_to!(
indoc!(
@ -596,6 +644,7 @@ fn linked_list_len_twice_0() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_len_1() {
assert_non_opt_evals_to!(
indoc!(
@ -623,6 +672,7 @@ fn linked_list_len_1() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_len_twice_1() {
assert_non_opt_evals_to!(
indoc!(
@ -650,6 +700,7 @@ fn linked_list_len_twice_1() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_len_3() {
assert_non_opt_evals_to!(
indoc!(
@ -678,6 +729,7 @@ fn linked_list_len_3() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_sum_num_a() {
assert_non_opt_evals_to!(
indoc!(
@ -706,6 +758,7 @@ fn linked_list_sum_num_a() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_sum_int() {
assert_non_opt_evals_to!(
indoc!(
@ -733,6 +786,7 @@ fn linked_list_sum_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_map() {
assert_non_opt_evals_to!(
indoc!(
@ -766,6 +820,7 @@ fn linked_list_map() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_nested_maybe() {
assert_evals_to!(
indoc!(
@ -822,6 +877,7 @@ fn when_nested_maybe() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_peano() {
assert_non_opt_evals_to!(
indoc!(
@ -879,6 +935,7 @@ fn when_peano() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "Roc failed with message: ")]
fn overflow_frees_list() {
assert_evals_to!(
@ -903,6 +960,7 @@ fn overflow_frees_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "Roc failed with message: ")]
fn undefined_variable() {
assert_evals_to!(
@ -920,6 +978,7 @@ fn undefined_variable() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "Roc failed with message: ")]
fn annotation_without_body() {
assert_evals_to!(
@ -937,6 +996,7 @@ fn annotation_without_body() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn simple_closure() {
assert_evals_to!(
indoc!(
@ -958,6 +1018,7 @@ fn simple_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_closure() {
assert_evals_to!(
indoc!(
@ -981,6 +1042,7 @@ fn nested_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn closure_in_list() {
assert_evals_to!(
indoc!(
@ -1006,6 +1068,7 @@ fn closure_in_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn specialize_closure() {
use roc_std::RocList;
@ -1037,6 +1100,7 @@ fn specialize_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn io_poc_effect() {
assert_non_opt_evals_to!(
indoc!(
@ -1067,6 +1131,7 @@ fn io_poc_effect() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn io_poc_desugared() {
assert_evals_to!(
indoc!(
@ -1094,6 +1159,7 @@ fn io_poc_desugared() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn return_wrapped_function_pointer() {
assert_non_opt_evals_to!(
indoc!(
@ -1116,6 +1182,7 @@ fn return_wrapped_function_pointer() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn return_wrapped_function_pointer_b() {
assert_non_opt_evals_to!(
indoc!(
@ -1137,6 +1204,7 @@ fn return_wrapped_function_pointer_b() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn return_wrapped_closure() {
assert_non_opt_evals_to!(
indoc!(
@ -1162,6 +1230,7 @@ fn return_wrapped_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_is_singleton() {
assert_non_opt_evals_to!(
indoc!(
@ -1196,6 +1265,7 @@ fn linked_list_is_singleton() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_is_empty_1() {
assert_non_opt_evals_to!(
indoc!(
@ -1230,6 +1300,7 @@ fn linked_list_is_empty_1() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_is_empty_2() {
assert_non_opt_evals_to!(
indoc!(
@ -1261,6 +1332,7 @@ fn linked_list_is_empty_2() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_singleton() {
// verifies only that valid llvm is produced
assert_non_opt_evals_to!(
@ -1281,6 +1353,7 @@ fn linked_list_singleton() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn recursive_function_with_rigid() {
assert_non_opt_evals_to!(
indoc!(
@ -1307,6 +1380,7 @@ fn recursive_function_with_rigid() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn rbtree_insert() {
assert_non_opt_evals_to!(
indoc!(
@ -1394,6 +1468,7 @@ fn rbtree_insert() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn rbtree_balance_3() {
assert_non_opt_evals_to!(
indoc!(
@ -1418,6 +1493,7 @@ fn rbtree_balance_3() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn rbtree_layout_issue() {
// there is a flex var in here somewhere that blows up layout creation
@ -1459,6 +1535,7 @@ fn rbtree_layout_issue() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn rbtree_balance_mono_problem() {
// because of how the function is written, only `Red` is used and so in the function's
@ -1512,6 +1589,7 @@ fn rbtree_balance_mono_problem() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn rbtree_balance_full() {
assert_non_opt_evals_to!(
indoc!(
@ -1563,6 +1641,7 @@ fn rbtree_balance_full() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_pattern_match_two_ways() {
// exposed an issue in the ordering of pattern match checks when ran with `--release` mode
assert_non_opt_evals_to!(
@ -1616,6 +1695,7 @@ fn nested_pattern_match_two_ways() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_guarded_double_pattern_match() {
// the important part here is that the first case (with the nested Cons) does not match
// TODO this also has undefined behavior
@ -1647,6 +1727,7 @@ fn linked_list_guarded_double_pattern_match() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn linked_list_double_pattern_match() {
assert_non_opt_evals_to!(
indoc!(
@ -1672,6 +1753,7 @@ fn linked_list_double_pattern_match() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn binary_tree_double_pattern_match() {
assert_non_opt_evals_to!(
indoc!(
@ -1697,6 +1779,7 @@ fn binary_tree_double_pattern_match() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unified_empty_closure_bool() {
// none of the Closure tags will have a payload
// this was not handled correctly in the past
@ -1721,6 +1804,7 @@ fn unified_empty_closure_bool() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unified_empty_closure_byte() {
// none of the Closure tags will have a payload
// this was not handled correctly in the past
@ -1746,6 +1830,7 @@ fn unified_empty_closure_byte() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn task_always_twice() {
assert_non_opt_evals_to!(
indoc!(
@ -1790,6 +1875,7 @@ fn task_always_twice() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn wildcard_rigid() {
assert_non_opt_evals_to!(
indoc!(
@ -1819,6 +1905,7 @@ fn wildcard_rigid() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn todo_bad_error_message() {
assert_non_opt_evals_to!(
@ -1866,6 +1953,7 @@ fn todo_bad_error_message() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn hof_conditional() {
// exposed issue with the if condition being just a symbol
assert_evals_to!(
@ -1882,6 +1970,7 @@ fn hof_conditional() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(
expected = "Roc failed with message: \"Shadowing { original_region: |L 3-3, C 4-5|, shadow: |L 6-6, C 8-9| Ident"
)]
@ -1901,6 +1990,7 @@ fn pattern_shadowing() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "TODO non-exhaustive pattern")]
fn non_exhaustive_pattern_let() {
assert_evals_to!(
@ -1920,6 +2010,7 @@ fn non_exhaustive_pattern_let() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
#[should_panic(expected = "")]
fn unsupported_pattern_str_interp() {
@ -1937,6 +2028,7 @@ fn unsupported_pattern_str_interp() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn fingertree_basic() {
assert_non_opt_evals_to!(
@ -1978,6 +2070,7 @@ fn fingertree_basic() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn case_or_pattern() {
// the `0` branch body should only be generated once in the future
// it is currently duplicated
@ -1998,6 +2091,7 @@ fn case_or_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn rosetree_basic() {
assert_non_opt_evals_to!(
@ -2025,6 +2119,7 @@ fn rosetree_basic() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn case_jump() {
// the decision tree will generate a jump to the `1` branch here
assert_evals_to!(
@ -2050,6 +2145,7 @@ fn case_jump() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nullable_eval_cfold() {
// the decision tree will generate a jump to the `1` branch here
assert_evals_to!(
@ -2086,6 +2182,7 @@ fn nullable_eval_cfold() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_switch() {
// exposed bug with passing the right symbol/layout down into switch branch generation
assert_evals_to!(
@ -2128,6 +2225,7 @@ fn nested_switch() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn count_deriv_x() {
// exposed bug with basing the block_of_memory on a specific (smaller) tag layout
assert_evals_to!(
@ -2154,6 +2252,7 @@ fn count_deriv_x() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn deriv_pow() {
// exposed bug with ordering of variable declarations before switch
assert_evals_to!(
@ -2190,6 +2289,7 @@ fn deriv_pow() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn multiple_increment() {
// the `leaf` value will be incremented multiple times at once
assert_evals_to!(
@ -2223,6 +2323,7 @@ fn multiple_increment() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn switch_fuse_rc_non_exhaustive() {
assert_evals_to!(
indoc!(
@ -2252,6 +2353,7 @@ fn switch_fuse_rc_non_exhaustive() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn switch_fuse_rc_exhaustive() {
assert_evals_to!(
indoc!(
@ -2280,6 +2382,7 @@ fn switch_fuse_rc_exhaustive() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn build_then_apply_closure() {
assert_evals_to!(
indoc!(
@ -2299,6 +2402,7 @@ fn build_then_apply_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn expanded_result() {
assert_evals_to!(
indoc!(
@ -2329,6 +2433,7 @@ fn expanded_result() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn backpassing_result() {
assert_evals_to!(
@ -2362,6 +2467,7 @@ fn backpassing_result() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[should_panic(
expected = "Shadowing { original_region: |L 3-3, C 4-5|, shadow: |L 5-5, C 6-7| Ident"
)]
@ -2380,6 +2486,7 @@ fn function_malformed_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "Hit an erroneous type when creating a layout for")]
fn call_invalid_layout() {
assert_llvm_evals_to!(
@ -2399,6 +2506,7 @@ fn call_invalid_layout() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "An expectation failed!")]
fn expect_fail() {
assert_evals_to!(
@ -2415,6 +2523,7 @@ fn expect_fail() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn increment_or_double_closure() {
assert_evals_to!(
indoc!(
@ -2452,6 +2561,7 @@ fn increment_or_double_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn module_thunk_is_function() {
assert_evals_to!(
indoc!(
@ -2468,6 +2578,7 @@ fn module_thunk_is_function() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "Roc failed with message: ")]
fn hit_unresolved_type_variable() {
assert_evals_to!(
@ -2491,6 +2602,7 @@ fn hit_unresolved_type_variable() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn pattern_match_empty_record() {
assert_evals_to!(
indoc!(
@ -2510,6 +2622,7 @@ fn pattern_match_empty_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn pattern_match_unit_tag() {
assert_evals_to!(
indoc!(
@ -2534,6 +2647,7 @@ fn pattern_match_unit_tag() {
// see for why this is disabled on wasm32 https://github.com/rtfeldman/roc/issues/1687
#[cfg(not(feature = "wasm-cli-run"))]
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn mirror_llvm_alignment_padding() {
// see https://github.com/rtfeldman/roc/issues/1569
assert_evals_to!(
@ -2556,6 +2670,7 @@ fn mirror_llvm_alignment_padding() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn lambda_set_bool() {
assert_evals_to!(
indoc!(
@ -2580,6 +2695,7 @@ fn lambda_set_bool() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn lambda_set_byte() {
assert_evals_to!(
indoc!(
@ -2605,6 +2721,7 @@ fn lambda_set_byte() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn lambda_set_struct_byte() {
assert_evals_to!(
indoc!(
@ -2632,6 +2749,7 @@ fn lambda_set_struct_byte() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn lambda_set_enum_byte_byte() {
assert_evals_to!(
indoc!(
@ -2662,6 +2780,7 @@ fn lambda_set_enum_byte_byte() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_walk_until() {
// see https://github.com/rtfeldman/roc/issues/1576
assert_evals_to!(
@ -2687,6 +2806,7 @@ fn list_walk_until() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn int_literal_not_specialized_with_annotation() {
// see https://github.com/rtfeldman/roc/issues/1600
assert_evals_to!(
@ -2714,6 +2834,7 @@ fn int_literal_not_specialized_with_annotation() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn int_literal_not_specialized_no_annotation() {
// see https://github.com/rtfeldman/roc/issues/1600
assert_evals_to!(
@ -2740,6 +2861,7 @@ fn int_literal_not_specialized_no_annotation() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unresolved_tvar_when_capture_is_unused() {
// see https://github.com/rtfeldman/roc/issues/1585
assert_evals_to!(
@ -2766,6 +2888,7 @@ fn unresolved_tvar_when_capture_is_unused() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "Roc failed with message: ")]
fn value_not_exposed_hits_panic() {
assert_evals_to!(
@ -2784,6 +2907,7 @@ fn value_not_exposed_hits_panic() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn mix_function_and_closure() {
// see https://github.com/rtfeldman/roc/pull/1706
assert_evals_to!(
@ -2809,6 +2933,7 @@ fn mix_function_and_closure() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn mix_function_and_closure_level_of_indirection() {
// see https://github.com/rtfeldman/roc/pull/1706
assert_evals_to!(
@ -2833,6 +2958,7 @@ fn mix_function_and_closure_level_of_indirection() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn do_pass_bool_byte_closure_layout() {
// see https://github.com/rtfeldman/roc/pull/1706
// the distinction is actually important, dropping that info means some functions just get
@ -2908,6 +3034,7 @@ fn do_pass_bool_byte_closure_layout() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_rigid_list() {
assert_evals_to!(
indoc!(
@ -2932,6 +3059,7 @@ fn nested_rigid_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn nested_rigid_alias() {
assert_evals_to!(
indoc!(
@ -2958,6 +3086,7 @@ fn nested_rigid_alias() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn nested_rigid_tag_union() {
assert_evals_to!(
indoc!(
@ -2982,6 +3111,7 @@ fn nested_rigid_tag_union() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn call_that_needs_closure_parameter() {
// here both p2 is lifted to the top-level, which means that `list` must be
// passed to it from `manyAux`.

View file

@ -1,10 +1,17 @@
#![cfg(test)]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::assert_evals_to;
#[cfg(feature = "gen-wasm")]
use crate::helpers::wasm::assert_evals_to;
use crate::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn basic_record() {
assert_evals_to!(
indoc!(
@ -38,6 +45,7 @@ fn basic_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn f64_record() {
assert_evals_to!(
indoc!(
@ -77,6 +85,7 @@ fn f64_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn fn_record() {
assert_evals_to!(
indoc!(
@ -128,6 +137,7 @@ fn fn_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn def_record() {
assert_evals_to!(
indoc!(
@ -167,6 +177,7 @@ fn def_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn when_on_record() {
assert_evals_to!(
indoc!(
@ -181,6 +192,7 @@ fn when_on_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn when_record_with_guard_pattern() {
assert_evals_to!(
indoc!(
@ -195,6 +207,7 @@ fn when_record_with_guard_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn let_with_record_pattern() {
assert_evals_to!(
indoc!(
@ -210,6 +223,7 @@ fn let_with_record_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn record_guard_pattern() {
assert_evals_to!(
indoc!(
@ -225,6 +239,7 @@ fn record_guard_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn twice_record_access() {
assert_evals_to!(
indoc!(
@ -239,6 +254,7 @@ fn twice_record_access() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-dev"))]
fn empty_record() {
assert_evals_to!(
indoc!(
@ -253,6 +269,7 @@ fn empty_record() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn i64_record2_literal() {
assert_evals_to!(
indoc!(
@ -266,6 +283,7 @@ fn i64_record2_literal() {
}
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn i64_record3_literal() {
// assert_evals_to!(
// indoc!(
@ -277,8 +295,8 @@ fn i64_record2_literal() {
// (i64, i64, i64)
// );
// }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn f64_record2_literal() {
assert_evals_to!(
indoc!(
@ -292,6 +310,7 @@ fn f64_record2_literal() {
}
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn f64_record3_literal() {
// assert_evals_to!(
// indoc!(
@ -305,6 +324,7 @@ fn f64_record2_literal() {
// }
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn bool_record4_literal() {
// assert_evals_to!(
// indoc!(
@ -319,8 +339,8 @@ fn f64_record2_literal() {
// (bool, bool, bool, bool)
// );
// }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn i64_record1_literal() {
assert_evals_to!(
indoc!(
@ -334,6 +354,7 @@ fn i64_record1_literal() {
}
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn i64_record9_literal() {
// assert_evals_to!(
// indoc!(
@ -347,6 +368,7 @@ fn i64_record1_literal() {
// }
// #[test]
// #[cfg(any(feature = "gen-llvm"))]
// fn f64_record3_literal() {
// assert_evals_to!(
// indoc!(
@ -358,8 +380,8 @@ fn i64_record1_literal() {
// (f64, f64, f64)
// );
// }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bool_literal() {
assert_evals_to!(
indoc!(
@ -376,6 +398,7 @@ fn bool_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record() {
assert_evals_to!(
indoc!(
@ -392,6 +415,7 @@ fn return_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn optional_field_when_use_default() {
assert_evals_to!(
indoc!(
@ -419,6 +443,7 @@ fn optional_field_when_use_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn optional_field_when_use_default_nested() {
assert_evals_to!(
indoc!(
@ -442,6 +467,7 @@ fn optional_field_when_use_default_nested() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn optional_field_when_no_use_default() {
assert_evals_to!(
indoc!(
@ -462,6 +488,7 @@ fn optional_field_when_no_use_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn optional_field_when_no_use_default_nested() {
assert_evals_to!(
indoc!(
@ -479,6 +506,7 @@ fn optional_field_when_no_use_default_nested() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn optional_field_let_use_default() {
assert_evals_to!(
indoc!(
@ -499,6 +527,7 @@ fn optional_field_let_use_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn optional_field_let_no_use_default() {
assert_evals_to!(
indoc!(
@ -519,6 +548,7 @@ fn optional_field_let_no_use_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn optional_field_let_no_use_default_nested() {
assert_evals_to!(
indoc!(
@ -536,6 +566,7 @@ fn optional_field_let_no_use_default_nested() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn optional_field_function_use_default() {
assert_evals_to!(
indoc!(
@ -552,6 +583,7 @@ fn optional_field_function_use_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn optional_field_function_no_use_default() {
// blocked on https://github.com/rtfeldman/roc/issues/786
@ -572,6 +604,7 @@ fn optional_field_function_no_use_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn optional_field_function_no_use_default_nested() {
// blocked on https://github.com/rtfeldman/roc/issues/786
@ -590,6 +623,7 @@ fn optional_field_function_no_use_default_nested() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn optional_field_singleton_record() {
assert_evals_to!(
indoc!(
@ -604,6 +638,7 @@ fn optional_field_singleton_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn optional_field_empty_record() {
assert_evals_to!(
indoc!(
@ -618,6 +653,7 @@ fn optional_field_empty_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_2() {
assert_evals_to!(
indoc!(
@ -631,6 +667,7 @@ fn return_record_2() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_3() {
assert_evals_to!(
indoc!(
@ -644,6 +681,7 @@ fn return_record_3() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_4() {
assert_evals_to!(
indoc!(
@ -657,6 +695,7 @@ fn return_record_4() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_5() {
assert_evals_to!(
indoc!(
@ -670,6 +709,7 @@ fn return_record_5() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_6() {
assert_evals_to!(
indoc!(
@ -683,6 +723,7 @@ fn return_record_6() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_7() {
assert_evals_to!(
indoc!(
@ -696,6 +737,7 @@ fn return_record_7() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_float_int() {
assert_evals_to!(
indoc!(
@ -709,6 +751,7 @@ fn return_record_float_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_int_float() {
assert_evals_to!(
indoc!(
@ -722,6 +765,7 @@ fn return_record_int_float() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_float_float() {
assert_evals_to!(
indoc!(
@ -735,6 +779,7 @@ fn return_record_float_float() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_record_float_float_float() {
assert_evals_to!(
indoc!(
@ -748,6 +793,7 @@ fn return_record_float_float_float() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn return_nested_record() {
assert_evals_to!(
indoc!(
@ -761,11 +807,13 @@ fn return_nested_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn accessor_twice() {
assert_evals_to!(".foo { foo: 4 } + .foo { bar: 6.28, foo: 3 } ", 7, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn accessor_multi_element_record() {
assert_evals_to!(
indoc!(
@ -779,6 +827,7 @@ fn accessor_multi_element_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn accessor_single_element_record() {
assert_evals_to!(
indoc!(
@ -792,6 +841,7 @@ fn accessor_single_element_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn update_record() {
assert_evals_to!(
indoc!(
@ -807,6 +857,7 @@ fn update_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn update_single_element_record() {
assert_evals_to!(
indoc!(
@ -822,6 +873,7 @@ fn update_single_element_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn booleans_in_record() {
assert_evals_to!(
indoc!("{ x: 1 == 1, y: 1 == 1 }"),
@ -846,6 +898,7 @@ fn booleans_in_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn alignment_in_record() {
assert_evals_to!(
indoc!("{ c: 32, b: if True then Red else if True then Green else Blue, a: 1 == 1 }"),
@ -855,6 +908,7 @@ fn alignment_in_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn blue_and_present() {
assert_evals_to!(
indoc!(
@ -873,6 +927,7 @@ fn blue_and_present() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn blue_and_absent() {
assert_evals_to!(
indoc!(
@ -891,6 +946,7 @@ fn blue_and_absent() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn update_the_only_field() {
assert_evals_to!(
indoc!(

View file

@ -1,9 +1,18 @@
#![cfg(test)]
#![cfg(feature = "gen-llvm")]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
// #[cfg(feature = "gen-dev")]
// use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to;
use crate::assert_evals_to;
use indoc::indoc;
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn with_default() {
assert_evals_to!(
indoc!(
@ -33,6 +42,7 @@ fn with_default() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn result_map() {
assert_evals_to!(
indoc!(
@ -66,6 +76,7 @@ fn result_map() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn result_map_err() {
assert_evals_to!(
indoc!(
@ -99,6 +110,7 @@ fn result_map_err() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn err_type_var() {
assert_evals_to!(
indoc!(
@ -113,6 +125,7 @@ fn err_type_var() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn err_type_var_annotation() {
assert_evals_to!(
indoc!(
@ -130,6 +143,7 @@ fn err_type_var_annotation() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn err_empty_tag_union() {
assert_evals_to!(
indoc!(

View file

@ -1,10 +1,19 @@
#![cfg(test)]
#![cfg(feature = "gen-llvm")]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
// #[cfg(feature = "gen-dev")]
// use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to;
use crate::assert_evals_to;
use indoc::indoc;
use roc_std::RocList;
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn empty_len() {
assert_evals_to!(
indoc!(
@ -18,6 +27,7 @@ fn empty_len() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn single_len() {
assert_evals_to!(
indoc!(
@ -31,6 +41,7 @@ fn single_len() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn single_to_list() {
assert_evals_to!(
indoc!(
@ -64,6 +75,7 @@ fn single_to_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn insert() {
assert_evals_to!(
indoc!(
@ -81,6 +93,7 @@ fn insert() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn remove() {
assert_evals_to!(
indoc!(
@ -99,6 +112,7 @@ fn remove() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn union() {
assert_evals_to!(
indoc!(
@ -119,6 +133,7 @@ fn union() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn difference() {
assert_evals_to!(
indoc!(
@ -139,6 +154,7 @@ fn difference() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn intersection() {
assert_evals_to!(
indoc!(
@ -159,6 +175,7 @@ fn intersection() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn walk_sum() {
assert_evals_to!(
indoc!(
@ -172,6 +189,7 @@ fn walk_sum() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn contains() {
assert_evals_to!(
indoc!(
@ -195,6 +213,7 @@ fn contains() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn from_list() {
assert_evals_to!(
indoc!(

View file

@ -1,11 +1,22 @@
#![cfg(test)]
#![cfg(not(feature = "gen-wasm"))]
use crate::assert_evals_to;
use crate::assert_llvm_evals_to;
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_llvm_evals_to;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::assert_evals_to;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::assert_evals_to as assert_llvm_evals_to;
#[allow(unused_imports)]
use indoc::indoc;
#[allow(unused_imports)]
use roc_std::{RocList, RocStr};
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_bigger_delimiter_small_str() {
assert_evals_to!(
indoc!(
@ -35,6 +46,7 @@ fn str_split_bigger_delimiter_small_str() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_str_concat_repeated() {
assert_evals_to!(
indoc!(
@ -58,6 +70,7 @@ fn str_split_str_concat_repeated() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_small_str_bigger_delimiter() {
assert_evals_to!(
indoc!(
@ -76,6 +89,7 @@ fn str_split_small_str_bigger_delimiter() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_big_str_small_delimiter() {
assert_evals_to!(
indoc!(
@ -105,6 +119,7 @@ fn str_split_big_str_small_delimiter() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_small_str_small_delimiter() {
assert_evals_to!(
indoc!(
@ -122,6 +137,7 @@ fn str_split_small_str_small_delimiter() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_bigger_delimiter_big_strs() {
assert_evals_to!(
indoc!(
@ -137,6 +153,7 @@ fn str_split_bigger_delimiter_big_strs() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_empty_strs() {
assert_evals_to!(
indoc!(
@ -150,6 +167,7 @@ fn str_split_empty_strs() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_minimal_example() {
assert_evals_to!(
indoc!(
@ -163,6 +181,7 @@ fn str_split_minimal_example() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_small_str_big_delimiter() {
assert_evals_to!(
indoc!(
@ -195,6 +214,7 @@ fn str_split_small_str_big_delimiter() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_small_str_20_char_delimiter() {
assert_evals_to!(
indoc!(
@ -214,6 +234,7 @@ fn str_split_small_str_20_char_delimiter() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_concat_big_to_big() {
assert_evals_to!(
indoc!(
@ -229,6 +250,7 @@ fn str_concat_big_to_big() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn small_str_literal() {
assert_llvm_evals_to!(
"\"JJJJJJJJJJJJJJJ\"",
@ -255,6 +277,7 @@ fn small_str_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn small_str_zeroed_literal() {
// Verifies that we zero out unused bytes in the string.
// This is important so that string equality tests don't randomly
@ -284,6 +307,7 @@ fn small_str_zeroed_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn small_str_concat_empty_first_arg() {
assert_llvm_evals_to!(
r#"Str.concat "" "JJJJJJJJJJJJJJJ""#,
@ -310,6 +334,7 @@ fn small_str_concat_empty_first_arg() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn small_str_concat_empty_second_arg() {
assert_llvm_evals_to!(
r#"Str.concat "JJJJJJJJJJJJJJJ" """#,
@ -336,6 +361,7 @@ fn small_str_concat_empty_second_arg() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn small_str_concat_small_to_big() {
assert_evals_to!(
r#"Str.concat "abc" " this is longer than 15 chars""#,
@ -345,6 +371,7 @@ fn small_str_concat_small_to_big() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn small_str_concat_small_to_small_staying_small() {
assert_llvm_evals_to!(
r#"Str.concat "J" "JJJJJJJJJJJJJJ""#,
@ -371,6 +398,7 @@ fn small_str_concat_small_to_small_staying_small() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn small_str_concat_small_to_small_overflow_to_big() {
assert_evals_to!(
r#"Str.concat "abcdefghijklm" "nopqrstuvwxyz""#,
@ -380,16 +408,19 @@ fn small_str_concat_small_to_small_overflow_to_big() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_concat_empty() {
assert_evals_to!(r#"Str.concat "" """#, RocStr::default(), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn small_str_is_empty() {
assert_evals_to!(r#"Str.isEmpty "abc""#, false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn big_str_is_empty() {
assert_evals_to!(
r#"Str.isEmpty "this is more than 15 chars long""#,
@ -399,11 +430,13 @@ fn big_str_is_empty() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn empty_str_is_empty() {
assert_evals_to!(r#"Str.isEmpty """#, true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with() {
assert_evals_to!(r#"Str.startsWith "hello world" "hell""#, true, bool);
assert_evals_to!(r#"Str.startsWith "hello world" """#, true, bool);
@ -413,6 +446,7 @@ fn str_starts_with() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_code_point() {
assert_evals_to!(
&format!(r#"Str.startsWithCodePt "foobar" {}"#, 'f' as u32),
@ -427,6 +461,7 @@ fn str_starts_with_code_point() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_ends_with() {
assert_evals_to!(r#"Str.endsWith "hello world" "world""#, true, bool);
assert_evals_to!(r#"Str.endsWith "nope" "hello world""#, false, bool);
@ -434,16 +469,19 @@ fn str_ends_with() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_count_graphemes_small_str() {
assert_evals_to!(r#"Str.countGraphemes "å🤔""#, 2, usize);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_count_graphemes_three_js() {
assert_evals_to!(r#"Str.countGraphemes "JJJ""#, 3, usize);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_count_graphemes_big_str() {
assert_evals_to!(
r#"Str.countGraphemes "6🤔å🤔e¥🤔çppkd🙃1jdal🦯asdfa∆ltråø˚waia8918.,🏅jjc""#,
@ -453,6 +491,7 @@ fn str_count_graphemes_big_str() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_same_big_str() {
assert_evals_to!(
r#"Str.startsWith "123456789123456789" "123456789123456789""#,
@ -462,6 +501,7 @@ fn str_starts_with_same_big_str() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_different_big_str() {
assert_evals_to!(
r#"Str.startsWith "12345678912345678910" "123456789123456789""#,
@ -471,20 +511,24 @@ fn str_starts_with_different_big_str() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_same_small_str() {
assert_evals_to!(r#"Str.startsWith "1234" "1234""#, true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_different_small_str() {
assert_evals_to!(r#"Str.startsWith "1234" "12""#, true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_false_small_str() {
assert_evals_to!(r#"Str.startsWith "1234" "23""#, false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_int() {
assert_evals_to!(
r#"Str.fromInt 1234"#,
@ -518,6 +562,7 @@ fn str_from_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_single_ascii() {
assert_evals_to!(
indoc!(
@ -533,6 +578,7 @@ fn str_from_utf8_pass_single_ascii() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_many_ascii() {
assert_evals_to!(
indoc!(
@ -548,6 +594,7 @@ fn str_from_utf8_pass_many_ascii() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_single_unicode() {
assert_evals_to!(
indoc!(
@ -563,6 +610,7 @@ fn str_from_utf8_pass_single_unicode() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_many_unicode() {
assert_evals_to!(
indoc!(
@ -578,6 +626,7 @@ fn str_from_utf8_pass_many_unicode() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_single_grapheme() {
assert_evals_to!(
indoc!(
@ -593,6 +642,7 @@ fn str_from_utf8_pass_single_grapheme() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_many_grapheme() {
assert_evals_to!(
indoc!(
@ -608,6 +658,7 @@ fn str_from_utf8_pass_many_grapheme() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_pass_all() {
assert_evals_to!(
indoc!(
@ -623,6 +674,7 @@ fn str_from_utf8_pass_all() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_fail_invalid_start_byte() {
assert_evals_to!(
indoc!(
@ -642,6 +694,7 @@ fn str_from_utf8_fail_invalid_start_byte() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_fail_unexpected_end_of_sequence() {
assert_evals_to!(
indoc!(
@ -661,6 +714,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_fail_expected_continuation() {
assert_evals_to!(
indoc!(
@ -680,6 +734,7 @@ fn str_from_utf8_fail_expected_continuation() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_fail_overlong_encoding() {
assert_evals_to!(
indoc!(
@ -699,6 +754,7 @@ fn str_from_utf8_fail_overlong_encoding() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_fail_codepoint_too_large() {
assert_evals_to!(
indoc!(
@ -718,6 +774,7 @@ fn str_from_utf8_fail_codepoint_too_large() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_fail_surrogate_half() {
assert_evals_to!(
indoc!(
@ -737,6 +794,7 @@ fn str_from_utf8_fail_surrogate_half() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_equality() {
assert_evals_to!(r#""a" == "a""#, true, bool);
assert_evals_to!(
@ -761,6 +819,7 @@ fn str_clone() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_recursive_literal() {
assert_evals_to!(
indoc!(
@ -791,6 +850,7 @@ fn nested_recursive_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_join_comma_small() {
assert_evals_to!(
r#"Str.joinWith ["1", "2"] ", " "#,
@ -800,6 +860,7 @@ fn str_join_comma_small() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_join_comma_big() {
assert_evals_to!(
r#"Str.joinWith ["10000000", "2000000", "30000000"] ", " "#,
@ -809,16 +870,19 @@ fn str_join_comma_big() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_join_comma_single() {
assert_evals_to!(r#"Str.joinWith ["1"] ", " "#, RocStr::from("1"), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_float() {
assert_evals_to!(r#"Str.fromFloat 3.14"#, RocStr::from("3.14"), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_to_utf8() {
assert_evals_to!(
r#"Str.toUtf8 "hello""#,
@ -836,6 +900,7 @@ fn str_to_utf8() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range() {
assert_evals_to!(
indoc!(
@ -852,6 +917,7 @@ fn str_from_utf8_range() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range_slice() {
assert_evals_to!(
indoc!(
@ -868,6 +934,7 @@ fn str_from_utf8_range_slice() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range_slice_not_end() {
assert_evals_to!(
indoc!(
@ -884,6 +951,7 @@ fn str_from_utf8_range_slice_not_end() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range_order_does_not_matter() {
assert_evals_to!(
indoc!(
@ -900,6 +968,7 @@ fn str_from_utf8_range_order_does_not_matter() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range_out_of_bounds_start_value() {
assert_evals_to!(
indoc!(
@ -917,6 +986,7 @@ fn str_from_utf8_range_out_of_bounds_start_value() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range_count_too_high() {
assert_evals_to!(
indoc!(
@ -934,6 +1004,7 @@ fn str_from_utf8_range_count_too_high() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_from_utf8_range_count_too_high_for_start() {
assert_evals_to!(
indoc!(
@ -951,6 +1022,7 @@ fn str_from_utf8_range_count_too_high_for_start() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_repeat_small() {
assert_evals_to!(
indoc!(r#"Str.repeat "Roc" 3"#),
@ -960,6 +1032,7 @@ fn str_repeat_small() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_repeat_big() {
assert_evals_to!(
indoc!(r#"Str.repeat "more than 16 characters" 2"#),
@ -969,26 +1042,31 @@ fn str_repeat_big() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_repeat_empty_string() {
assert_evals_to!(indoc!(r#"Str.repeat "" 3"#), RocStr::from(""), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_repeat_zero_times() {
assert_evals_to!(indoc!(r#"Str.repeat "Roc" 0"#), RocStr::from(""), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_empty_string() {
assert_evals_to!(indoc!(r#"Str.trim """#), RocStr::from(""), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_small_blank_string() {
assert_evals_to!(indoc!(r#"Str.trim " ""#), RocStr::from(""), RocStr);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_small_to_small() {
assert_evals_to!(
indoc!(r#"Str.trim " hello world ""#),
@ -998,6 +1076,7 @@ fn str_trim_small_to_small() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_large_to_large_unique() {
assert_evals_to!(
indoc!(r#"Str.trim (Str.concat " " "hello world from a large string ")"#),
@ -1007,6 +1086,7 @@ fn str_trim_large_to_large_unique() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_large_to_small_unique() {
assert_evals_to!(
indoc!(r#"Str.trim (Str.concat " " "hello world ")"#),
@ -1016,6 +1096,7 @@ fn str_trim_large_to_small_unique() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_large_to_large_shared() {
assert_evals_to!(
indoc!(
@ -1035,6 +1116,7 @@ fn str_trim_large_to_large_shared() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_large_to_small_shared() {
assert_evals_to!(
indoc!(
@ -1054,6 +1136,7 @@ fn str_trim_large_to_small_shared() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_trim_small_to_small_shared() {
assert_evals_to!(
indoc!(

View file

@ -1,11 +1,20 @@
#![cfg(test)]
#![cfg(feature = "gen-llvm")]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
// #[cfg(feature = "gen-dev")]
// use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to;
use crate::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
use roc_std::{RocList, RocStr};
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn width_and_alignment_u8_u8() {
use roc_mono::layout::Builtin;
use roc_mono::layout::Layout;
@ -23,6 +32,7 @@ fn width_and_alignment_u8_u8() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_nothing_ir() {
assert_evals_to!(
indoc!(
@ -42,6 +52,7 @@ fn applied_tag_nothing_ir() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_nothing() {
assert_evals_to!(
indoc!(
@ -61,6 +72,7 @@ fn applied_tag_nothing() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_just() {
assert_evals_to!(
indoc!(
@ -79,6 +91,7 @@ fn applied_tag_just() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_just_ir() {
assert_evals_to!(
indoc!(
@ -97,6 +110,7 @@ fn applied_tag_just_ir() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_just_enum() {
assert_evals_to!(
indoc!(
@ -120,6 +134,7 @@ fn applied_tag_just_enum() {
}
// #[test]
#[cfg(any(feature = "gen-llvm"))]
// fn raw_result() {
// assert_evals_to!(
// indoc!(
@ -134,8 +149,8 @@ fn applied_tag_just_enum() {
// i8
// );
// }
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn true_is_true() {
assert_evals_to!(
indoc!(
@ -152,6 +167,7 @@ fn true_is_true() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn false_is_false() {
assert_evals_to!(
indoc!(
@ -168,6 +184,7 @@ fn false_is_false() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn basic_enum() {
assert_evals_to!(
indoc!(
@ -189,6 +206,7 @@ fn basic_enum() {
}
// #[test]
#[cfg(any(feature = "gen-llvm"))]
// fn linked_list_empty() {
// assert_evals_to!(
// indoc!(
@ -207,6 +225,7 @@ fn basic_enum() {
// }
//
// #[test]
#[cfg(any(feature = "gen-llvm"))]
// fn linked_list_singleton() {
// assert_evals_to!(
// indoc!(
@ -225,6 +244,7 @@ fn basic_enum() {
// }
//
// #[test]
#[cfg(any(feature = "gen-llvm"))]
// fn linked_list_is_empty() {
// assert_evals_to!(
// indoc!(
@ -244,8 +264,8 @@ fn basic_enum() {
// bool
// );
// }
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn even_odd() {
assert_evals_to!(
indoc!(
@ -271,6 +291,7 @@ fn even_odd() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn gen_literal_true() {
assert_evals_to!(
indoc!(
@ -284,6 +305,7 @@ fn gen_literal_true() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn gen_if_float() {
assert_evals_to!(
indoc!(
@ -296,6 +318,7 @@ fn gen_if_float() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_on_nothing() {
assert_evals_to!(
indoc!(
@ -314,6 +337,7 @@ fn when_on_nothing() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_on_just() {
assert_evals_to!(
indoc!(
@ -332,6 +356,7 @@ fn when_on_just() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_on_result() {
assert_evals_to!(
indoc!(
@ -350,6 +375,7 @@ fn when_on_result() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_on_these() {
assert_evals_to!(
indoc!(
@ -371,6 +397,7 @@ fn when_on_these() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn match_on_two_values() {
// this will produce a Chain internally
assert_evals_to!(
@ -387,6 +414,7 @@ fn match_on_two_values() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn pair_with_guard_pattern() {
assert_evals_to!(
indoc!(
@ -403,6 +431,7 @@ fn pair_with_guard_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn result_with_guard_pattern() {
// This test revealed an issue with hashing Test values
assert_evals_to!(
@ -423,6 +452,7 @@ fn result_with_guard_pattern() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn maybe_is_just() {
assert_evals_to!(
indoc!(
@ -447,6 +477,7 @@ fn maybe_is_just() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn maybe_is_just_nested() {
assert_evals_to!(
indoc!(
@ -468,6 +499,7 @@ fn maybe_is_just_nested() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_pattern_match() {
assert_evals_to!(
indoc!(
@ -488,6 +520,7 @@ fn nested_pattern_match() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_vanilla() {
assert_evals_to!(
indoc!(
@ -503,6 +536,7 @@ fn if_guard_vanilla() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn when_on_single_value_tag() {
// this fails because the switched-on symbol is not defined
@ -520,6 +554,7 @@ fn when_on_single_value_tag() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_multiple() {
assert_evals_to!(
indoc!(
@ -540,6 +575,7 @@ fn if_guard_multiple() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_constructor_switch() {
assert_evals_to!(
indoc!(
@ -583,6 +619,7 @@ fn if_guard_constructor_switch() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_constructor_chain() {
assert_evals_to!(
indoc!(
@ -599,6 +636,7 @@ fn if_guard_constructor_chain() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_pattern_false() {
assert_evals_to!(
indoc!(
@ -617,6 +655,7 @@ fn if_guard_pattern_false() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_switch() {
assert_evals_to!(
indoc!(
@ -635,6 +674,7 @@ fn if_guard_switch() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_pattern_true() {
assert_evals_to!(
indoc!(
@ -653,6 +693,7 @@ fn if_guard_pattern_true() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn if_guard_exhaustiveness() {
assert_evals_to!(
indoc!(
@ -671,6 +712,7 @@ fn if_guard_exhaustiveness() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn when_on_enum() {
assert_evals_to!(
indoc!(
@ -692,6 +734,7 @@ fn when_on_enum() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn pattern_matching_unit() {
assert_evals_to!(
indoc!(
@ -750,6 +793,7 @@ fn pattern_matching_unit() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn one_element_tag() {
assert_evals_to!(
indoc!(
@ -766,6 +810,7 @@ fn one_element_tag() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_tag_union() {
assert_evals_to!(
indoc!(
@ -786,6 +831,7 @@ fn nested_tag_union() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unit_type() {
assert_evals_to!(
indoc!(
@ -804,6 +850,7 @@ fn unit_type() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_record_load() {
assert_evals_to!(
indoc!(
@ -821,6 +868,7 @@ fn nested_record_load() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn join_point_if() {
assert_evals_to!(
indoc!(
@ -837,6 +885,7 @@ fn join_point_if() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn join_point_when() {
assert_evals_to!(
indoc!(
@ -862,6 +911,7 @@ fn join_point_when() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn join_point_with_cond_expr() {
assert_evals_to!(
indoc!(
@ -900,6 +950,7 @@ fn join_point_with_cond_expr() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn alignment_in_single_tag_construction() {
assert_evals_to!(indoc!("Three (1 == 1) 32"), (32i64, true), (i64, bool));
@ -911,6 +962,7 @@ fn alignment_in_single_tag_construction() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn alignment_in_single_tag_pattern_match() {
assert_evals_to!(
indoc!(
@ -942,6 +994,7 @@ fn alignment_in_single_tag_pattern_match() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn alignment_in_multi_tag_construction_two() {
assert_evals_to!(
indoc!(
@ -959,6 +1012,7 @@ fn alignment_in_multi_tag_construction_two() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn alignment_in_multi_tag_construction_three() {
assert_evals_to!(
indoc!(
@ -975,6 +1029,7 @@ fn alignment_in_multi_tag_construction_three() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn alignment_in_multi_tag_pattern_match() {
assert_evals_to!(
indoc!(
@ -1013,6 +1068,7 @@ fn alignment_in_multi_tag_pattern_match() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn phantom_polymorphic() {
// see https://github.com/rtfeldman/roc/issues/786 and below
@ -1038,6 +1094,7 @@ fn phantom_polymorphic() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn phantom_polymorphic_record() {
// see https://github.com/rtfeldman/roc/issues/786
@ -1065,6 +1122,7 @@ fn phantom_polymorphic_record() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn result_never() {
assert_evals_to!(
indoc!(
@ -1086,6 +1144,7 @@ fn result_never() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn nested_recursive_literal() {
assert_evals_to!(
indoc!(
@ -1105,6 +1164,7 @@ fn nested_recursive_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn newtype_wrapper() {
assert_evals_to!(
indoc!(
@ -1128,6 +1188,7 @@ fn newtype_wrapper() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_function() {
assert_evals_to!(
indoc!(
@ -1147,6 +1208,7 @@ fn applied_tag_function() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_function_result() {
assert_evals_to!(
indoc!(
@ -1166,6 +1228,7 @@ fn applied_tag_function_result() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn applied_tag_function_linked_list() {
assert_evals_to!(
indoc!(
@ -1186,6 +1249,7 @@ fn applied_tag_function_linked_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(expected = "")]
fn tag_must_be_its_own_type() {
assert_evals_to!(

View file

@ -0,0 +1,252 @@
use libloading::Library;
use roc_build::link::{link, LinkType};
use roc_builtins::bitcode;
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::MutMap;
use tempfile::tempdir;
#[allow(dead_code)]
fn promote_expr_to_module(src: &str) -> String {
let mut buffer = String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n");
for line in src.lines() {
// indent the body!
buffer.push_str(" ");
buffer.push_str(line);
buffer.push('\n');
}
buffer
}
#[allow(dead_code)]
pub fn helper(
arena: &bumpalo::Bump,
src: &str,
stdlib: roc_builtins::std::StdLib,
_leak: bool,
lazy_literals: bool,
) -> (String, Vec<roc_problem::can::Problem>, Library) {
use std::path::{Path, PathBuf};
let dir = tempdir().unwrap();
let filename = PathBuf::from("Test.roc");
let src_dir = Path::new("fake/test/path");
let app_o_file = dir.path().join("app.o");
let module_src;
let temp;
if src.starts_with("app") {
// this is already a module
module_src = src;
} else {
// this is an expression, promote it to a module
temp = promote_expr_to_module(src);
module_src = &temp;
}
let exposed_types = MutMap::default();
let loaded = roc_load::file::load_and_monomorphize_from_str(
arena,
filename,
module_src,
&stdlib,
src_dir,
exposed_types,
8,
builtin_defs_map,
);
let mut loaded = loaded.expect("failed to load module");
use roc_load::file::MonomorphizedModule;
let MonomorphizedModule {
procedures: top_procedures,
interns,
exposed_to_host,
..
} = loaded;
let mut procedures = MutMap::default();
for (key, proc) in top_procedures {
procedures.insert(key, proc);
}
// You can comment and uncomment this block out to get more useful information
// while you're working on the dev backend!
{
// println!("=========== Procedures ==========");
// println!("{:?}", procedures);
// println!("=================================\n");
// println!("=========== Interns ==========");
// println!("{:?}", interns);
// println!("=================================\n");
// println!("=========== Exposed ==========");
// println!("{:?}", exposed_to_host);
// println!("=================================\n");
}
debug_assert_eq!(exposed_to_host.len(), 1);
let main_fn_symbol = loaded.entry_point.symbol;
let main_fn_layout = loaded.entry_point.layout;
let mut layout_ids = roc_mono::layout::LayoutIds::default();
let main_fn_name_base = layout_ids
.get_toplevel(main_fn_symbol, &main_fn_layout)
.to_symbol_string(main_fn_symbol, &interns);
let main_fn_name = format!("roc_{}_exposed", main_fn_name_base);
let mut lines = Vec::new();
// errors whose reporting we delay (so we can see that code gen generates runtime errors)
let mut delayed_errors = Vec::new();
for (home, (module_path, src)) in loaded.sources {
use roc_reporting::report::{
can_problem, mono_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE,
};
let can_problems = loaded.can_problems.remove(&home).unwrap_or_default();
let type_problems = loaded.type_problems.remove(&home).unwrap_or_default();
let mono_problems = loaded.mono_problems.remove(&home).unwrap_or_default();
let error_count = can_problems.len() + type_problems.len() + mono_problems.len();
if error_count == 0 {
continue;
}
let src_lines: Vec<&str> = src.split('\n').collect();
let palette = DEFAULT_PALETTE;
// Report parsing and canonicalization problems
let alloc = RocDocAllocator::new(&src_lines, home, &interns);
use roc_problem::can::Problem::*;
for problem in can_problems.into_iter() {
// Ignore "unused" problems
match problem {
UnusedDef(_, _) | UnusedArgument(_, _, _) | UnusedImport(_, _) => {
delayed_errors.push(problem);
continue;
}
_ => {
let report = can_problem(&alloc, module_path.clone(), problem);
let mut buf = String::new();
report.render_color_terminal(&mut buf, &alloc, &palette);
lines.push(buf);
}
}
}
for problem in type_problems {
if let Some(report) = type_problem(&alloc, module_path.clone(), problem) {
let mut buf = String::new();
report.render_color_terminal(&mut buf, &alloc, &palette);
lines.push(buf);
}
}
for problem in mono_problems {
let report = mono_problem(&alloc, module_path.clone(), problem);
let mut buf = String::new();
report.render_color_terminal(&mut buf, &alloc, &palette);
lines.push(buf);
}
}
if !lines.is_empty() {
println!("{}", lines.join("\n"));
assert_eq!(0, 1, "Mistakes were made");
}
let env = roc_gen_dev::Env {
arena,
interns,
exposed_to_host: exposed_to_host.keys().copied().collect(),
lazy_literals,
generate_allocators: true, // Needed for testing, since we don't have a platform
};
let target = target_lexicon::Triple::host();
let module_object =
roc_gen_dev::build_module(&env, &target, procedures).expect("failed to compile module");
let module_out = module_object
.write()
.expect("failed to build output object");
std::fs::write(&app_o_file, module_out).expect("failed to write object to file");
// std::fs::copy(&app_o_file, "/tmp/app.o").unwrap();
let (mut child, dylib_path) = link(
&target,
app_o_file.clone(),
// Long term we probably want a smarter way to link in zig builtins.
// With the current method all methods are kept and it adds about 100k to all outputs.
&[app_o_file.to_str().unwrap(), bitcode::OBJ_PATH],
LinkType::Dylib,
)
.expect("failed to link dynamic library");
child.wait().unwrap();
// Load the dylib
let path = dylib_path.as_path().to_str().unwrap();
// std::fs::copy(&path, "/tmp/libapp.so").unwrap();
let lib = unsafe { Library::new(path) }.expect("failed to load shared library");
(main_fn_name, delayed_errors, lib)
}
#[allow(unused_macros)]
macro_rules! assert_evals_to {
($src:expr, $expected:expr, $ty:ty) => {{
assert_evals_to!($src, $expected, $ty, (|val| val));
}};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
// Same as above, except with an additional transformation argument.
{
assert_evals_to!($src, $expected, $ty, $transform, true);
}
};
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr) => {
// Run both with and without lazy literal optimization.
{
assert_evals_to!($src, $expected, $ty, $transform, $leak, false);
}
{
assert_evals_to!($src, $expected, $ty, $transform, $leak, true);
}
};
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr, $lazy_literals:expr) => {
use bumpalo::Bump;
use roc_gen_dev::run_jit_function_raw;
let stdlib = roc_builtins::std::standard_stdlib();
let arena = Bump::new();
let (main_fn_name, errors, lib) =
$crate::helpers::dev::helper(&arena, $src, stdlib, $leak, $lazy_literals);
let transform = |success| {
let expected = $expected;
let given = $transform(success);
assert_eq!(&given, &expected);
};
run_jit_function_raw!(lib, main_fn_name, $ty, transform, errors)
};
}
#[allow(unused_imports)]
pub(crate) use assert_evals_to;

View file

@ -0,0 +1,210 @@
use roc_std::{RocDec, RocList, RocOrder, RocStr};
pub trait FromWasm32Memory: Sized {
const SIZE_OF_WASM: usize;
const ALIGN_OF_WASM: usize;
const ACTUAL_WIDTH: usize = if (Self::SIZE_OF_WASM % Self::ALIGN_OF_WASM) == 0 {
Self::SIZE_OF_WASM
} else {
Self::SIZE_OF_WASM + (Self::ALIGN_OF_WASM - (Self::SIZE_OF_WASM % Self::ALIGN_OF_WASM))
};
fn decode(memory: &wasmer::Memory, offset: u32) -> Self;
}
macro_rules! from_wasm_memory_primitive_decode {
($type_name:ident) => {
const SIZE_OF_WASM: usize = core::mem::size_of::<$type_name>();
const ALIGN_OF_WASM: usize = core::mem::align_of::<$type_name>();
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
use core::mem::MaybeUninit;
let mut output: MaybeUninit<Self> = MaybeUninit::uninit();
let width = std::mem::size_of::<Self>();
let ptr = output.as_mut_ptr();
let raw_ptr = ptr as *mut u8;
let slice = unsafe { std::slice::from_raw_parts_mut(raw_ptr, width) };
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(offset as u32);
let foobar = (ptr.deref(memory, 0, width as u32)).unwrap();
let wasm_slice = unsafe { std::mem::transmute(foobar) };
slice.copy_from_slice(wasm_slice);
unsafe { output.assume_init() }
}
};
}
macro_rules! from_wasm_memory_primitive {
($($type_name:ident ,)+) => {
$(
impl FromWasm32Memory for $type_name {
from_wasm_memory_primitive_decode!($type_name);
}
)*
}
}
from_wasm_memory_primitive!(
u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, f32, f64, bool, RocDec, RocOrder,
);
impl FromWasm32Memory for () {
const SIZE_OF_WASM: usize = 0;
const ALIGN_OF_WASM: usize = 0;
fn decode(_: &wasmer::Memory, _: u32) -> Self {}
}
impl FromWasm32Memory for RocStr {
const SIZE_OF_WASM: usize = 8;
const ALIGN_OF_WASM: usize = 4;
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let bytes = <u64 as FromWasm32Memory>::decode(memory, offset);
let length = (bytes >> 32) as u32;
let elements = bytes as u32;
if length == 0 {
RocStr::default()
} else if (length as i32) < 0 {
// this is a small string
let last_byte = bytes.to_ne_bytes()[7];
let actual_length = (last_byte ^ 0b1000_0000) as usize;
let slice = &bytes.to_ne_bytes()[..actual_length as usize];
RocStr::from_slice(slice)
} else {
// this is a big string
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(elements);
let foobar = (ptr.deref(memory, 0, length)).unwrap();
let wasm_slice = unsafe { std::mem::transmute(foobar) };
RocStr::from_slice(wasm_slice)
}
}
}
impl<T: FromWasm32Memory + Clone> FromWasm32Memory for RocList<T> {
const SIZE_OF_WASM: usize = 8;
const ALIGN_OF_WASM: usize = 4;
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let bytes = <u64 as FromWasm32Memory>::decode(memory, offset);
let length = (bytes >> 32) as u32;
let elements = bytes as u32;
let mut items = Vec::with_capacity(length as usize);
for i in 0..length {
let item = <T as FromWasm32Memory>::decode(
memory,
elements + i * <T as FromWasm32Memory>::SIZE_OF_WASM as u32,
);
items.push(item);
}
RocList::from_slice(&items)
}
}
impl<T: FromWasm32Memory> FromWasm32Memory for &'_ T {
const SIZE_OF_WASM: usize = 4;
const ALIGN_OF_WASM: usize = 4;
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let elements = <u32 as FromWasm32Memory>::decode(memory, offset);
let actual = <T as FromWasm32Memory>::decode(memory, elements);
let b = Box::new(actual);
std::boxed::Box::<T>::leak(b)
}
}
impl<T: FromWasm32Memory + Clone, const N: usize> FromWasm32Memory for [T; N] {
const SIZE_OF_WASM: usize = N * T::SIZE_OF_WASM;
const ALIGN_OF_WASM: usize = T::ALIGN_OF_WASM;
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(offset);
let width = <T as FromWasm32Memory>::SIZE_OF_WASM as u32 * N as u32;
let foobar = (ptr.deref(memory, 0, width)).unwrap();
let wasm_slice: &[T; N] = unsafe { &*(foobar as *const _ as *const [T; N]) };
wasm_slice.clone()
}
}
impl FromWasm32Memory for usize {
const SIZE_OF_WASM: usize = 4;
const ALIGN_OF_WASM: usize = 4;
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
<u32 as FromWasm32Memory>::decode(memory, offset) as usize
}
}
impl<T: FromWasm32Memory, U: FromWasm32Memory> FromWasm32Memory for (T, U) {
const SIZE_OF_WASM: usize = T::SIZE_OF_WASM + U::SIZE_OF_WASM;
const ALIGN_OF_WASM: usize = max2(T::SIZE_OF_WASM, U::SIZE_OF_WASM);
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
debug_assert!(
T::ALIGN_OF_WASM >= U::ALIGN_OF_WASM,
"this function does not handle alignment"
);
let t = <T as FromWasm32Memory>::decode(memory, offset);
let u = <U as FromWasm32Memory>::decode(memory, offset + T::ACTUAL_WIDTH as u32);
(t, u)
}
}
const fn max2(a: usize, b: usize) -> usize {
if a > b {
a
} else {
b
}
}
const fn max3(a: usize, b: usize, c: usize) -> usize {
max2(max2(a, b), c)
}
impl<T: FromWasm32Memory, U: FromWasm32Memory, V: FromWasm32Memory> FromWasm32Memory for (T, U, V) {
const SIZE_OF_WASM: usize = T::SIZE_OF_WASM + U::SIZE_OF_WASM + V::SIZE_OF_WASM;
const ALIGN_OF_WASM: usize = max3(T::SIZE_OF_WASM, U::SIZE_OF_WASM, V::SIZE_OF_WASM);
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
debug_assert!(
T::ALIGN_OF_WASM >= U::ALIGN_OF_WASM,
"this function does not handle alignment"
);
debug_assert!(
U::ALIGN_OF_WASM >= V::ALIGN_OF_WASM,
"this function does not handle alignment"
);
let t = <T as FromWasm32Memory>::decode(memory, offset);
let u = <U as FromWasm32Memory>::decode(memory, offset + T::ACTUAL_WIDTH as u32);
let v = <V as FromWasm32Memory>::decode(
memory,
offset + T::ACTUAL_WIDTH as u32 + U::ACTUAL_WIDTH as u32,
);
(t, u, v)
}
}

View file

@ -1,3 +1,4 @@
use crate::helpers::from_wasm32_memory::FromWasm32Memory;
use inkwell::module::Module;
use libloading::Library;
use roc_build::link::module_to_dylib;
@ -10,7 +11,6 @@ use roc_module::symbol::Symbol;
use roc_mono::ir::OptLevel;
use roc_types::subs::VarStore;
use target_lexicon::Triple;
use test_wasm_util::from_wasm32_memory::FromWasm32Memory;
fn promote_expr_to_module(src: &str) -> String {
let mut buffer = String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n");
@ -469,7 +469,7 @@ where
let stdlib = arena.alloc(roc_builtins::std::standard_stdlib());
let is_gen_test = true;
let instance = crate::helpers::eval::helper_wasm(
let instance = crate::helpers::llvm::helper_wasm(
&arena,
src,
stdlib,
@ -480,7 +480,7 @@ where
let memory = instance.exports.get_memory("memory").unwrap();
crate::helpers::eval::MEMORY.with(|f| {
crate::helpers::llvm::MEMORY.with(|f| {
*f.borrow_mut() = Some(unsafe { std::mem::transmute(memory) });
});
@ -494,7 +494,7 @@ where
_ => panic!(),
};
let output = <T as crate::helpers::eval::FromWasm32Memory>::decode(
let output = <T as crate::helpers::llvm::FromWasm32Memory>::decode(
memory,
// skip the RocCallResult tag id
address as u32 + 8,
@ -505,10 +505,10 @@ where
}
}
#[macro_export]
#[allow(unused_macros)]
macro_rules! assert_wasm_evals_to {
($src:expr, $expected:expr, $ty:ty, $transform:expr, $ignore_problems:expr) => {
match $crate::helpers::eval::assert_wasm_evals_to_help::<$ty>($src, $ignore_problems) {
match $crate::helpers::llvm::assert_wasm_evals_to_help::<$ty>($src, $ignore_problems) {
Err(msg) => panic!("Wasm test failed: {:?}", msg),
Ok(actual) => {
#[allow(clippy::bool_assert_comparison)]
@ -518,15 +518,21 @@ macro_rules! assert_wasm_evals_to {
};
($src:expr, $expected:expr, $ty:ty) => {
$crate::assert_wasm_evals_to!($src, $expected, $ty, $crate::helpers::eval::identity, false);
$crate::helpers::llvm::assert_wasm_evals_to!(
$src,
$expected,
$ty,
$crate::helpers::llvm::identity,
false
);
};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
$crate::assert_wasm_evals_to!($src, $expected, $ty, $transform, false);
$crate::helpers::llvm::assert_wasm_evals_to!($src, $expected, $ty, $transform, false);
};
}
#[macro_export]
#[allow(unused_macros)]
macro_rules! assert_llvm_evals_to {
($src:expr, $expected:expr, $ty:ty, $transform:expr, $ignore_problems:expr) => {
use bumpalo::Bump;
@ -540,7 +546,7 @@ macro_rules! assert_llvm_evals_to {
let stdlib = arena.alloc(roc_builtins::std::standard_stdlib());
let is_gen_test = true;
let (main_fn_name, errors, lib) = $crate::helpers::eval::helper(
let (main_fn_name, errors, lib) = $crate::helpers::llvm::helper(
&arena,
$src,
stdlib,
@ -559,26 +565,32 @@ macro_rules! assert_llvm_evals_to {
};
($src:expr, $expected:expr, $ty:ty) => {
$crate::assert_llvm_evals_to!($src, $expected, $ty, $crate::helpers::eval::identity, false);
$crate::helpers::llvm::assert_llvm_evals_to!(
$src,
$expected,
$ty,
$crate::helpers::llvm::identity,
false
);
};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
$crate::assert_llvm_evals_to!($src, $expected, $ty, $transform, false);
$crate::helpers::llvm::assert_llvm_evals_to!($src, $expected, $ty, $transform, false);
};
}
#[macro_export]
#[allow(unused_macros)]
macro_rules! assert_evals_to {
($src:expr, $expected:expr, $ty:ty) => {{
assert_evals_to!($src, $expected, $ty, $crate::helpers::eval::identity);
assert_evals_to!($src, $expected, $ty, $crate::helpers::llvm::identity);
}};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
// Same as above, except with an additional transformation argument.
{
#[cfg(feature = "wasm-cli-run")]
$crate::assert_wasm_evals_to!($src, $expected, $ty, $transform, false);
$crate::helpers::llvm::assert_wasm_evals_to!($src, $expected, $ty, $transform, false);
$crate::assert_llvm_evals_to!($src, $expected, $ty, $transform, false);
$crate::helpers::llvm::assert_llvm_evals_to!($src, $expected, $ty, $transform, false);
}
};
}
@ -588,18 +600,32 @@ pub fn identity<T>(value: T) -> T {
value
}
#[macro_export]
#[allow(unused_macros)]
macro_rules! assert_non_opt_evals_to {
($src:expr, $expected:expr, $ty:ty) => {{
$crate::assert_llvm_evals_to!($src, $expected, $ty, $crate::helpers::eval::identity);
$crate::helpers::llvm::assert_llvm_evals_to!(
$src,
$expected,
$ty,
$crate::helpers::llvm::identity
);
}};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
// Same as above, except with an additional transformation argument.
{
$crate::assert_llvm_evals_to!($src, $expected, $ty, $transform, false);
$crate::helpers::llvm::assert_llvm_evals_to!($src, $expected, $ty, $transform, false);
}
};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {{
$crate::assert_llvm_evals_to!($src, $expected, $ty, $transform);
$crate::helpers::llvm::assert_llvm_evals_to!($src, $expected, $ty, $transform);
}};
}
#[allow(unused_imports)]
pub(crate) use assert_evals_to;
#[allow(unused_imports)]
pub(crate) use assert_llvm_evals_to;
#[allow(unused_imports)]
pub(crate) use assert_non_opt_evals_to;
#[allow(unused_imports)]
pub(crate) use assert_wasm_evals_to;

View file

@ -1,7 +1,14 @@
extern crate bumpalo;
#[macro_use]
pub mod eval;
#[cfg(feature = "gen-dev")]
pub mod dev;
pub mod from_wasm32_memory;
#[cfg(feature = "gen-llvm")]
pub mod llvm;
#[cfg(feature = "gen-wasm")]
pub mod wasm;
#[cfg(feature = "gen-wasm")]
pub mod wasm32_test_result;
/// Used in the with_larger_debug_stack() function, for tests that otherwise
/// run out of stack space in debug builds (but don't in --release builds)

View file

@ -0,0 +1,239 @@
use std::cell::Cell;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use crate::helpers::from_wasm32_memory::FromWasm32Memory;
use crate::helpers::wasm32_test_result::Wasm32TestResult;
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::{MutMap, MutSet};
const TEST_WRAPPER_NAME: &str = "test_wrapper";
std::thread_local! {
static TEST_COUNTER: Cell<u32> = Cell::new(0);
}
fn promote_expr_to_module(src: &str) -> String {
let mut buffer = String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n");
for line in src.lines() {
// indent the body!
buffer.push_str(" ");
buffer.push_str(line);
buffer.push('\n');
}
buffer
}
#[allow(dead_code)]
pub fn helper_wasm<'a, T: Wasm32TestResult>(
arena: &'a bumpalo::Bump,
src: &str,
stdlib: &'a roc_builtins::std::StdLib,
_result_type_dummy: &T,
) -> wasmer::Instance {
use std::path::{Path, PathBuf};
let filename = PathBuf::from("Test.roc");
let src_dir = Path::new("fake/test/path");
let module_src;
let temp;
if src.starts_with("app") {
// this is already a module
module_src = src;
} else {
// this is an expression, promote it to a module
temp = promote_expr_to_module(src);
module_src = &temp;
}
let exposed_types = MutMap::default();
let loaded = roc_load::file::load_and_monomorphize_from_str(
arena,
filename,
module_src,
stdlib,
src_dir,
exposed_types,
8,
builtin_defs_map,
);
let loaded = loaded.expect("failed to load module");
use roc_load::file::MonomorphizedModule;
let MonomorphizedModule {
procedures,
interns,
exposed_to_host,
..
} = loaded;
// You can comment and uncomment this block out to get more useful information
// while you're working on the wasm backend!
// {
// println!("=========== Procedures ==========");
// println!("{:?}", procedures);
// println!("=================================\n");
// println!("=========== Interns ==========");
// println!("{:?}", interns);
// println!("=================================\n");
// println!("=========== Exposed ==========");
// println!("{:?}", exposed_to_host);
// println!("=================================\n");
// }
debug_assert_eq!(exposed_to_host.len(), 1);
let main_fn_symbol = loaded.entry_point.symbol;
let main_fn_index = procedures
.keys()
.position(|(s, _)| *s == main_fn_symbol)
.unwrap();
let exposed_to_host = exposed_to_host.keys().copied().collect::<MutSet<_>>();
let env = roc_gen_wasm::Env {
arena,
interns,
exposed_to_host,
};
let mut wasm_module = roc_gen_wasm::build_module_help(&env, procedures).unwrap();
T::insert_test_wrapper(
arena,
&mut wasm_module,
TEST_WRAPPER_NAME,
main_fn_index as u32,
);
let mut module_bytes = std::vec::Vec::with_capacity(4096);
wasm_module.serialize_mut(&mut module_bytes);
// for debugging (e.g. with wasm2wat or wasm-objdump)
if false {
use std::io::Write;
let mut hash_state = DefaultHasher::new();
src.hash(&mut hash_state);
let src_hash = hash_state.finish();
// Filename contains a hash of the Roc test source code. Helpful when comparing across commits.
let dir = "/tmp/roc/compiler/gen_wasm/output";
std::fs::create_dir_all(dir).unwrap();
let path = format!("{}/test-{:016x}.wasm", dir, src_hash);
// Print out filename (appears just after test name)
println!("dumping file {:?}", path);
match std::fs::File::create(path) {
Err(e) => eprintln!("Problem creating wasm debug file: {:?}", e),
Ok(mut file) => {
file.write_all(&module_bytes).unwrap();
}
}
}
// now, do wasmer stuff
use wasmer::{Instance, Module, Store};
let store = Store::default();
// let module = Module::from_file(&store, &test_wasm_path).unwrap();
let wasmer_module = Module::from_binary(&store, &module_bytes).unwrap();
// First, we create the `WasiEnv`
use wasmer_wasi::WasiState;
let mut wasi_env = WasiState::new("hello").finalize().unwrap();
// Then, we get the import object related to our WASI
// and attach it to the Wasm instance.
let import_object = wasi_env
.import_object(&wasmer_module)
.unwrap_or_else(|_| wasmer::imports!());
Instance::new(&wasmer_module, &import_object).unwrap()
}
#[allow(dead_code)]
pub fn assert_wasm_evals_to_help<T>(src: &str, expected: T) -> Result<T, String>
where
T: FromWasm32Memory + Wasm32TestResult,
{
let arena = bumpalo::Bump::new();
// NOTE the stdlib must be in the arena; just taking a reference will segfault
let stdlib = arena.alloc(roc_builtins::std::standard_stdlib());
let instance = crate::helpers::wasm::helper_wasm(&arena, src, stdlib, &expected);
let memory = instance.exports.get_memory("__linear_memory").unwrap();
let test_wrapper = instance.exports.get_function(TEST_WRAPPER_NAME).unwrap();
match test_wrapper.call(&[]) {
Err(e) => Err(format!("{:?}", e)),
Ok(result) => {
let address = match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
};
let output = <T as FromWasm32Memory>::decode(memory, address as u32);
Ok(output)
}
}
}
#[allow(unused_macros)]
macro_rules! assert_wasm_evals_to {
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
match $crate::helpers::wasm::assert_wasm_evals_to_help::<$ty>($src, $expected) {
Err(msg) => panic!("{:?}", msg),
Ok(actual) => {
assert_eq!($transform(actual), $expected)
}
}
};
($src:expr, $expected:expr, $ty:ty) => {
$crate::helpers::wasm::assert_wasm_evals_to!(
$src,
$expected,
$ty,
$crate::helpers::wasm::identity
);
};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
$crate::helpers::wasm::assert_wasm_evals_to!($src, $expected, $ty, $transform);
};
}
#[allow(unused_macros)]
macro_rules! assert_evals_to {
($src:expr, $expected:expr, $ty:ty) => {{
assert_evals_to!($src, $expected, $ty, $crate::helpers::wasm::identity);
}};
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
// Same as above, except with an additional transformation argument.
{
$crate::helpers::wasm::assert_wasm_evals_to!($src, $expected, $ty, $transform);
}
};
}
#[allow(dead_code)]
pub fn identity<T>(value: T) -> T {
value
}
#[allow(unused_imports)]
pub(crate) use assert_evals_to;
#[allow(unused_imports)]
pub(crate) use assert_wasm_evals_to;

View file

@ -0,0 +1,279 @@
use bumpalo::collections::Vec;
use crate::helpers::from_wasm32_memory::FromWasm32Memory;
use roc_gen_wasm::wasm_module::{
linking::SymInfo, linking::WasmObjectSymbol, Align, CodeBuilder, Export, ExportType, LocalId,
Signature, ValueType, WasmModule,
};
use roc_std::{RocDec, RocList, RocOrder, RocStr};
pub trait Wasm32TestResult {
fn insert_test_wrapper<'a>(
arena: &'a bumpalo::Bump,
module: &mut WasmModule<'a>,
wrapper_name: &str,
main_function_index: u32,
) {
let index = module.code.code_builders.len() as u32;
module.add_function_signature(Signature {
param_types: Vec::with_capacity_in(0, arena),
ret_type: Some(ValueType::I32),
});
module.export.entries.push(Export {
name: wrapper_name.to_string(),
ty: ExportType::Func,
index,
});
let symbol_table = module.linking.symbol_table_mut();
symbol_table.push(SymInfo::Function(WasmObjectSymbol::Defined {
flags: 0,
index,
name: wrapper_name.to_string(),
}));
let mut code_builder = CodeBuilder::new(arena);
Self::build_wrapper_body(&mut code_builder, main_function_index);
module.code.code_builders.push(code_builder);
}
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32);
}
macro_rules! build_wrapper_body_primitive {
($store_instruction: ident, $align: expr) => {
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
let frame_pointer_id = LocalId(0);
let frame_pointer = Some(frame_pointer_id);
let local_types = &[ValueType::I32];
let frame_size = 8;
// Main's symbol index is the same as its function index, since the first symbols we created were for procs
let main_symbol_index = main_function_index;
code_builder.get_local(frame_pointer_id);
code_builder.call(main_function_index, main_symbol_index, 0, true);
code_builder.$store_instruction($align, 0);
code_builder.get_local(frame_pointer_id);
code_builder.build_fn_header(local_types, frame_size, frame_pointer);
}
};
}
macro_rules! wasm_test_result_primitive {
($type_name: ident, $store_instruction: ident, $align: expr) => {
impl Wasm32TestResult for $type_name {
build_wrapper_body_primitive!($store_instruction, $align);
}
};
}
fn build_wrapper_body_stack_memory(
code_builder: &mut CodeBuilder,
main_function_index: u32,
size: usize,
) {
let local_id = LocalId(0);
let local_types = &[ValueType::I32];
let frame_pointer = Some(local_id);
// Main's symbol index is the same as its function index, since the first symbols we created were for procs
let main_symbol_index = main_function_index;
code_builder.get_local(local_id);
code_builder.call(main_function_index, main_symbol_index, 0, true);
code_builder.get_local(local_id);
code_builder.build_fn_header(local_types, size as i32, frame_pointer);
}
macro_rules! wasm_test_result_stack_memory {
($type_name: ident) => {
impl Wasm32TestResult for $type_name {
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
$type_name::ACTUAL_WIDTH,
)
}
}
};
}
wasm_test_result_primitive!(bool, i32_store8, Align::Bytes1);
wasm_test_result_primitive!(RocOrder, i32_store8, Align::Bytes1);
wasm_test_result_primitive!(u8, i32_store8, Align::Bytes1);
wasm_test_result_primitive!(i8, i32_store8, Align::Bytes1);
wasm_test_result_primitive!(u16, i32_store16, Align::Bytes2);
wasm_test_result_primitive!(i16, i32_store16, Align::Bytes2);
wasm_test_result_primitive!(u32, i32_store, Align::Bytes4);
wasm_test_result_primitive!(i32, i32_store, Align::Bytes4);
wasm_test_result_primitive!(u64, i64_store, Align::Bytes8);
wasm_test_result_primitive!(i64, i64_store, Align::Bytes8);
wasm_test_result_primitive!(usize, i32_store, Align::Bytes4);
wasm_test_result_primitive!(f32, f32_store, Align::Bytes8);
wasm_test_result_primitive!(f64, f64_store, Align::Bytes8);
wasm_test_result_stack_memory!(u128);
wasm_test_result_stack_memory!(i128);
wasm_test_result_stack_memory!(RocDec);
wasm_test_result_stack_memory!(RocStr);
impl<T: Wasm32TestResult> Wasm32TestResult for RocList<T> {
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(code_builder, main_function_index, 12)
}
}
impl<T: Wasm32TestResult> Wasm32TestResult for &'_ T {
build_wrapper_body_primitive!(i32_store, Align::Bytes4);
}
impl<T, const N: usize> Wasm32TestResult for [T; N]
where
T: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(code_builder, main_function_index, N * T::ACTUAL_WIDTH)
}
}
impl<T, U> Wasm32TestResult for (T, U)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH,
)
}
}
impl<T, U, V> Wasm32TestResult for (T, U, V)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
V: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH,
)
}
}
impl<T, U, V, W> Wasm32TestResult for (T, U, V, W)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
V: Wasm32TestResult + FromWasm32Memory,
W: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH,
)
}
}
impl<T, U, V, W, X> Wasm32TestResult for (T, U, V, W, X)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
V: Wasm32TestResult + FromWasm32Memory,
W: Wasm32TestResult + FromWasm32Memory,
X: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH + X::ACTUAL_WIDTH,
)
}
}
impl<T, U, V, W, X, Y> Wasm32TestResult for (T, U, V, W, X, Y)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
V: Wasm32TestResult + FromWasm32Memory,
W: Wasm32TestResult + FromWasm32Memory,
X: Wasm32TestResult + FromWasm32Memory,
Y: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH
+ U::ACTUAL_WIDTH
+ V::ACTUAL_WIDTH
+ W::ACTUAL_WIDTH
+ X::ACTUAL_WIDTH
+ Y::ACTUAL_WIDTH,
)
}
}
impl<T, U, V, W, X, Y, Z> Wasm32TestResult for (T, U, V, W, X, Y, Z)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
V: Wasm32TestResult + FromWasm32Memory,
W: Wasm32TestResult + FromWasm32Memory,
X: Wasm32TestResult + FromWasm32Memory,
Y: Wasm32TestResult + FromWasm32Memory,
Z: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH
+ U::ACTUAL_WIDTH
+ V::ACTUAL_WIDTH
+ W::ACTUAL_WIDTH
+ X::ACTUAL_WIDTH
+ Y::ACTUAL_WIDTH
+ Z::ACTUAL_WIDTH,
)
}
}
impl<T, U, V, W, X, Y, Z, A> Wasm32TestResult for (T, U, V, W, X, Y, Z, A)
where
T: Wasm32TestResult + FromWasm32Memory,
U: Wasm32TestResult + FromWasm32Memory,
V: Wasm32TestResult + FromWasm32Memory,
W: Wasm32TestResult + FromWasm32Memory,
X: Wasm32TestResult + FromWasm32Memory,
Y: Wasm32TestResult + FromWasm32Memory,
Z: Wasm32TestResult + FromWasm32Memory,
A: Wasm32TestResult + FromWasm32Memory,
{
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
build_wrapper_body_stack_memory(
code_builder,
main_function_index,
T::ACTUAL_WIDTH
+ U::ACTUAL_WIDTH
+ V::ACTUAL_WIDTH
+ W::ACTUAL_WIDTH
+ X::ACTUAL_WIDTH
+ Y::ACTUAL_WIDTH
+ Z::ACTUAL_WIDTH
+ A::ACTUAL_WIDTH,
)
}
}

View file

@ -10,8 +10,48 @@ pub mod gen_list;
pub mod gen_num;
pub mod gen_primitives;
pub mod gen_records;
pub mod gen_result;
pub mod gen_set;
pub mod gen_str;
pub mod gen_tags;
mod helpers;
pub mod wasm_str;
use core::ffi::c_void;
#[no_mangle]
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
libc::malloc(size)
}
#[no_mangle]
pub unsafe fn roc_realloc(
c_ptr: *mut c_void,
new_size: usize,
_old_size: usize,
_alignment: u32,
) -> *mut c_void {
libc::realloc(c_ptr, new_size)
}
#[no_mangle]
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
libc::free(c_ptr)
}
#[no_mangle]
pub unsafe fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
use roc_gen_llvm::llvm::build::PanicTagId;
use std::convert::TryFrom;
use std::ffi::CStr;
use std::os::raw::c_char;
match PanicTagId::try_from(tag_id) {
Ok(PanicTagId::NullTerminatedString) => {
let slice = CStr::from_ptr(c_ptr as *const c_char);
let string = slice.to_str().unwrap();
eprintln!("Roc hit a panic: {}", string);
std::process::exit(1);
}
Err(_) => unreachable!(),
}
}

File diff suppressed because it is too large Load diff