Merge branch 'trunk' of github.com:rtfeldman/roc into update_zig_09

This commit is contained in:
Brian Carroll 2022-04-11 18:37:05 +01:00
commit 9b0c7fad41
107 changed files with 4162 additions and 1741 deletions

View file

@ -954,7 +954,7 @@ fn list_keep_if_str_is_hello() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_on_empty_list_with_int_layout() {
assert_evals_to!(
indoc!(
@ -972,7 +972,7 @@ fn list_map_on_empty_list_with_int_layout() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_on_non_empty_list() {
assert_evals_to!(
indoc!(
@ -990,7 +990,7 @@ fn list_map_on_non_empty_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_changes_input() {
assert_evals_to!(
indoc!(
@ -1008,7 +1008,7 @@ fn list_map_changes_input() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_on_big_list() {
assert_evals_to!(
indoc!(
@ -1028,7 +1028,7 @@ fn list_map_on_big_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_with_type_change() {
assert_evals_to!(
indoc!(
@ -1047,7 +1047,7 @@ fn list_map_with_type_change() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_using_defined_function() {
assert_evals_to!(
indoc!(
@ -1069,7 +1069,7 @@ fn list_map_using_defined_function() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_map_all_inline() {
assert_evals_to!(
indoc!(

View file

@ -2160,7 +2160,7 @@ fn max_u8() {
);
}
macro_rules! to_int_tests {
macro_rules! num_conversion_tests {
($($fn:expr, $typ:ty, ($($test_name:ident, $input:expr, $output:expr $(, [ $($support_gen:literal),* ])? )*))*) => {$($(
#[test]
#[cfg(any(feature = "gen-llvm", $($(feature = $support_gen)*)?))]
@ -2171,7 +2171,7 @@ macro_rules! to_int_tests {
)*)*}
}
to_int_tests! {
num_conversion_tests! {
"Num.toI8", i8, (
to_i8_same_width, "15u8", 15, ["gen-wasm"]
to_i8_truncate, "115i32", 115, ["gen-wasm"]
@ -2232,6 +2232,36 @@ to_int_tests! {
to_nat_truncate, "115i128", 115
to_nat_truncate_wraps, "10_000_000_000_000_000_000_000i128", 1864712049423024128
)
"Num.toF32", f32, (
to_f32_from_i8, "15i8", 15.0
to_f32_from_i16, "15i16", 15.0
to_f32_from_i32, "15i32", 15.0
to_f32_from_i64, "15i64", 15.0
to_f32_from_i128, "15i128", 15.0
to_f32_from_u8, "15u8", 15.0
to_f32_from_u16, "15u16", 15.0
to_f32_from_u32, "15u32", 15.0
to_f32_from_u64, "15u64", 15.0
to_f32_from_u128, "15u128", 15.0
to_f32_from_nat, "15nat", 15.0
to_f32_from_f32, "1.5f32", 1.5
to_f32_from_f64, "1.5f64", 1.5
)
"Num.toF64", f64, (
to_f64_from_i8, "15i8", 15.0
to_f64_from_i16, "15i16", 15.0
to_f64_from_i32, "15i32", 15.0
to_f64_from_i64, "15i64", 15.0
to_f64_from_i128, "15i128", 15.0
to_f64_from_u8, "15u8", 15.0
to_f64_from_u16, "15u16", 15.0
to_f64_from_u32, "15u32", 15.0
to_f64_from_u64, "15u64", 15.0
to_f64_from_u128, "15u128", 15.0
to_f64_from_nat, "15nat", 15.0
to_f64_from_f32, "1.5f32", 1.5
to_f64_from_f64, "1.5f64", 1.5
)
}
macro_rules! to_int_checked_tests {

View file

@ -1074,7 +1074,7 @@ fn closure_in_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn specialize_closure() {
use roc_std::RocList;
@ -2660,7 +2660,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"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn mirror_llvm_alignment_padding() {
// see https://github.com/rtfeldman/roc/issues/1569
assert_evals_to!(
@ -2683,7 +2683,7 @@ fn mirror_llvm_alignment_padding() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lambda_set_bool() {
assert_evals_to!(
indoc!(
@ -2708,7 +2708,7 @@ fn lambda_set_bool() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lambda_set_byte() {
assert_evals_to!(
indoc!(
@ -2762,7 +2762,7 @@ fn lambda_set_struct_byte() {
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn lambda_set_enum_byte_byte() {
assert_evals_to!(
indoc!(
@ -3275,3 +3275,47 @@ fn box_and_unbox_string() {
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn box_and_unbox_num() {
assert_evals_to!(
indoc!(
r#"
Box.unbox (Box.box (123u8))
"#
),
123,
u8
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn box_and_unbox_record() {
assert_evals_to!(
indoc!(
r#"
Box.unbox (Box.box { a: 15u8, b: 27u8 })
"#
),
(15, 27),
(u8, u8)
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn box_and_unbox_tag_union() {
assert_evals_to!(
indoc!(
r#"
v : [ A U8, B U8 ] # usually stack allocated
v = B 27u8
Box.unbox (Box.box v)
"#
),
(27, 1),
(u8, u8)
)
}

View file

@ -301,8 +301,8 @@ fn refcount_different_rosetrees_inc() {
(Pointer, Pointer),
&[
Live(2), // s
Live(3), // i1
Live(2), // s1
Live(3), // i1
Live(1), // [i1, i1]
Live(1), // i2
Live(1), // [s1, s1]

View file

@ -256,3 +256,15 @@ fn roc_result_err() {
RocResult<i64, RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn issue_2583_specialize_errors_behind_unified_branches() {
assert_evals_to!(
r#"
if True then List.first [15] else Str.toI64 ""
"#,
RocResult::ok(15i64),
RocResult<i64, bool>
)
}

View file

@ -1587,3 +1587,19 @@ fn str_to_dec() {
RocDec
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn issue_2811() {
assert_evals_to!(
indoc!(
r#"
x = Command { tool: "bash" }
Command c = x
c.tool
"#
),
RocStr::from("bash"),
RocStr
);
}