Merge remote-tracking branch 'origin/trunk' into gen-dev/quicksort2

This commit is contained in:
Brendan Hansknecht 2022-02-27 00:26:04 -08:00
commit 7a608524ec
262 changed files with 11188 additions and 2721 deletions

View file

@ -28,7 +28,7 @@ fn roc_list_construction() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn empty_list_literal() {
assert_evals_to!("[]", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("[]", RocList::<i64>::from_slice(&[]), RocList<i64>);
}
#[test]
@ -136,7 +136,7 @@ fn bool_list_literal() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn variously_sized_list_literals() {
assert_evals_to!("[]", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("[]", RocList::<i64>::from_slice(&[]), RocList<i64>);
assert_evals_to!("[1]", RocList::from_slice(&[1]), RocList<i64>);
assert_evals_to!("[1, 2]", RocList::from_slice(&[1, 2]), RocList<i64>);
assert_evals_to!("[1, 2, 3]", RocList::from_slice(&[1, 2, 3]), RocList<i64>);
@ -177,12 +177,12 @@ fn list_take_first() {
);
assert_evals_to!(
"List.takeFirst [1, 2, 3] 0",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.takeFirst [] 1",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
@ -202,10 +202,14 @@ fn list_take_last() {
);
assert_evals_to!(
"List.takeLast [1, 2, 3] 0",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.takeLast [] 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!("List.takeLast [] 1", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.takeLast [1,2] 5",
RocList::from_slice(&[1, 2]),
@ -233,17 +237,17 @@ fn list_sublist() {
);
assert_evals_to!(
"List.sublist [1, 2, 3] { start: 3 , len: 2 } ",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.sublist [] { start: 1 , len: 1 } ",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.sublist [1, 2, 3] { start: 1 , len: 0 } ",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
@ -261,7 +265,7 @@ fn list_split() {
list = List.split [1, 2, 3] 0
list.before
"#,
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
@ -280,17 +284,26 @@ fn list_split() {
);
assert_evals_to!(
"List.split [1, 2, 3] 3",
(RocList::from_slice(&[1, 2, 3]), RocList::from_slice(&[]),),
(
RocList::from_slice(&[1, 2, 3]),
RocList::<i64>::from_slice(&[]),
),
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [1, 2, 3] 4",
(RocList::from_slice(&[1, 2, 3]), RocList::from_slice(&[]),),
(
RocList::from_slice(&[1, 2, 3]),
RocList::<i64>::from_slice(&[]),
),
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [] 1",
(RocList::from_slice(&[]), RocList::from_slice(&[]),),
(
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
),
(RocList<i64>, RocList<i64>,)
);
}
@ -302,8 +315,16 @@ fn list_drop() {
RocList::from_slice(&[3]),
RocList<i64>
);
assert_evals_to!("List.drop [] 1", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("List.drop [1,2] 5", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.drop [] 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.drop [1,2] 5",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
@ -319,8 +340,16 @@ fn list_drop_at() {
RocList::from_slice(&[0, 0, 0]),
RocList<i64>
);
assert_evals_to!("List.dropAt [] 1", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("List.dropAt [0] 0", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.dropAt [] 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropAt [0] 0",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
@ -341,7 +370,7 @@ fn list_intersperse() {
List.intersperse [] 1
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -380,7 +409,7 @@ fn list_drop_if_empty_list_of_int() {
List.dropIf empty \_ -> True
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -397,7 +426,7 @@ fn list_drop_if_empty_list() {
List.dropIf [] alwaysTrue
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -425,7 +454,7 @@ fn list_drop_if_always_true_for_non_empty_list() {
List.dropIf [1,2,3,4,5,6,7,8] (\_ -> True)
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -453,10 +482,7 @@ fn list_drop_if_string_eq() {
List.dropIf ["x", "y", "x"] (\s -> s == "y")
"#
),
RocList::from_slice(&[
RocStr::from_slice("x".as_bytes()),
RocStr::from_slice("x".as_bytes())
]),
RocList::from_slice(&[RocStr::from("x"), RocStr::from("x")]),
RocList<RocStr>
);
}
@ -469,8 +495,16 @@ fn list_drop_last() {
RocList::from_slice(&[1, 2]),
RocList<i64>
);
assert_evals_to!("List.dropLast []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("List.dropLast [0]", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.dropLast []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropLast [0]",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
@ -503,14 +537,26 @@ fn list_drop_first() {
RocList::from_slice(&[2, 3]),
RocList<i64>
);
assert_evals_to!("List.dropFirst []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("List.dropFirst [0]", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.dropFirst []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropFirst [0]",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_swap() {
assert_evals_to!("List.swap [] 0 1", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.swap [] 0 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.swap [ 0 ] 1 2",
RocList::from_slice(&[0]),
@ -621,7 +667,7 @@ fn list_prepend() {
List.prepend init "bar"
"#
),
RocList::from_slice(&[RocStr::from_slice(b"bar"), RocStr::from_slice(b"foo"),]),
RocList::from_slice(&[RocStr::from("bar"), RocStr::from("foo"),]),
RocList<RocStr>
);
}
@ -783,7 +829,7 @@ fn list_keep_if_empty_list_of_int() {
List.keepIf empty \_ -> True
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -802,7 +848,7 @@ fn list_keep_if_empty_list() {
List.keepIf [] alwaysTrue
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -842,7 +888,7 @@ fn list_keep_if_always_false_for_non_empty_list() {
List.keepIf [1,2,3,4,5,6,7,8] alwaysFalse
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -874,10 +920,7 @@ fn list_keep_if_str_is_hello() {
List.keepIf ["x", "y", "x"] (\x -> x == "x")
"#
),
RocList::from_slice(&[
RocStr::from_slice("x".as_bytes()),
RocStr::from_slice("x".as_bytes())
]),
RocList::from_slice(&[RocStr::from("x"), RocStr::from("x")]),
RocList<RocStr>
);
}
@ -895,7 +938,7 @@ fn list_map_on_empty_list_with_int_layout() {
List.map empty (\x -> x)
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -1006,7 +1049,7 @@ fn list_map_all_inline() {
List.map [] (\x -> x > 0)
"#
),
RocList::from_slice(&[]),
RocList::<bool>::from_slice(&[]),
RocList<bool>
);
}
@ -1060,7 +1103,7 @@ fn list_map4_different_length() {
(\a, b, c, d -> Str.concat a (Str.concat b (Str.concat c d)))
"#
),
RocList::from_slice(&[RocStr::from_slice("hola".as_bytes()),]),
RocList::from_slice(&[RocStr::from("hola"),]),
RocList<RocStr>
);
}
@ -1092,7 +1135,7 @@ fn list_map3_different_length() {
(\a, b, c -> Str.concat a (Str.concat b c))
"#
),
RocList::from_slice(&[RocStr::from_slice("abc".as_bytes()),]),
RocList::from_slice(&[RocStr::from("abc"),]),
RocList<RocStr>
);
}
@ -1124,7 +1167,7 @@ fn list_map2_different_lengths() {
(\a, b -> Str.concat a b)
"#
),
RocList::from_slice(&[RocStr::from_slice("ab".as_bytes()),]),
RocList::from_slice(&[RocStr::from("ab"),]),
RocList<RocStr>
);
}
@ -1132,7 +1175,11 @@ fn list_map2_different_lengths() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_join_empty_list() {
assert_evals_to!("List.join []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.join []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
@ -1214,7 +1261,7 @@ fn list_join_defined_empty_list() {
fn list_join_all_empty_lists() {
assert_evals_to!(
"List.join [ [], [], [] ]",
RocList::from_slice(&[]),
RocList::<f64>::from_slice(&[]),
RocList<f64>
);
}
@ -1252,7 +1299,7 @@ fn list_repeat() {
assert_evals_to!(
"List.repeat [] 2",
RocList::from_slice(&[RocList::default(), RocList::default()]),
RocList::from_slice(&[RocList::<i64>::default(), RocList::default()]),
RocList<RocList<i64>>
);
@ -1266,7 +1313,7 @@ fn list_repeat() {
List.repeat noStrs 2
"#
),
RocList::from_slice(&[RocList::default(), RocList::default()]),
RocList::from_slice(&[RocList::<i64>::default(), RocList::default()]),
RocList<RocList<i64>>
);
@ -1306,7 +1353,7 @@ fn list_reverse_empty_list_of_int() {
List.reverse emptyList
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -1314,7 +1361,11 @@ fn list_reverse_empty_list_of_int() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_reverse_empty_list() {
assert_evals_to!("List.reverse []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.reverse []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
@ -1334,7 +1385,7 @@ fn list_concat() {
List.concat firstList secondList
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -1342,7 +1393,11 @@ fn list_concat() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_concat_two_empty_lists() {
assert_evals_to!("List.concat [] []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.concat [] []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
@ -1362,7 +1417,7 @@ fn list_concat_two_empty_lists_of_int() {
List.concat firstList secondList
"#
),
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
@ -2392,7 +2447,11 @@ fn cleanup_because_exception() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_range() {
assert_evals_to!("List.range 0 -1", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.range 0 -1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!("List.range 0 0", RocList::from_slice(&[0]), RocList<i64>);
assert_evals_to!(
"List.range 0 5",
@ -2406,7 +2465,7 @@ fn list_range() {
fn list_sort_with() {
assert_evals_to!(
"List.sortWith [] Num.compare",
RocList::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
@ -2424,7 +2483,11 @@ fn list_sort_with() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_sort_asc() {
assert_evals_to!("List.sortAsc []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.sortAsc []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.sortAsc [ 4,3,2,1 ]",
RocList::from_slice(&[1, 2, 3, 4]),
@ -2435,7 +2498,11 @@ fn list_sort_asc() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_sort_desc() {
assert_evals_to!("List.sortDesc []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!(
"List.sortDesc []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.sortDesc [ 1,2,3,4 ]",
RocList::from_slice(&[4, 3, 2, 1]),
@ -2552,7 +2619,7 @@ fn empty_list_of_function_type() {
Err _ -> "bad!"
"#
),
RocStr::from_slice(b"bar"),
RocStr::from("bar"),
RocStr
);
}
@ -2567,11 +2634,11 @@ fn list_join_map() {
"#
),
RocList::from_slice(&[
RocStr::from_slice("guava".as_bytes()),
RocStr::from_slice("apple".as_bytes()),
RocStr::from_slice("pear".as_bytes()),
RocStr::from_slice("bailey".as_bytes()),
RocStr::from_slice("cyrus".as_bytes()),
RocStr::from("guava"),
RocStr::from("apple"),
RocStr::from("pear"),
RocStr::from("bailey"),
RocStr::from("cyrus"),
]),
RocList<RocStr>
)
@ -2602,7 +2669,7 @@ fn list_find() {
Err _ -> "not found"
"#
),
RocStr::from_slice(b"bc"),
RocStr::from("bc"),
RocStr
);
}
@ -2618,7 +2685,7 @@ fn list_find_not_found() {
Err _ -> "not found"
"#
),
RocStr::from_slice(b"not found"),
RocStr::from("not found"),
RocStr
);
}
@ -2634,7 +2701,7 @@ fn list_find_empty_typed_list() {
Err _ -> "not found"
"#
),
RocStr::from_slice(b"not found"),
RocStr::from("not found"),
RocStr
);
}

View file

@ -357,6 +357,66 @@ fn u8_hex_int_alias() {
);
}
#[test]
fn character_literal() {
assert_evals_to!(
indoc!(
r#"
x = 'A'
x
"#
),
65,
u32
);
}
#[test]
fn character_literal_back_slash() {
assert_evals_to!(
indoc!(
r#"
x = '\\'
x
"#
),
92,
u32
);
}
#[test]
fn character_literal_single_quote() {
assert_evals_to!(
indoc!(
r#"
x = '\''
x
"#
),
39,
u32
);
}
#[test]
fn character_literal_new_line() {
assert_evals_to!(
indoc!(
r#"
x = '\n'
x
"#
),
10,
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn dec_float_alias() {
@ -2053,6 +2113,207 @@ fn max_u8() {
);
}
macro_rules! to_int_tests {
($($fn:expr, $typ:ty, ($($test_name:ident, $input:expr, $output:expr $(, [ $($support_gen:literal),* ])? )*))*) => {$($(
#[test]
#[cfg(any(feature = "gen-llvm", $($(feature = $support_gen)*)?))]
fn $test_name() {
let input = format!("{} {}", $fn, $input);
assert_evals_to!(&input, $output, $typ)
}
)*)*}
}
to_int_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"]
)
"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"]
)
"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"]
)
"Num.toI64", i64, (
to_i64_same_width, "15u64", 15, ["gen-wasm"]
to_i64_extend, "15i8", 15, ["gen-wasm"]
to_i64_truncate, "115i128", 115
to_i64_truncate_wraps, "10_000_000_000_000_000_000i128", -8446744073709551616
)
"Num.toI128", i128, (
to_i128_same_width, "15u128", 15
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"]
)
"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"]
)
"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"]
)
"Num.toU64", u64, (
to_u64_same_width, "15i64", 15, ["gen-wasm"]
to_u64_extend, "15i8", 15, ["gen-wasm"]
to_u64_truncate, "115i128", 115
to_u64_truncate_wraps, "10_000_000_000_000_000_000_000i128", 1864712049423024128
)
"Num.toU128", u128, (
to_u128_same_width, "15i128", 15
to_u128_extend, "15i8", 15
)
}
macro_rules! to_int_checked_tests {
($($fn:expr, $typ:ty, ($($test_name:ident, $input:expr, $output:expr)*))*) => {$($(
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn $test_name() {
let sentinel = 23;
// Some n = Ok n, None = OutOfBounds
let expected = match $output.into() {
None => sentinel,
Some(n) => {
assert_ne!(n, sentinel);
n
}
};
let input = format!("Result.withDefault ({} {}) {}", $fn, $input, sentinel);
assert_evals_to!(&input, expected, $typ)
}
)*)*}
}
to_int_checked_tests! {
"Num.toI8Checked", i8, (
to_i8_checked_same, "15i8", 15
to_i8_checked_same_width_unsigned_fits, "15u8", 15
to_i8_checked_same_width_unsigned_oob, "128u8", None
to_i8_checked_larger_width_signed_fits_pos, "15i16", 15
to_i8_checked_larger_width_signed_oob_pos, "128i16", None
to_i8_checked_larger_width_signed_fits_neg, "-15i16", -15
to_i8_checked_larger_width_signed_oob_neg, "-129i16", None
to_i8_checked_larger_width_unsigned_fits_pos, "15u16", 15
to_i8_checked_larger_width_unsigned_oob_pos, "128u16", None
)
"Num.toI16Checked", i16, (
to_i16_checked_smaller_width_pos, "15i8", 15
to_i16_checked_smaller_width_neg, "-15i8", -15
to_i16_checked_same, "15i16", 15
to_i16_checked_same_width_unsigned_fits, "15u16", 15
to_i16_checked_same_width_unsigned_oob, "32768u16", None
to_i16_checked_larger_width_signed_fits_pos, "15i32", 15
to_i16_checked_larger_width_signed_oob_pos, "32768i32", None
to_i16_checked_larger_width_signed_fits_neg, "-15i32", -15
to_i16_checked_larger_width_signed_oob_neg, "-32769i32", None
to_i16_checked_larger_width_unsigned_fits_pos, "15u32", 15
to_i16_checked_larger_width_unsigned_oob_pos, "32768u32", None
)
"Num.toI32Checked", i32, (
to_i32_checked_smaller_width_pos, "15i8", 15
to_i32_checked_smaller_width_neg, "-15i8", -15
to_i32_checked_same, "15i32", 15
to_i32_checked_same_width_unsigned_fits, "15u32", 15
to_i32_checked_same_width_unsigned_oob, "2147483648u32", None
to_i32_checked_larger_width_signed_fits_pos, "15i64", 15
to_i32_checked_larger_width_signed_oob_pos, "2147483648i64", None
to_i32_checked_larger_width_signed_fits_neg, "-15i64", -15
to_i32_checked_larger_width_signed_oob_neg, "-2147483649i64", None
to_i32_checked_larger_width_unsigned_fits_pos, "15u64", 15
to_i32_checked_larger_width_unsigned_oob_pos, "2147483648u64", None
)
"Num.toI64Checked", i64, (
to_i64_checked_smaller_width_pos, "15i8", 15
to_i64_checked_smaller_width_neg, "-15i8", -15
to_i64_checked_same, "15i64", 15
to_i64_checked_same_width_unsigned_fits, "15u64", 15
to_i64_checked_same_width_unsigned_oob, "9223372036854775808u64", None
to_i64_checked_larger_width_signed_fits_pos, "15i128", 15
to_i64_checked_larger_width_signed_oob_pos, "9223372036854775808i128", None
to_i64_checked_larger_width_signed_fits_neg, "-15i128", -15
to_i64_checked_larger_width_signed_oob_neg, "-9223372036854775809i128", None
to_i64_checked_larger_width_unsigned_fits_pos, "15u128", 15
to_i64_checked_larger_width_unsigned_oob_pos, "9223372036854775808u128", None
)
"Num.toI128Checked", i128, (
to_i128_checked_smaller_width_pos, "15i8", 15
to_i128_checked_smaller_width_neg, "-15i8", -15
to_i128_checked_same, "15i128", 15
to_i128_checked_same_width_unsigned_fits, "15u128", 15
to_i128_checked_same_width_unsigned_oob, "170141183460469231731687303715884105728u128", None
)
"Num.toU8Checked", u8, (
to_u8_checked_same, "15u8", 15
to_u8_checked_same_width_signed_fits, "15i8", 15
to_u8_checked_same_width_signed_oob, "-1i8", None
to_u8_checked_larger_width_signed_fits_pos, "15i16", 15
to_u8_checked_larger_width_signed_oob_pos, "256i16", None
to_u8_checked_larger_width_signed_oob_neg, "-1i16", None
to_u8_checked_larger_width_unsigned_fits_pos, "15u16", 15
to_u8_checked_larger_width_unsigned_oob_pos, "256u16", None
)
"Num.toU16Checked", u16, (
to_u16_checked_smaller_width_pos, "15i8", 15
to_u16_checked_smaller_width_neg_oob, "-15i8", None
to_u16_checked_same, "15u16", 15
to_u16_checked_same_width_signed_fits, "15i16", 15
to_u16_checked_same_width_signed_oob, "-1i16", None
to_u16_checked_larger_width_signed_fits_pos, "15i32", 15
to_u16_checked_larger_width_signed_oob_pos, "65536i32", None
to_u16_checked_larger_width_signed_oob_neg, "-1i32", None
to_u16_checked_larger_width_unsigned_fits_pos, "15u32", 15
to_u16_checked_larger_width_unsigned_oob_pos, "65536u32", None
)
"Num.toU32Checked", u32, (
to_u32_checked_smaller_width_pos, "15i8", 15
to_u32_checked_smaller_width_neg_oob, "-15i8", None
to_u32_checked_same, "15u32", 15
to_u32_checked_same_width_signed_fits, "15i32", 15
to_u32_checked_same_width_signed_oob, "-1i32", None
to_u32_checked_larger_width_signed_fits_pos, "15i64", 15
to_u32_checked_larger_width_signed_oob_pos, "4294967296i64", None
to_u32_checked_larger_width_signed_oob_neg, "-1i64", None
to_u32_checked_larger_width_unsigned_fits_pos, "15u64", 15
to_u32_checked_larger_width_unsigned_oob_pos, "4294967296u64", None
)
"Num.toU64Checked", u64, (
to_u64_checked_smaller_width_pos, "15i8", 15
to_u64_checked_smaller_width_neg_oob, "-15i8", None
to_u64_checked_same, "15u64", 15
to_u64_checked_same_width_signed_fits, "15i64", 15
to_u64_checked_same_width_signed_oob, "-1i64", None
to_u64_checked_larger_width_signed_fits_pos, "15i128", 15
to_u64_checked_larger_width_signed_oob_pos, "18446744073709551616i128", None
to_u64_checked_larger_width_signed_oob_neg, "-1i128", None
to_u64_checked_larger_width_unsigned_fits_pos, "15u128", 15
to_u64_checked_larger_width_unsigned_oob_pos, "18446744073709551616u128", None
)
"Num.toU128Checked", u128, (
to_u128_checked_smaller_width_pos, "15i8", 15
to_u128_checked_smaller_width_neg_oob, "-15i8", None
to_u128_checked_same, "15u128", 15
to_u128_checked_same_width_signed_fits, "15i128", 15
to_u128_checked_same_width_signed_oob, "-1i128", None
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn is_multiple_of() {
@ -2285,29 +2546,21 @@ fn when_on_i16() {
fn num_to_str() {
use roc_std::RocStr;
assert_evals_to!(
r#"Num.toStr 1234"#,
RocStr::from_slice("1234".as_bytes()),
RocStr
);
assert_evals_to!(r#"Num.toStr 0"#, RocStr::from_slice("0".as_bytes()), RocStr);
assert_evals_to!(
r#"Num.toStr -1"#,
RocStr::from_slice("-1".as_bytes()),
RocStr
);
assert_evals_to!(r#"Num.toStr 1234"#, RocStr::from("1234"), RocStr);
assert_evals_to!(r#"Num.toStr 0"#, RocStr::from("0"), RocStr);
assert_evals_to!(r#"Num.toStr -1"#, RocStr::from("-1"), RocStr);
let max = format!("{}", i64::MAX);
assert_evals_to!(
r#"Num.toStr Num.maxI64"#,
RocStr::from_slice(max.as_bytes()),
RocStr::from(max.as_str()),
RocStr
);
let min = format!("{}", i64::MIN);
assert_evals_to!(
r#"Num.toStr Num.minI64"#,
RocStr::from_slice(min.as_bytes()),
RocStr::from(min.as_str()),
RocStr
);
}

View file

@ -1468,7 +1468,7 @@ fn rbtree_insert() {
show (insert 0 {} Empty)
"#
),
RocStr::from_slice("Node".as_bytes()),
RocStr::from("Node"),
RocStr
);
}
@ -1535,7 +1535,7 @@ fn rbtree_layout_issue() {
main = show (balance Red zero zero Empty)
"#
),
RocStr::from_slice("Empty".as_bytes()),
RocStr::from("Empty"),
RocStr
);
}
@ -1589,7 +1589,7 @@ fn rbtree_balance_mono_problem() {
main = show (balance Red 0 0 Empty Empty)
"#
),
RocStr::from_slice("Empty".as_bytes()),
RocStr::from("Empty"),
RocStr
);
}
@ -2382,7 +2382,7 @@ fn build_then_apply_closure() {
(\_ -> x) {}
"#
),
RocStr::from_slice(b"long string that is malloced"),
RocStr::from("long string that is malloced"),
RocStr
);
}
@ -2556,7 +2556,7 @@ fn module_thunk_is_function() {
helper = Str.concat
"#
),
RocStr::from_slice(b"foobar"),
RocStr::from("foobar"),
RocStr
);
}
@ -2580,7 +2580,7 @@ fn hit_unresolved_type_variable() {
\input -> input
"#
),
RocStr::from_slice(b"B"),
RocStr::from("B"),
RocStr
);
}
@ -2648,7 +2648,7 @@ fn mirror_llvm_alignment_padding() {
"#
),
RocStr::from_slice(b"pass\npass"),
RocStr::from("pass\npass"),
RocStr
);
}
@ -2911,7 +2911,7 @@ fn mix_function_and_closure() {
(if 1 == 1 then foo else (bar "nope nope nope")) "hello world"
"#
),
RocStr::from_slice(b"hello world"),
RocStr::from("hello world"),
RocStr
);
}
@ -2936,7 +2936,7 @@ fn mix_function_and_closure_level_of_indirection() {
f "hello world"
"#
),
RocStr::from_slice(b"hello world"),
RocStr::from("hello world"),
RocStr
);
}
@ -3012,7 +3012,7 @@ fn do_pass_bool_byte_closure_layout() {
main = [test1, test2, test3, test4] |> Str.joinWith ", "
"#
),
RocStr::from_slice(b"PASS, PASS, PASS, PASS"),
RocStr::from("PASS, PASS, PASS, PASS"),
RocStr
);
}
@ -3037,7 +3037,7 @@ fn nested_rigid_list() {
_ -> "hello world"
"#
),
RocStr::from_slice(b"hello world"),
RocStr::from("hello world"),
RocStr
);
}
@ -3064,7 +3064,7 @@ fn nested_rigid_alias() {
_ -> "hello world"
"#
),
RocStr::from_slice(b"hello world"),
RocStr::from("hello world"),
RocStr
);
}
@ -3089,7 +3089,7 @@ fn nested_rigid_tag_union() {
_ -> "hello world"
"#
),
RocStr::from_slice(b"hello world"),
RocStr::from("hello world"),
RocStr
);
}
@ -3117,7 +3117,7 @@ fn call_that_needs_closure_parameter() {
runTest manyAuxTest
"#
),
RocStr::from_slice(b"FAIL"),
RocStr::from("FAIL"),
RocStr
);
}
@ -3138,7 +3138,7 @@ fn alias_defined_out_of_order() {
"#
),
RocStr::from_slice(b"foo"),
RocStr::from("foo"),
RocStr
);
}
@ -3184,7 +3184,7 @@ fn recursively_build_effect() {
e2 {}
"#
),
RocStr::from_slice(b"Hello, World!"),
RocStr::from("Hello, World!"),
RocStr
);
}

