Merge pull request #5336 from roc-lang/dev-backend-list-map

dev backend: many more builtins
This commit is contained in:
Folkert de Vries 2023-05-01 10:20:15 +02:00 committed by GitHub
commit a5a91d428f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 900 additions and 373 deletions

View file

@ -1176,29 +1176,21 @@ fn gen_div_checked_by_zero_i64() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn gen_rem_i64() {
assert_evals_to!(
indoc!(
r#"
Num.rem 8 3
"#
),
2,
i64
);
assert_evals_to!("Num.rem 8 3", 2, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn gen_rem_checked_div_by_zero_i64() {
assert_evals_to!(
indoc!(
r#"
when Num.remChecked 8 0 is
Err DivByZero -> 4
Ok _ -> -23
"#
when Num.remChecked 8 0 is
Err DivByZero -> 4
Ok _ -> -23
"#
),
4,
i64
@ -1978,17 +1970,15 @@ fn float_negative_mul_overflow() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn int_mul_wrap() {
assert_evals_to!(
indoc!(
r#"
Num.mulWrap Num.maxI64 2
"#
),
-2,
i64
);
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn int_mul_wrap_i64() {
assert_evals_to!("Num.mulWrap Num.maxI64 2", -2, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn int_mul_wrap_i128() {
assert_evals_to!("Num.mulWrap Num.maxI128 2", -2, i128);
}
#[test]
@ -2107,7 +2097,7 @@ fn shift_right_zf_by() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn shift_right_cast_i8() {
// FIXME (Brian) Something funny happening with 8-bit binary literals in tests
@ -2141,311 +2131,135 @@ fn shift_right_cast_i8() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn min_i128() {
assert_evals_to!(
indoc!(
r#"
Num.minI128
"#
),
i128::MIN,
i128
);
assert_evals_to!("Num.minI128", i128::MIN, i128);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn max_i128() {
assert_evals_to!(
indoc!(
r#"
Num.maxI128
"#
),
i128::MAX,
i128
);
assert_evals_to!("Num.maxI128", i128::MAX, i128);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_i64() {
assert_evals_to!(
indoc!(
r#"
Num.minI64
"#
),
i64::MIN,
i64
);
assert_evals_to!("Num.minI64", i64::MIN, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_i64() {
assert_evals_to!(
indoc!(
r#"
Num.maxI64
"#
),
i64::MAX,
i64
);
assert_evals_to!("Num.maxI64", i64::MAX, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_u64() {
assert_evals_to!(
indoc!(
r#"
Num.minU64
"#
),
u64::MIN,
u64
);
assert_evals_to!("Num.minU64", u64::MIN, u64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_u64() {
assert_evals_to!(
indoc!(
r#"
Num.maxU64
"#
),
u64::MAX,
u64
);
assert_evals_to!("Num.maxU64", u64::MAX, u64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_i32() {
assert_evals_to!(
indoc!(
r#"
Num.minI32
"#
),
i32::MIN,
i32
);
assert_evals_to!("Num.minI32", i32::MIN, i32);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_i32() {
assert_evals_to!(
indoc!(
r#"
Num.maxI32
"#
),
i32::MAX,
i32
);
assert_evals_to!("Num.maxI32", i32::MAX, i32);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_u32() {
assert_evals_to!(
indoc!(
r#"
Num.minU32
"#
),
u32::MIN,
u32
);
assert_evals_to!("Num.minU32", u32::MIN, u32);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_u32() {
assert_evals_to!(
indoc!(
r#"
Num.maxU32
"#
),
u32::MAX,
u32
);
assert_evals_to!("Num.maxU32", u32::MAX, u32);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_i16() {
assert_evals_to!(
indoc!(
r#"
Num.minI16
"#
),
i16::MIN,
i16
);
assert_evals_to!("Num.minI16", i16::MIN, i16);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_i16() {
assert_evals_to!(
indoc!(
r#"
Num.maxI16
"#
),
i16::MAX,
i16
);
assert_evals_to!("Num.maxI16", i16::MAX, i16);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_u16() {
assert_evals_to!(
indoc!(
r#"
Num.minU16
"#
),
u16::MIN,
u16
);
assert_evals_to!("Num.minU16", u16::MIN, u16);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_u16() {
assert_evals_to!(
indoc!(
r#"
Num.maxU16
"#
),
u16::MAX,
u16
);
assert_evals_to!("Num.maxU16", u16::MAX, u16);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_i8() {
assert_evals_to!(
indoc!(
r#"
Num.minI8
"#
),
i8::MIN,
i8
);
assert_evals_to!("Num.minI8", i8::MIN, i8);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_i8() {
assert_evals_to!(
indoc!(
r#"
Num.maxI8
"#
),
i8::MAX,
i8
);
assert_evals_to!("Num.maxI8", i8::MAX, i8);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_u8() {
assert_evals_to!(
indoc!(
r#"
Num.minU8
"#
),
u8::MIN,
u8
);
assert_evals_to!("Num.minU8", u8::MIN, u8);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_u8() {
assert_evals_to!(
indoc!(
r#"
Num.maxU8
"#
),
u8::MAX,
u8
);
assert_evals_to!("Num.maxU8", u8::MAX, u8);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_f64() {
assert_evals_to!(
indoc!(
r#"
Num.maxF64
"#
),
f64::MAX,
f64
);
assert_evals_to!("Num.maxF64", f64::MAX, f64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_f64() {
assert_evals_to!(
indoc!(
r#"
Num.minF64
"#
),
f64::MIN,
f64
);
assert_evals_to!("Num.minF64", f64::MIN, f64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn max_f32() {
assert_evals_to!(
indoc!(
r#"
Num.maxF32
"#
),
f32::MAX,
f32
);
assert_evals_to!("Num.maxF32", f32::MAX, f32);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn min_f32() {
assert_evals_to!(
indoc!(
r#"
Num.minF32
"#
),
f32::MIN,
f32
);
assert_evals_to!("Num.minF32", f32::MIN, f32);
}
#[test]
@ -2458,7 +2272,7 @@ fn to_nat_truncate_wraps() {
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)*)?))]
#[cfg(any(feature = "gen-llvm", $($(feature = $support_gen,)*)?))]
fn $test_name() {
let input = format!("{} {}", $fn, $input);
assert_evals_to!(&input, $output, $typ)
@ -2468,25 +2282,31 @@ macro_rules! num_conversion_tests {
num_conversion_tests! {
"Num.toI8", i8, (
to_i8_same_width, "15u8", 15, ["gen-wasm"]
to_i8_truncate, "115i32", 115, ["gen-wasm"]
to_i8_truncate_wraps, "500i32", -12, ["gen-wasm"]
to_i8_same_width, "15u8", 15, ["gen-wasm", "gen-dev"]
to_i8_truncate, "115i32", 115, ["gen-wasm", "gen-dev"]
to_i8_truncate_wraps, "500i32", -12, ["gen-wasm", "gen-dev"]
)
"Num.toI16", i16, (
to_i16_same_width, "15u16", 15, ["gen-wasm"]
to_i16_extend, "15i8", 15, ["gen-wasm"]
to_i16_truncate, "115i32", 115, ["gen-wasm"]
to_i16_truncate_wraps, "60000i32", -5536, ["gen-wasm"]
to_i16_same_width, "15u16", 15, ["gen-wasm", "gen-dev"]
to_i16_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_i16_sign_extend_i8, "-15i8", -15, ["gen-wasm", "gen-dev"]
to_i16_truncate, "115i32", 115, ["gen-wasm", "gen-dev"]
to_i16_truncate_wraps, "60000i32", -5536, ["gen-wasm", "gen-dev"]
)
"Num.toI32", i32, (
to_i32_same_width, "15u32", 15, ["gen-wasm"]
to_i32_extend, "15i8", 15, ["gen-wasm"]
to_i32_truncate, "115i64", 115, ["gen-wasm"]
to_i32_truncate_wraps, "5000000000i64", 705032704, ["gen-wasm"]
to_i32_same_width, "15u32", 15, ["gen-wasm", "gen-dev"]
to_i32_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_i32_sign_extend_i8, "-15i8", -15, ["gen-wasm", "gen-dev"]
to_i32_sign_extend_i16, "-15i16", -15, ["gen-wasm", "gen-dev"]
to_i32_truncate, "115i64", 115, ["gen-wasm", "gen-dev"]
to_i32_truncate_wraps, "5000000000i64", 705032704, ["gen-wasm", "gen-dev"]
)
"Num.toI64", i64, (
to_i64_same_width, "15u64", 15, ["gen-wasm"]
to_i64_extend, "15i8", 15, ["gen-wasm"]
to_i64_same_width, "15u64", 15, ["gen-wasm", "gen-dev"]
to_i64_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_i64_sign_extend_i8, "-15i8", -15, ["gen-wasm", "gen-dev"]
to_i64_sign_extend_i16, "-15i16", -15, ["gen-wasm", "gen-dev"]
to_i64_sign_extend_i32, "-15i32", -15, ["gen-wasm", "gen-dev"]
to_i64_truncate, "115i128", 115
to_i64_truncate_wraps, "10_000_000_000_000_000_000i128", -8446744073709551616
)
@ -2495,25 +2315,25 @@ num_conversion_tests! {
to_i128_extend, "15i8", 15
)
"Num.toU8", u8, (
to_u8_same_width, "15i8", 15, ["gen-wasm"]
to_u8_truncate, "115i32", 115, ["gen-wasm"]
to_u8_truncate_wraps, "500i32", 244, ["gen-wasm"]
to_u8_same_width, "15i8", 15, ["gen-wasm", "gen-dev"]
to_u8_truncate, "115i32", 115, ["gen-wasm", "gen-dev"]
to_u8_truncate_wraps, "500i32", 244, ["gen-wasm", "gen-dev"]
)
"Num.toU16", u16, (
to_u16_same_width, "15i16", 15, ["gen-wasm"]
to_u16_extend, "15i8", 15, ["gen-wasm"]
to_u16_truncate, "115i32", 115, ["gen-wasm"]
to_u16_truncate_wraps, "600000000i32", 17920, ["gen-wasm"]
to_u16_same_width, "15i16", 15, ["gen-wasm", "gen-dev"]
to_u16_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_u16_truncate, "115i32", 115, ["gen-wasm", "gen-dev"]
to_u16_truncate_wraps, "600000000i32", 17920, ["gen-wasm", "gen-dev"]
)
"Num.toU32", u32, (
to_u32_same_width, "15i32", 15, ["gen-wasm"]
to_u32_extend, "15i8", 15, ["gen-wasm"]
to_u32_truncate, "115i64", 115, ["gen-wasm"]
to_u32_truncate_wraps, "5000000000000000000i64", 1156841472, ["gen-wasm"]
to_u32_same_width, "15i32", 15, ["gen-wasm", "gen-dev"]
to_u32_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_u32_truncate, "115i64", 115, ["gen-wasm", "gen-dev"]
to_u32_truncate_wraps, "5000000000000000000i64", 1156841472, ["gen-wasm", "gen-dev"]
)
"Num.toU64", u64, (
to_u64_same_width, "15i64", 15, ["gen-wasm"]
to_u64_extend, "15i8", 15, ["gen-wasm"]
to_u64_same_width, "15i64", 15, ["gen-wasm", "gen-dev"]
to_u64_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_u64_truncate, "115i128", 115
to_u64_truncate_wraps, "10_000_000_000_000_000_000_000i128", 1864712049423024128
)
@ -2522,8 +2342,8 @@ num_conversion_tests! {
to_u128_extend, "15i8", 15
)
"Num.toNat", usize, (
to_nat_same_width, "15i64", 15, ["gen-wasm"]
to_nat_extend, "15i8", 15, ["gen-wasm"]
to_nat_same_width, "15i64", 15, ["gen-wasm", "gen-dev"]
to_nat_extend, "15i8", 15, ["gen-wasm", "gen-dev"]
to_nat_truncate, "115i128", 115
)
"Num.toF32", f32, (
@ -2704,7 +2524,7 @@ to_int_checked_tests! {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn is_multiple_of_signed() {
// true
assert_evals_to!("Num.isMultipleOf 5 1", true, bool);
@ -3710,7 +3530,7 @@ fn to_float_f64() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
// https://github.com/roc-lang/roc/issues/2696
fn upcast_of_int_is_zext() {
assert_evals_to!(
@ -3922,7 +3742,7 @@ fn when_on_decimals() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn when_on_i128() {
assert_evals_to!(
indoc!(

View file

@ -3288,6 +3288,25 @@ fn box_and_unbox_big_string() {
)
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn box_and_unbox_nonrecursive_tag() {
assert_evals_to!(
indoc!(
r#"
result : Result U64 U64
result = Ok 42
result
|> Box.box
|> Box.unbox
"#
),
roc_std::RocResult::ok(42),
roc_std::RocResult<u64, u64>
)
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn box_num() {