mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Merge pull request #6644 from roc-lang/rust-1-76-0-upgrade
Rust 1.76.0 upgrade
This commit is contained in:
commit
f7011c8e33
30 changed files with 266 additions and 188 deletions
|
@ -526,7 +526,7 @@ pub fn rebuild_host(
|
|||
// on windows, we need the nightly toolchain so we can use `-Z export-executable-symbols`
|
||||
// using `+nightly` only works when running cargo through rustup
|
||||
let mut cmd = rustup();
|
||||
cmd.args(["run", "nightly-2023-08-20", "cargo"]);
|
||||
cmd.args(["run", "nightly-2023-12-21", "cargo"]);
|
||||
|
||||
cmd
|
||||
} else {
|
||||
|
|
|
@ -978,7 +978,7 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
// there are opaques that implement an ability using a value symbol). But, value symbols might
|
||||
// shadow symbols defined in a local ability def.
|
||||
|
||||
for (_, either_index) in loc_defs.tags.iter().enumerate() {
|
||||
for either_index in loc_defs.tags.iter() {
|
||||
if let Ok(type_index) = either_index.split() {
|
||||
let type_def = &loc_defs.type_defs[type_index.index()];
|
||||
let pending_type_def = to_pending_type_def(env, type_def, scope, pattern_type);
|
||||
|
|
|
@ -225,7 +225,7 @@ pub fn unwrap_suffixed_expression_apply_help<'a>(
|
|||
|
||||
// Any suffixed arguments will be innermost, therefore we unwrap those first
|
||||
let local_args = arena.alloc_slice_copy(apply_args);
|
||||
for (_, arg) in local_args.iter_mut().enumerate() {
|
||||
for arg in local_args.iter_mut() {
|
||||
match unwrap_suffixed_expression(arena, arg, maybe_def_pat) {
|
||||
Ok(new_arg) => {
|
||||
*arg = new_arg;
|
||||
|
|
|
@ -2161,13 +2161,13 @@ impl<'a> LowLevelCall<'a> {
|
|||
|
||||
// Empty record is always equal to empty record.
|
||||
// There are no runtime arguments to check, so just emit true or false.
|
||||
LayoutRepr::Struct(field_layouts) if field_layouts.is_empty() => {
|
||||
LayoutRepr::Struct([]) => {
|
||||
backend.code_builder.i32_const(!invert_result as i32);
|
||||
}
|
||||
|
||||
// Void is always equal to void. This is the type for the contents of the empty list in `[] == []`
|
||||
// This instruction will never execute, but we need an i32 for module validation
|
||||
LayoutRepr::Union(UnionLayout::NonRecursive(tags)) if tags.is_empty() => {
|
||||
LayoutRepr::Union(UnionLayout::NonRecursive([])) => {
|
||||
backend.code_builder.i32_const(!invert_result as i32);
|
||||
}
|
||||
|
||||
|
|
|
@ -452,7 +452,7 @@ enum Match {
|
|||
}
|
||||
|
||||
fn check_for_match(branches: &[Branch]) -> Match {
|
||||
match branches.get(0) {
|
||||
match branches.first() {
|
||||
Some(Branch {
|
||||
goal,
|
||||
patterns,
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
use std::{
|
||||
cell::RefCell,
|
||||
hash::{BuildHasher, Hasher},
|
||||
marker::PhantomData,
|
||||
sync::Arc,
|
||||
};
|
||||
use std::{cell::RefCell, hash::BuildHasher, marker::PhantomData, sync::Arc};
|
||||
|
||||
use bumpalo::Bump;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
|
@ -591,9 +586,8 @@ struct LockedGlobalInterner<'a, 'r> {
|
|||
///
|
||||
/// This uses the [default_hasher], so interner maps should also rely on [default_hasher].
|
||||
fn hash<V: std::hash::Hash>(val: V) -> u64 {
|
||||
let mut state = roc_collections::all::BuildHasher::default().build_hasher();
|
||||
val.hash(&mut state);
|
||||
state.finish()
|
||||
let hasher = roc_collections::all::BuildHasher::default();
|
||||
hasher.hash_one(&val)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
|
@ -322,43 +322,6 @@ pub fn fast_eat_until_control_character(bytes: &[u8]) -> usize {
|
|||
simple_eat_until_control_character(&bytes[i..]) + i
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_eat_whitespace_simple() {
|
||||
let bytes = &[0, 0, 0, 0, 0, 0, 0, 0];
|
||||
assert_eq!(simple_eat_whitespace(bytes), fast_eat_whitespace(bytes));
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn test_eat_whitespace(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
|
||||
prop_assert_eq!(simple_eat_whitespace(&bytes), fast_eat_whitespace(&bytes));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eat_until_control_character_simple() {
|
||||
let bytes = &[32, 0, 0, 0, 0, 0, 0, 0];
|
||||
assert_eq!(
|
||||
simple_eat_until_control_character(bytes),
|
||||
fast_eat_until_control_character(bytes)
|
||||
);
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn test_eat_until_control_character(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
|
||||
prop_assert_eq!(
|
||||
simple_eat_until_control_character(&bytes),
|
||||
fast_eat_until_control_character(&bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn space0_e<'a, E>(
|
||||
indent_problem: fn(Position) -> E,
|
||||
) -> impl Parser<'a, &'a [CommentOrNewline<'a>], E>
|
||||
|
@ -514,3 +477,40 @@ where
|
|||
|
||||
Ok((progress, state))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_eat_whitespace_simple() {
|
||||
let bytes = &[0, 0, 0, 0, 0, 0, 0, 0];
|
||||
assert_eq!(simple_eat_whitespace(bytes), fast_eat_whitespace(bytes));
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn test_eat_whitespace(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
|
||||
prop_assert_eq!(simple_eat_whitespace(&bytes), fast_eat_whitespace(&bytes));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eat_until_control_character_simple() {
|
||||
let bytes = &[32, 0, 0, 0, 0, 0, 0, 0];
|
||||
assert_eq!(
|
||||
simple_eat_until_control_character(bytes),
|
||||
fast_eat_until_control_character(bytes)
|
||||
);
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn test_eat_until_control_character(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
|
||||
prop_assert_eq!(
|
||||
simple_eat_until_control_character(&bytes),
|
||||
fast_eat_until_control_character(&bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,17 +291,19 @@ fn crash_kw<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
|
|||
fn loc_possibly_negative_or_negated_term<'a>(
|
||||
options: ExprParseOptions,
|
||||
) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
let parse_unary_negate = move |arena, state: State<'a>, min_indent: u32| {
|
||||
let initial = state.clone();
|
||||
|
||||
let (_, (loc_op, loc_expr), state) =
|
||||
and!(loc!(unary_negate()), loc_term(options)).parse(arena, state, min_indent)?;
|
||||
|
||||
let loc_expr = numeric_negate_expression(arena, initial, loc_op, loc_expr, &[]);
|
||||
|
||||
Ok((MadeProgress, loc_expr, state))
|
||||
};
|
||||
|
||||
one_of![
|
||||
|arena, state: State<'a>, min_indent: u32| {
|
||||
let initial = state.clone();
|
||||
|
||||
let (_, (loc_op, loc_expr), state) =
|
||||
and!(loc!(unary_negate()), loc_term(options)).parse(arena, state, min_indent)?;
|
||||
|
||||
let loc_expr = numeric_negate_expression(arena, initial, loc_op, loc_expr, &[]);
|
||||
|
||||
Ok((MadeProgress, loc_expr, state))
|
||||
},
|
||||
parse_unary_negate,
|
||||
// this will parse negative numbers, which the unary negate thing up top doesn't (for now)
|
||||
loc!(specialize_err(EExpr::Number, number_literal_help())),
|
||||
loc!(map_with_arena!(
|
||||
|
|
|
@ -958,7 +958,7 @@ fn sort_and_deduplicate<T>(tag_vars: &mut bumpalo::collections::Vec<(TagName, T)
|
|||
fn find_tag_name_run(slice: &[TagName], subs: &mut Subs) -> Option<SubsSlice<TagName>> {
|
||||
use std::cmp::Ordering;
|
||||
|
||||
let tag_name = slice.get(0)?;
|
||||
let tag_name = slice.first()?;
|
||||
|
||||
let mut result = None;
|
||||
|
||||
|
|
|
@ -1056,7 +1056,7 @@ mod decode_immediate {
|
|||
use indoc::indoc;
|
||||
|
||||
#[cfg(all(test, feature = "gen-llvm"))]
|
||||
use roc_std::RocStr;
|
||||
use roc_std::{RocStr, I128, U128};
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-llvm")]
|
||||
|
@ -1121,7 +1121,7 @@ mod decode_immediate {
|
|||
}
|
||||
|
||||
macro_rules! num_immediate {
|
||||
($($num:expr, $typ:ident)*) => {$(
|
||||
($($num:expr, $typ:ident, $expected_type:ident)*) => {$(
|
||||
#[test]
|
||||
#[cfg(feature = "gen-llvm")]
|
||||
fn $typ() {
|
||||
|
@ -1137,25 +1137,25 @@ mod decode_immediate {
|
|||
"#
|
||||
), $num, stringify!($typ), stringify!($typ)),
|
||||
$num,
|
||||
$typ
|
||||
$expected_type
|
||||
)
|
||||
}
|
||||
)*}
|
||||
}
|
||||
|
||||
num_immediate! {
|
||||
17, i8
|
||||
17, i16
|
||||
17, i32
|
||||
17, i64
|
||||
17, i128
|
||||
17, u8
|
||||
17, u16
|
||||
17, u32
|
||||
17, u64
|
||||
17, u128
|
||||
17.23, f32
|
||||
17.23, f64
|
||||
17, i8, i8
|
||||
17, i16, i16
|
||||
17, i32, i32
|
||||
17, i64, i64
|
||||
I128::from(17), i128, I128
|
||||
17, u8, u8
|
||||
17, u16, u16
|
||||
17, u32, u32
|
||||
17, u64, u64
|
||||
U128::from(17), u128, U128
|
||||
17.23, f32, f32
|
||||
17.23, f64, f64
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::helpers::wasm::assert_evals_to;
|
|||
#[allow(unused_imports)]
|
||||
use indoc::indoc;
|
||||
#[allow(unused_imports)]
|
||||
use roc_std::{RocDec, RocOrder, RocResult};
|
||||
use roc_std::{RocDec, RocOrder, RocResult, I128, U128};
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
|
||||
|
@ -42,8 +42,8 @@ fn i128_signed_int_alias() {
|
|||
i
|
||||
"
|
||||
),
|
||||
128,
|
||||
i128
|
||||
I128::from(128),
|
||||
I128
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
@ -126,8 +126,8 @@ fn i128_hex_int_alias() {
|
|||
f
|
||||
"
|
||||
),
|
||||
0x123,
|
||||
i128
|
||||
I128::from(0x123),
|
||||
I128
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
@ -207,8 +207,8 @@ fn u128_signed_int_alias() {
|
|||
i
|
||||
"
|
||||
),
|
||||
128,
|
||||
u128
|
||||
U128::from(128),
|
||||
U128
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
@ -288,8 +288,8 @@ fn u128_hex_int_alias() {
|
|||
f
|
||||
"
|
||||
),
|
||||
0x123,
|
||||
i128
|
||||
I128::from(0x123),
|
||||
I128
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
@ -429,8 +429,8 @@ fn dec_float_alias() {
|
|||
x
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("2.1"),
|
||||
i128
|
||||
RocDec::from_str("2.1").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -568,14 +568,14 @@ fn various_sized_abs() {
|
|||
assert_evals_to!("Num.abs -6i32", 6, i32);
|
||||
assert_evals_to!("Num.abs -6i64", 6, i64);
|
||||
if !cfg!(feature = "gen-wasm") {
|
||||
assert_evals_to!("Num.abs -6i128", 6, i128);
|
||||
assert_evals_to!("Num.abs -6i128", I128::from(6), I128);
|
||||
}
|
||||
assert_evals_to!("Num.abs 6u8", 6, u8);
|
||||
assert_evals_to!("Num.abs 6u16", 6, u16);
|
||||
assert_evals_to!("Num.abs 6u32", 6, u32);
|
||||
assert_evals_to!("Num.abs 6u64", 6, u64);
|
||||
if !cfg!(feature = "gen-wasm") {
|
||||
assert_evals_to!("Num.abs 6u128", 6, u128);
|
||||
assert_evals_to!("Num.abs 6u128", U128::from(6), U128);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -652,8 +652,8 @@ fn gen_add_dec() {
|
|||
z
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("5.2"),
|
||||
i128
|
||||
RocDec::from_str("5.2").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
@ -742,8 +742,8 @@ fn gen_div_dec() {
|
|||
x / y
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("3.333333333333333333"),
|
||||
i128
|
||||
RocDec::from_str("3.333333333333333333").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -764,8 +764,8 @@ fn gen_div_checked_dec() {
|
|||
Err _ -> -1
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("3.333333333333333333"),
|
||||
i128
|
||||
RocDec::from_str("3.333333333333333333").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
@ -785,8 +785,8 @@ fn gen_div_checked_by_zero_dec() {
|
|||
Err _ -> -1
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("-1"),
|
||||
i128
|
||||
RocDec::from_str("-1").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -794,7 +794,7 @@ fn gen_div_checked_by_zero_dec() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
#[should_panic(expected = r#"Roc failed with message: "Decimal division by 0!"#)]
|
||||
fn gen_div_dec_by_zero() {
|
||||
assert_evals_to!("1dec / 0", RocDec::from_str_to_i128_unsafe("-1"), i128);
|
||||
assert_evals_to!("1dec / 0", RocDec::from_str("-1").unwrap(), RocDec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1030,8 +1030,8 @@ fn gen_sub_dec() {
|
|||
(x - y) - z
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("-3.9"),
|
||||
i128
|
||||
RocDec::from_str("-3.9").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1053,8 +1053,8 @@ fn gen_mul_dec() {
|
|||
x * y * z
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("48.0"),
|
||||
i128
|
||||
RocDec::from_str("48.0").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2064,7 +2064,7 @@ fn int_mul_wrap_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);
|
||||
assert_evals_to!("Num.mulWrap Num.maxI128 2", I128::from(-2), I128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2195,13 +2195,13 @@ fn shift_right_cast_i8() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn min_i128() {
|
||||
assert_evals_to!("Num.minI128", i128::MIN, i128);
|
||||
assert_evals_to!("Num.minI128", I128::from(i128::MIN), I128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn max_i128() {
|
||||
assert_evals_to!("Num.maxI128", i128::MAX, i128);
|
||||
assert_evals_to!("Num.maxI128", I128::from(i128::MAX), I128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2498,13 +2498,6 @@ to_int_checked_tests! {
|
|||
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
|
||||
|
@ -2551,13 +2544,81 @@ to_int_checked_tests! {
|
|||
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
|
||||
)
|
||||
}
|
||||
|
||||
fn wrap_with_default(test_roc_code: &str) -> String {
|
||||
format!("Result.withDefault ({}) 123454321", test_roc_code)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_i128_checked_smaller_width_pos() {
|
||||
let test_roc_code = wrap_with_default("Num.toI128Checked 15i8");
|
||||
assert_evals_to!(&test_roc_code, I128::from(15), I128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_i128_checked_smaller_width_neg() {
|
||||
let test_roc_code = wrap_with_default("Num.toI128Checked -15i8");
|
||||
assert_evals_to!(&test_roc_code, I128::from(-15), I128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_i128_checked_same() {
|
||||
let test_roc_code = wrap_with_default("Num.toI128Checked 15i128");
|
||||
assert_evals_to!(&test_roc_code, I128::from(15), I128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_i128_checked_same_width_unsigned_fits() {
|
||||
let test_roc_code = wrap_with_default("Num.toI128Checked 15u128");
|
||||
assert_evals_to!(&test_roc_code, I128::from(15), I128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_i128_checked_same_width_unsigned_oob() {
|
||||
let test_roc_code =
|
||||
"Result.isErr (Num.toI128Checked 170141183460469231731687303715884105728u128)";
|
||||
assert_evals_to!(&test_roc_code, true, bool)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_u128_checked_smaller_width_pos() {
|
||||
let test_roc_code = wrap_with_default("Num.toU128Checked 15i8");
|
||||
assert_evals_to!(&test_roc_code, U128::from(15), U128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_u128_checked_smaller_width_neg_oob() {
|
||||
let test_roc_code = "Result.isErr (Num.toU128Checked -15i8)";
|
||||
assert_evals_to!(&test_roc_code, true, bool)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_u128_checked_same() {
|
||||
let test_roc_code = wrap_with_default("Num.toU128Checked 15u128");
|
||||
assert_evals_to!(&test_roc_code, U128::from(15), U128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_u128_checked_same_width_signed_fits() {
|
||||
let test_roc_code = wrap_with_default("Num.toU128Checked 15i128");
|
||||
assert_evals_to!(&test_roc_code, U128::from(15), U128)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn to_u128_checked_same_width_signed_oob() {
|
||||
let test_roc_code = "Result.isErr (Num.toU128Checked -1i128)";
|
||||
assert_evals_to!(&test_roc_code, true, bool)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3263,8 +3324,8 @@ fn dec_float_suffix() {
|
|||
123.0dec
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("123.0"),
|
||||
i128
|
||||
RocDec::from_str("123.0").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3277,8 +3338,8 @@ fn dec_no_decimal() {
|
|||
3dec
|
||||
"
|
||||
),
|
||||
RocDec::from_str_to_i128_unsafe("3.0"),
|
||||
i128
|
||||
RocDec::from_str("3.0").unwrap(),
|
||||
RocDec
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3356,8 +3417,11 @@ fn promote_i128_number_layout() {
|
|||
}
|
||||
"
|
||||
),
|
||||
(18446744073709551617, -9223372036854775808),
|
||||
(i128, i128)
|
||||
(
|
||||
I128::from(18446744073709551617),
|
||||
I128::from(-9223372036854775808)
|
||||
),
|
||||
(I128, I128)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3370,8 +3434,8 @@ fn promote_u128_number_layout() {
|
|||
170141183460469231731687303715884105728 + 1
|
||||
"
|
||||
),
|
||||
170141183460469231731687303715884105729,
|
||||
u128
|
||||
U128::from(170141183460469231731687303715884105729),
|
||||
U128
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3498,10 +3562,14 @@ fn num_abs_diff_int() {
|
|||
#[test]
|
||||
#[cfg(feature = "gen-llvm")]
|
||||
fn num_abs_diff_large_bits() {
|
||||
assert_evals_to!(r"Num.absDiff 0u128 0u128", 0, u128);
|
||||
assert_evals_to!(r"Num.absDiff 1u128 2u128", 1, u128);
|
||||
assert_evals_to!(r"Num.absDiff -1i128 1i128", 2, i128);
|
||||
assert_evals_to!(r"Num.absDiff Num.minI128 -1i128", i128::MAX, i128);
|
||||
assert_evals_to!(r"Num.absDiff 0u128 0u128", U128::from(0), U128);
|
||||
assert_evals_to!(r"Num.absDiff 1u128 2u128", U128::from(1), U128);
|
||||
assert_evals_to!(r"Num.absDiff -1i128 1i128", I128::from(2), I128);
|
||||
assert_evals_to!(
|
||||
r"Num.absDiff Num.minI128 -1i128",
|
||||
I128::from(i128::MAX),
|
||||
I128
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3532,7 +3600,7 @@ fn num_abs_int_min_overflow() {
|
|||
#[cfg(feature = "gen-llvm")]
|
||||
#[should_panic(expected = r#"Roc failed with message: "Integer subtraction overflowed!"#)]
|
||||
fn num_abs_large_bits_min_overflow() {
|
||||
assert_evals_to!(r"Num.absDiff Num.minI128 0", 0, i128);
|
||||
assert_evals_to!(r"Num.absDiff Num.minI128 0", I128::from(0), I128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3619,8 +3687,8 @@ fn mul_checked_u128() {
|
|||
x
|
||||
"
|
||||
),
|
||||
RocResult::ok(5u128 * 2u128),
|
||||
RocResult<u128, ()>
|
||||
RocResult::ok(U128::from(5u128 * 2u128)),
|
||||
RocResult<U128, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3636,8 +3704,8 @@ fn sub_checked_u128() {
|
|||
x
|
||||
"
|
||||
),
|
||||
RocResult::ok(5u128 - 2u128),
|
||||
RocResult<u128, ()>
|
||||
RocResult::ok(U128::from(5u128 - 2u128)),
|
||||
RocResult<U128, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3653,8 +3721,8 @@ fn add_checked_u128() {
|
|||
x
|
||||
"
|
||||
),
|
||||
RocResult::ok(5u128 + 2u128),
|
||||
RocResult<u128, ()>
|
||||
RocResult::ok(U128::from(5u128 + 2u128)),
|
||||
RocResult<U128, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3717,18 +3785,18 @@ fn without_decimal_point() {
|
|||
);
|
||||
assert_evals_to!(
|
||||
r"Num.withoutDecimalPoint 123.000000000000000000",
|
||||
123000000000000000000,
|
||||
i128
|
||||
I128::from(123000000000000000000),
|
||||
I128
|
||||
);
|
||||
assert_evals_to!(
|
||||
r"Num.withoutDecimalPoint 170141183460469231731.687303715884105727",
|
||||
i128::MAX,
|
||||
i128
|
||||
I128::from(i128::MAX),
|
||||
I128
|
||||
);
|
||||
assert_evals_to!(
|
||||
r"Num.withoutDecimalPoint -170141183460469231731.687303715884105728",
|
||||
i128::MIN,
|
||||
i128
|
||||
I128::from(i128::MIN),
|
||||
I128
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ 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, RocResult, RocStr};
|
||||
use roc_std::{RocList, RocResult, RocStr, I128, U128};
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
|
@ -1345,8 +1345,8 @@ fn str_to_i128() {
|
|||
Str.toI128 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
RocResult<i128, ()>
|
||||
RocResult::ok(I128::from(1)),
|
||||
RocResult<I128, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1359,11 +1359,12 @@ fn str_to_u128() {
|
|||
Str.toU128 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
RocResult<u128, ()>
|
||||
RocResult::ok(U128::from(1)),
|
||||
RocResult<U128, ()>
|
||||
);
|
||||
}
|
||||
|
||||
// TODO add alignment check between i64 and I64 somewhere
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_to_i64() {
|
||||
|
|
|
@ -15,7 +15,7 @@ use indoc::indoc;
|
|||
|
||||
use roc_mono::layout::{LayoutRepr, STLayoutInterner};
|
||||
#[cfg(test)]
|
||||
use roc_std::{RocList, RocStr, U128};
|
||||
use roc_std::{RocList, RocStr, I128, U128};
|
||||
|
||||
#[test]
|
||||
fn width_and_alignment_u8_u8() {
|
||||
|
@ -1779,7 +1779,24 @@ fn alignment_i128() {
|
|||
x
|
||||
#"
|
||||
),
|
||||
// NOTE: roc_std::U128 is always aligned to 16, unlike rust's u128
|
||||
// NOTE: roc_std::I128 is always aligned to 16, unlike rust's i128
|
||||
((I128::from(42), true), 1),
|
||||
((I128, bool), u8)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn alignment_u128() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"#
|
||||
x : [One U128 Bool, Empty]
|
||||
x = One 42 (1 == 1)
|
||||
x
|
||||
#"
|
||||
),
|
||||
// NOTE: roc_std::U128 is always aligned to 16, unlike rust's i128
|
||||
((U128::from(42), true), 1),
|
||||
((U128, bool), u8)
|
||||
);
|
||||
|
|
|
@ -335,6 +335,9 @@ pub fn helper<'a>(
|
|||
let (main_fn_name, delayed_errors, module) =
|
||||
create_llvm_module(arena, src, config, context, target, function_kind);
|
||||
|
||||
// for debugging:
|
||||
//module.print_to_file(std::path::Path::new("/home/username/roc/llvm_ir.ll")).unwrap();
|
||||
|
||||
if !config.emit_debug_info {
|
||||
module.strip_debug_info();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::helpers::wasm::assert_evals_to;
|
|||
|
||||
#[allow(unused_imports)]
|
||||
use indoc::indoc;
|
||||
use roc_std::{RocList, RocStr};
|
||||
use roc_std::{RocList, RocStr, I128, U128};
|
||||
|
||||
#[test]
|
||||
fn str_split_empty_delimiter() {
|
||||
|
@ -998,8 +998,8 @@ fn str_to_i128() {
|
|||
Err _ -> 0
|
||||
"#
|
||||
),
|
||||
1,
|
||||
i128
|
||||
I128::from(1),
|
||||
I128
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1013,8 +1013,8 @@ fn str_to_u128() {
|
|||
Err _ -> 0
|
||||
"#
|
||||
),
|
||||
1,
|
||||
u128
|
||||
U128::from(1),
|
||||
U128
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2913,8 +2913,7 @@ where
|
|||
|
||||
pub fn iter_all(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (SubsIndex<L>, SubsIndex<VariableSubsSlice>)> + ExactSizeIterator
|
||||
{
|
||||
) -> impl ExactSizeIterator<Item = (SubsIndex<L>, SubsIndex<VariableSubsSlice>)> {
|
||||
self.labels().into_iter().zip(self.variables())
|
||||
}
|
||||
|
||||
|
@ -2923,7 +2922,7 @@ where
|
|||
pub fn iter_from_subs<'a>(
|
||||
&'a self,
|
||||
subs: &'a Subs,
|
||||
) -> impl Iterator<Item = (&'a L, &'a [Variable])> + ExactSizeIterator {
|
||||
) -> impl ExactSizeIterator<Item = (&'a L, &'a [Variable])> {
|
||||
self.iter_all().map(move |(name_index, payload_index)| {
|
||||
(
|
||||
L::index_subs(subs, name_index),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue