Gen tests for promoted num layouts

This commit is contained in:
Ayaz Hafiz 2022-07-04 19:03:31 -04:00 committed by ayazhafiz
parent ba450367ca
commit 2492fba9f9
No known key found for this signature in database
GPG key ID: B443F7A3030C9AED
5 changed files with 79 additions and 16 deletions

View file

@ -8186,17 +8186,17 @@ fn from_can_pattern_help<'a>(
Underscore => Ok(Pattern::Underscore),
Identifier(symbol) => Ok(Pattern::Identifier(*symbol)),
AbilityMemberSpecialization { ident, .. } => Ok(Pattern::Identifier(*ident)),
IntLiteral(_, precision_var, int_str, int, _bound) => Ok(make_num_literal_pattern(
IntLiteral(var, _, int_str, int, _bound) => Ok(make_num_literal_pattern(
env,
layout_cache,
*precision_var,
*var,
int_str,
IntOrFloatValue::Int(*int),
)),
FloatLiteral(_, precision_var, float_str, float, _bound) => Ok(make_num_literal_pattern(
FloatLiteral(var, _, float_str, float, _bound) => Ok(make_num_literal_pattern(
env,
layout_cache,
*precision_var,
*var,
float_str,
IntOrFloatValue::Float(*float),
)),
@ -8882,9 +8882,10 @@ fn make_num_literal<'a>(
},
Layout::Builtin(Builtin::Float(width)) => match num_value {
IntOrFloatValue::Float(n) => NumLiteral::Float(n, width),
IntOrFloatValue::Int(..) => {
internal_error!("Int value where float was expected, should have been a type error")
}
IntOrFloatValue::Int(int_value) => match int_value {
IntValue::I128(n) => NumLiteral::Float(i128::from_ne_bytes(n) as f64, width),
IntValue::U128(n) => NumLiteral::Float(u128::from_ne_bytes(n) as f64, width),
},
},
Layout::Builtin(Builtin::Decimal) => {
let dec = match RocDec::from_str(&num_str) {
@ -8927,6 +8928,10 @@ fn make_num_literal_pattern<'a>(
num_str: &str,
num_value: IntOrFloatValue,
) -> Pattern<'a> {
dbg!(roc_types::subs::SubsFmtContent(
env.subs.get_content_without_compacting(variable),
&env.subs
));
let layout = layout_cache
.from_var(env.arena, variable, &env.subs)
.unwrap();

View file

@ -3530,3 +3530,48 @@ fn round_to_u32() {
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn promote_u64_number_layout() {
assert_evals_to!(
indoc!(
r#"
9999999999999999999 + 1
"#
),
10000000000000000000,
u64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn promote_i128_number_layout() {
assert_evals_to!(
indoc!(
r#"
{
a: 18446744073709551616 + 1,
b: -9223372036854775809 + 1,
}
"#
),
(18446744073709551617, -9223372036854775808),
(i128, i128)
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn promote_u128_number_layout() {
assert_evals_to!(
indoc!(
r#"
170141183460469231731687303715884105728 + 1
"#
),
170141183460469231731687303715884105729,
u128
);
}

View file

@ -173,7 +173,7 @@ fn when_two_element_tag_first() {
assert_evals_to!(
indoc!(
r#"
x : [A (Int *), B (Int *)]
x : [A (Int a), B (Int a)]
x = A 0x2
when x is
@ -192,7 +192,7 @@ fn when_two_element_tag_second() {
assert_evals_to!(
indoc!(
r#"
x : [A (Int *), B (Int *)]
x : [A (Int a), B (Int a)]
x = B 0x3
when x is

View file

@ -1682,3 +1682,12 @@ fn choose_u128_layout() {
"#
)
}
#[mono_test]
fn foobar() {
indoc!(
r#"
170141183460469231731687303715884105728 + 1
"#
)
}

View file

@ -510,12 +510,13 @@ fn unify_ranged_number<M: MetaCollector>(
// Ranged number wins
merge(subs, ctx, RangedNumber(range_vars))
}
RecursionVar { .. }
| RigidVar(..)
| Alias(..)
| Structure(..)
| RigidAbleVar(..)
| FlexAbleVar(..) => check_and_merge_valid_range(subs, ctx, ctx.second, range_vars),
RigidVar(name) => {
// Int a vs Int <range>, the rigid wins
merge(subs, ctx, RigidVar(*name))
}
RecursionVar { .. } | Alias(..) | Structure(..) | RigidAbleVar(..) | FlexAbleVar(..) => {
check_and_merge_valid_range(subs, ctx, ctx.second, range_vars)
}
&RangedNumber(other_range_vars) => match range_vars.intersection(&other_range_vars) {
Some(range) => merge(subs, ctx, RangedNumber(range)),
None => not_in_range_mismatch(),
@ -2206,13 +2207,16 @@ fn unify_rigid<M: MetaCollector>(
"Rigid {:?} with FlexAble {:?}", ctx.first, other
)
}
RangedNumber(..) => {
// Int a vs Int <range>, the rigid wins
merge(subs, ctx, RigidVar(*name))
}
RigidVar(_)
| RigidAbleVar(..)
| RecursionVar { .. }
| Structure(_)
| Alias(..)
| RangedNumber(..)
| LambdaSet(..) => {
// Type mismatch! Rigid can only unify with flex, even if the
// rigid names are the same.