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

View file

@ -3530,3 +3530,48 @@ fn round_to_u32() {
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!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
x : [A (Int *), B (Int *)] x : [A (Int a), B (Int a)]
x = A 0x2 x = A 0x2
when x is when x is
@ -192,7 +192,7 @@ fn when_two_element_tag_second() {
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
x : [A (Int *), B (Int *)] x : [A (Int a), B (Int a)]
x = B 0x3 x = B 0x3
when x is 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 // Ranged number wins
merge(subs, ctx, RangedNumber(range_vars)) merge(subs, ctx, RangedNumber(range_vars))
} }
RecursionVar { .. } RigidVar(name) => {
| RigidVar(..) // Int a vs Int <range>, the rigid wins
| Alias(..) merge(subs, ctx, RigidVar(*name))
| Structure(..) }
| RigidAbleVar(..) RecursionVar { .. } | Alias(..) | Structure(..) | RigidAbleVar(..) | FlexAbleVar(..) => {
| FlexAbleVar(..) => check_and_merge_valid_range(subs, ctx, ctx.second, range_vars), check_and_merge_valid_range(subs, ctx, ctx.second, range_vars)
}
&RangedNumber(other_range_vars) => match range_vars.intersection(&other_range_vars) { &RangedNumber(other_range_vars) => match range_vars.intersection(&other_range_vars) {
Some(range) => merge(subs, ctx, RangedNumber(range)), Some(range) => merge(subs, ctx, RangedNumber(range)),
None => not_in_range_mismatch(), None => not_in_range_mismatch(),
@ -2206,13 +2207,16 @@ fn unify_rigid<M: MetaCollector>(
"Rigid {:?} with FlexAble {:?}", ctx.first, other "Rigid {:?} with FlexAble {:?}", ctx.first, other
) )
} }
RangedNumber(..) => {
// Int a vs Int <range>, the rigid wins
merge(subs, ctx, RigidVar(*name))
}
RigidVar(_) RigidVar(_)
| RigidAbleVar(..) | RigidAbleVar(..)
| RecursionVar { .. } | RecursionVar { .. }
| Structure(_) | Structure(_)
| Alias(..) | Alias(..)
| RangedNumber(..)
| LambdaSet(..) => { | LambdaSet(..) => {
// Type mismatch! Rigid can only unify with flex, even if the // Type mismatch! Rigid can only unify with flex, even if the
// rigid names are the same. // rigid names are the same.