View file

@ -13,6 +13,9 @@ use crate::helpers::wasm::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
#[cfg(test)]
use roc_std::RocList;
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn basic_record() {
@ -1007,6 +1010,36 @@ fn both_have_unique_fields() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
// https://github.com/rtfeldman/roc/issues/2535
fn different_proc_types_specialized_to_same_layout() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [ nums ] to "./platform"
# Top-level values compile to procedure calls with no args
# alpha has the generic type { a: Num *, b: Num * }
# and gets specialized to two procedure calls below
alpha = { a: 1, b: 2 }
# The wider number always comes first in the layout,
# which makes the two specializations look very similar.
# Test that the compiler doesn't get them mixed up!
nums : List U8
nums =
[
alpha.a, # alpha specialized to layout { b: I64, a: U8 }
alpha.b, # alpha specialized to layout { a: I64, b: U8 }
]
"#
),
RocList::from_slice(&[1, 2]),
RocList<u8>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic(

View file

@ -252,7 +252,7 @@ fn roc_result_err() {
result
"#
),
RocResult::err(RocStr::from_slice(b"foo")),
RocResult::err(RocStr::from("foo")),
RocResult<i64, RocStr>
);
}

View file

@ -238,7 +238,7 @@ fn from_list() {
|> Set.toList
"#
),
RocList::default(),
RocList::<i64>::default(),
RocList<i64>
);
}
@ -254,7 +254,7 @@ fn from_list_void() {
|> Set.toList
"#
),
RocList::default(),
RocList::<i64>::default(),
RocList<i64>
);
}

View file

@ -94,7 +94,7 @@ fn str_split_str_concat_repeated() {
"#
),
RocStr::from_slice(b"JJJJJJJJJJJJJJJJJJJJJJJJJ"),
RocStr::from("JJJJJJJJJJJJJJJJJJJJJJJJJ"),
RocStr
);
}
@ -113,7 +113,7 @@ fn str_split_small_str_bigger_delimiter() {
_ -> ""
"#
),
RocStr::from_slice(b"JJJ"),
RocStr::from("JJJ"),
RocStr
);
}
@ -128,8 +128,8 @@ fn str_split_big_str_small_delimiter() {
"#
),
RocList::from_slice(&[
RocStr::from_slice(b"01234567789abcdefghi"),
RocStr::from_slice(b"01234567789abcdefghi")
RocStr::from("01234567789abcdefghi"),
RocStr::from("01234567789abcdefghi")
]),
RocList<RocStr>
);
@ -141,8 +141,8 @@ fn str_split_big_str_small_delimiter() {
"#
),
RocList::from_slice(&[
RocStr::from_slice(b"01234567789abcdefghi "),
RocStr::from_slice(b" 01234567789abcdefghi")
RocStr::from("01234567789abcdefghi "),
RocStr::from(" 01234567789abcdefghi")
]),
RocList<RocStr>
);
@ -157,11 +157,7 @@ fn str_split_small_str_small_delimiter() {
Str.split "J!J!J" "!"
"#
),
RocList::from_slice(&[
RocStr::from_slice(b"J"),
RocStr::from_slice(b"J"),
RocStr::from_slice(b"J")
]),
RocList::from_slice(&[RocStr::from("J"), RocStr::from("J"), RocStr::from("J")]),
RocList<RocStr>
);
}
@ -177,7 +173,7 @@ fn str_split_bigger_delimiter_big_strs() {
"than the delimiter which happens to be very very long"
"#
),
RocList::from_slice(&[RocStr::from_slice(b"string to split is shorter")]),
RocList::from_slice(&[RocStr::from("string to split is shorter")]),
RocList<RocStr>
);
}
@ -191,7 +187,7 @@ fn str_split_empty_strs() {
Str.split "" ""
"#
),
RocList::from_slice(&[RocStr::from_slice(b"")]),
RocList::from_slice(&[RocStr::from("")]),
RocList<RocStr>
);
}
@ -205,7 +201,7 @@ fn str_split_minimal_example() {
Str.split "a," ","
"#
),
RocList::from_slice(&[RocStr::from_slice(b"a"), RocStr::from_slice(b"")]),
RocList::from_slice(&[RocStr::from("a"), RocStr::from("")]),
RocList<RocStr>
)
}
@ -234,11 +230,7 @@ fn str_split_small_str_big_delimiter() {
"---- ---- ---- ---- ----"
"#
),
RocList::from_slice(&[
RocStr::from_slice(b"1"),
RocStr::from_slice(b"2"),
RocStr::from_slice(b"")
]),
RocList::from_slice(&[RocStr::from("1"), RocStr::from("2"), RocStr::from("")]),
RocList<RocStr>
);
}
@ -254,11 +246,7 @@ fn str_split_small_str_20_char_delimiter() {
"|-- -- -- -- -- -- |"
"#
),
RocList::from_slice(&[
RocStr::from_slice(b"3"),
RocStr::from_slice(b"4"),
RocStr::from_slice(b"")
]),
RocList::from_slice(&[RocStr::from("3"), RocStr::from("4"), RocStr::from("")]),
RocList<RocStr>
);
}
@ -274,7 +262,7 @@ fn str_concat_big_to_big() {
"Second string that is also fairly long. Two long strings test things that might not appear with short strings."
"#
),
RocStr::from_slice(b"First string that is fairly long. Longer strings make for different errors. Second string that is also fairly long. Two long strings test things that might not appear with short strings."),
RocStr::from("First string that is fairly long. Longer strings make for different errors. Second string that is also fairly long. Two long strings test things that might not appear with short strings."),
RocStr
);
}
@ -395,7 +383,7 @@ fn small_str_concat_empty_second_arg() {
fn small_str_concat_small_to_big() {
assert_evals_to!(
r#"Str.concat "abc" " this is longer than 15 chars""#,
RocStr::from_slice(b"abc this is longer than 15 chars"),
RocStr::from("abc this is longer than 15 chars"),
RocStr
);
}
@ -432,7 +420,7 @@ fn small_str_concat_small_to_small_staying_small() {
fn small_str_concat_small_to_small_overflow_to_big() {
assert_evals_to!(
r#"Str.concat "abcdefghijklm" "nopqrstuvwxyz""#,
RocStr::from_slice(b"abcdefghijklmnopqrstuvwxyz"),
RocStr::from("abcdefghijklmnopqrstuvwxyz"),
RocStr
);
}
@ -568,7 +556,7 @@ fn str_from_utf8_pass_single_ascii() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -584,7 +572,7 @@ fn str_from_utf8_pass_many_ascii() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("abc~".as_bytes()),
roc_std::RocStr::from("abc~"),
roc_std::RocStr
);
}
@ -600,7 +588,7 @@ fn str_from_utf8_pass_single_unicode() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("".as_bytes()),
roc_std::RocStr::from(""),
roc_std::RocStr
);
}
@ -616,7 +604,7 @@ fn str_from_utf8_pass_many_unicode() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("∆œ¬".as_bytes()),
roc_std::RocStr::from("∆œ¬"),
roc_std::RocStr
);
}
@ -632,7 +620,7 @@ fn str_from_utf8_pass_single_grapheme() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("💖".as_bytes()),
roc_std::RocStr::from("💖"),
roc_std::RocStr
);
}
@ -648,7 +636,7 @@ fn str_from_utf8_pass_many_grapheme() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("💖🤠🚀".as_bytes()),
roc_std::RocStr::from("💖🤠🚀"),
roc_std::RocStr
);
}
@ -664,7 +652,7 @@ fn str_from_utf8_pass_all() {
Err _ -> ""
"#
),
roc_std::RocStr::from_slice("💖b∆".as_bytes()),
roc_std::RocStr::from("💖b∆"),
roc_std::RocStr
);
}
@ -684,7 +672,7 @@ fn str_from_utf8_fail_invalid_start_byte() {
_ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -704,7 +692,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
_ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -724,7 +712,7 @@ fn str_from_utf8_fail_expected_continuation() {
_ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -744,7 +732,7 @@ fn str_from_utf8_fail_overlong_encoding() {
_ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -764,7 +752,7 @@ fn str_from_utf8_fail_codepoint_too_large() {
_ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -784,7 +772,7 @@ fn str_from_utf8_fail_surrogate_half() {
_ -> ""
"#
),
roc_std::RocStr::from_slice("a".as_bytes()),
roc_std::RocStr::from("a"),
roc_std::RocStr
);
}
@ -805,9 +793,9 @@ fn str_equality() {
#[test]
fn str_clone() {
use roc_std::RocStr;
let long = RocStr::from_slice("loremipsumdolarsitamet".as_bytes());
let short = RocStr::from_slice("x".as_bytes());
let empty = RocStr::from_slice("".as_bytes());
let long = RocStr::from("loremipsumdolarsitamet");
let short = RocStr::from("x");
let empty = RocStr::from("");
debug_assert_eq!(long.clone(), long);
debug_assert_eq!(short.clone(), short);
@ -840,7 +828,7 @@ fn nested_recursive_literal() {
printExpr expr
"#
),
RocStr::from_slice(b"Add (Add (Val 3) (Val 1)) (Add (Val 1) (Var 1))"),
RocStr::from("Add (Add (Val 3) (Val 1)) (Add (Val 1) (Var 1))"),
RocStr
);
}

View file

@ -1177,10 +1177,7 @@ fn applied_tag_function() {
x
"#
),
RocList::from_slice(&[
RocStr::from_slice("a".as_bytes()),
RocStr::from_slice("b".as_bytes())
]),
RocList::from_slice(&[RocStr::from("a"), RocStr::from("b")]),
RocList<RocStr>
);
}
@ -1197,10 +1194,7 @@ fn applied_tag_function_result() {
List.keepOks x (\y -> y)
"#
),
RocList::from_slice(&[
(RocStr::from_slice("a".as_bytes())),
(RocStr::from_slice("b".as_bytes()))
]),
RocList::from_slice(&[(RocStr::from("a")), (RocStr::from("b"))]),
RocList<RocStr>
);
}
@ -1297,7 +1291,7 @@ fn monomorphized_applied_tag() {
f a
"#
),
RocStr::from_slice(b"abc"),
RocStr::from("abc"),
RocStr
)
}

View file

@ -1,5 +1,5 @@
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
use roc_std::{RocDec, RocList, RocOrder, RocStr};
use roc_std::{ReferenceCount, RocDec, RocList, RocOrder, RocStr};
pub trait FromWasmerMemory: Wasm32Sized {
fn decode(memory: &wasmer::Memory, offset: u32) -> Self;
@ -61,19 +61,19 @@ impl FromWasmerMemory for RocStr {
let actual_length = (last_byte ^ 0b1000_0000) as usize;
let slice = &bytes.to_ne_bytes()[..actual_length as usize];
RocStr::from_slice(slice)
unsafe { 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)
unsafe { RocStr::from_slice(wasm_slice) }
}
}
}
impl<T: FromWasmerMemory + Clone> FromWasmerMemory for RocList<T> {
impl<T: FromWasmerMemory + Clone + ReferenceCount> FromWasmerMemory for RocList<T> {
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let bytes = <u64 as FromWasmerMemory>::decode(memory, offset);

View file

@ -489,10 +489,7 @@ where
match test_wrapper.call(&[]) {
Err(e) => Err(format!("call to `test_wrapper`: {:?}", e)),
Ok(result) => {
let address = match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
};
let address = result[0].unwrap_i32();
let output = <T as crate::helpers::llvm::FromWasmerMemory>::decode(
memory,

View file

@ -194,10 +194,7 @@ where
match test_wrapper.call(&[]) {
Err(e) => Err(format!("{:?}", e)),
Ok(result) => {
let address = match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
};
let address = result[0].unwrap_i32();
if false {
println!("test_wrapper returned 0x{:x}", address);
@ -239,10 +236,7 @@ where
let init_result = init_refcount_test.call(&[wasmer::Value::I32(expected_len)]);
let refcount_vector_addr = match init_result {
Err(e) => return Err(format!("{:?}", e)),
Ok(result) => match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
},
Ok(result) => result[0].unwrap_i32(),
};
// Run the test

View file

@ -320,7 +320,7 @@ fn small_str_zeroed_literal() {
fn long_str_literal() {
assert_evals_to!(
"\"0123456789 123456789 123456789\"",
RocStr::from_slice(b"0123456789 123456789 123456789"),
RocStr::from("0123456789 123456789 123456789"),
RocStr
);
}
@ -347,7 +347,7 @@ fn small_str_concat_empty_second_arg() {
fn small_str_concat_small_to_big() {
assert_evals_to!(
r#"Str.concat "abc" " this is longer than 7 chars""#,
RocStr::from_slice(b"abc this is longer than 7 chars"),
RocStr::from("abc this is longer than 7 chars"),
RocStr
);
}
@ -365,7 +365,7 @@ fn small_str_concat_small_to_small_staying_small() {
fn small_str_concat_small_to_small_overflow_to_big() {
assert_evals_to!(
r#"Str.concat "abcdefg" "hijklmn""#,
RocStr::from_slice(b"abcdefghijklmn"),
RocStr::from("abcdefghijklmn"),
RocStr
);
}