mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
fix: uniqueness for Num types
This commit is contained in:
parent
c9308c0662
commit
d1ae3b47af
4 changed files with 47 additions and 49 deletions
|
@ -1190,36 +1190,34 @@ fn lift(u: VarId, a: SolvedType) -> SolvedType {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn float_type(u: VarId) -> SolvedType {
|
fn float_type(u: VarId) -> SolvedType {
|
||||||
|
let b_64 = builtin_aliases::binary64_type();
|
||||||
|
let attr_b_64 = lift(u, b_64);
|
||||||
|
let fp = builtin_aliases::floatingpoint_type(attr_b_64);
|
||||||
|
let attr_fb = lift(u, fp);
|
||||||
|
let num = builtin_aliases::num_type(attr_fb);
|
||||||
|
|
||||||
SolvedType::Apply(
|
SolvedType::Apply(
|
||||||
Symbol::ATTR_ATTR,
|
Symbol::ATTR_ATTR,
|
||||||
vec![
|
vec![
|
||||||
flex(u),
|
flex(u),
|
||||||
SolvedType::Alias(
|
SolvedType::Alias(Symbol::NUM_F64, Vec::new(), Box::new(num)),
|
||||||
Symbol::NUM_F64,
|
|
||||||
Vec::new(),
|
|
||||||
Box::new(builtin_aliases::num_type(SolvedType::Apply(
|
|
||||||
Symbol::ATTR_ATTR,
|
|
||||||
vec![flex(u), builtin_aliases::float_type()],
|
|
||||||
))),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn int_type(u: VarId) -> SolvedType {
|
fn int_type(u: VarId) -> SolvedType {
|
||||||
|
let signed_64 = builtin_aliases::signed64_type();
|
||||||
|
let attr_signed_64 = lift(u, signed_64);
|
||||||
|
let integer = builtin_aliases::integer_type(attr_signed_64);
|
||||||
|
let attr_fb = lift(u, integer);
|
||||||
|
let num = builtin_aliases::num_type(attr_fb);
|
||||||
|
|
||||||
SolvedType::Apply(
|
SolvedType::Apply(
|
||||||
Symbol::ATTR_ATTR,
|
Symbol::ATTR_ATTR,
|
||||||
vec![
|
vec![
|
||||||
flex(u),
|
flex(u),
|
||||||
SolvedType::Alias(
|
SolvedType::Alias(Symbol::NUM_I64, Vec::new(), Box::new(num)),
|
||||||
Symbol::NUM_I64,
|
|
||||||
Vec::new(),
|
|
||||||
Box::new(builtin_aliases::num_type(SolvedType::Apply(
|
|
||||||
Symbol::ATTR_ATTR,
|
|
||||||
vec![flex(u), builtin_aliases::int_type()],
|
|
||||||
))),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,17 +174,17 @@ fn constrain_pattern(
|
||||||
}
|
}
|
||||||
|
|
||||||
IntLiteral(_) => {
|
IntLiteral(_) => {
|
||||||
let (var1, var2, num_uvar, int_uvar, num_type) = unique_int(var_store);
|
let (num_uvar, num_type) = unique_int(var_store);
|
||||||
state.constraints.push(exists(
|
state.constraints.push(exists(
|
||||||
vec![num_uvar, int_uvar, var1, var2],
|
vec![num_uvar],
|
||||||
Constraint::Pattern(pattern.region, PatternCategory::Int, num_type, expected),
|
Constraint::Pattern(pattern.region, PatternCategory::Int, num_type, expected),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
FloatLiteral(_) => {
|
FloatLiteral(_) => {
|
||||||
let (var1, var2, num_uvar, float_uvar, num_type) = unique_float(var_store);
|
let (num_uvar, num_type) = unique_float(var_store);
|
||||||
|
|
||||||
state.constraints.push(exists(
|
state.constraints.push(exists(
|
||||||
vec![num_uvar, float_uvar, var1, var2],
|
vec![num_uvar],
|
||||||
Constraint::Pattern(pattern.region, PatternCategory::Float, num_type, expected),
|
Constraint::Pattern(pattern.region, PatternCategory::Float, num_type, expected),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -423,54 +423,49 @@ fn unique_unbound_num(
|
||||||
(num_uvar, val_uvar, num_type, num_var)
|
(num_uvar, val_uvar, num_type, num_var)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unique_num(var_store: &mut VarStore, val_type: Type) -> (Variable, Variable, Type) {
|
fn unique_num(val_type: Type, uvar: Variable) -> Type {
|
||||||
let num_uvar = var_store.fresh();
|
let val_utype = attr_type(Bool::variable(uvar), val_type);
|
||||||
let val_uvar = var_store.fresh();
|
|
||||||
|
|
||||||
let val_utype = attr_type(Bool::variable(val_uvar), val_type);
|
|
||||||
|
|
||||||
let num_utype = num_num(val_utype);
|
let num_utype = num_num(val_utype);
|
||||||
let num_type = attr_type(Bool::variable(num_uvar), num_utype);
|
let num_type = attr_type(Bool::variable(uvar), num_utype);
|
||||||
|
|
||||||
(num_uvar, val_uvar, num_type)
|
num_type
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unique_integer(var_store: &mut VarStore, val_type: Type) -> (Variable, Variable, Type) {
|
fn unique_integer(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) {
|
||||||
let num_uvar = var_store.fresh();
|
let num_uvar = var_store.fresh();
|
||||||
let val_uvar = var_store.fresh();
|
|
||||||
|
|
||||||
let val_utype = attr_type(Bool::variable(val_uvar), val_type);
|
let val_utype = attr_type(Bool::variable(num_uvar), val_type);
|
||||||
|
|
||||||
let num_type = num_integer(val_utype);
|
let num_type = num_integer(val_utype);
|
||||||
|
|
||||||
(num_uvar, val_uvar, num_type)
|
(num_uvar, num_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unique_int(var_store: &mut VarStore) -> (Variable, Variable, Variable, Variable, Type) {
|
fn unique_int(var_store: &mut VarStore) -> (Variable, Type) {
|
||||||
let (var1, var2, typ) = unique_integer(var_store, num_signed64());
|
let (var1, typ) = unique_integer(var_store, num_signed64());
|
||||||
|
|
||||||
let (var3, var4, typ) = unique_num(var_store, typ);
|
let typ = unique_num(typ, var1);
|
||||||
|
|
||||||
(var1, var2, var3, var4, typ)
|
(var1, typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unique_floatingpoint(var_store: &mut VarStore, val_type: Type) -> (Variable, Variable, Type) {
|
fn unique_floatingpoint(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) {
|
||||||
let num_uvar = var_store.fresh();
|
let num_uvar = var_store.fresh();
|
||||||
let val_uvar = var_store.fresh();
|
|
||||||
|
|
||||||
let val_utype = attr_type(Bool::variable(val_uvar), val_type);
|
let val_utype = attr_type(Bool::variable(num_uvar), val_type);
|
||||||
|
|
||||||
let num_type = num_floatingpoint(val_utype);
|
let num_type = num_floatingpoint(val_utype);
|
||||||
|
|
||||||
(num_uvar, val_uvar, num_type)
|
(num_uvar, num_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unique_float(var_store: &mut VarStore) -> (Variable, Variable, Variable, Variable, Type) {
|
fn unique_float(var_store: &mut VarStore) -> (Variable, Type) {
|
||||||
let (var1, var2, typ) = unique_floatingpoint(var_store, num_binary64());
|
let (var1, typ) = unique_floatingpoint(var_store, num_binary64());
|
||||||
|
|
||||||
let (var3, var4, typ) = unique_num(var_store, typ);
|
let typ = unique_num(typ, var1);
|
||||||
|
|
||||||
(var1, var2, var3, var4, typ)
|
(var1, typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn constrain_expr(
|
pub fn constrain_expr(
|
||||||
|
@ -503,10 +498,10 @@ pub fn constrain_expr(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Int(var, _) => {
|
Int(var, _) => {
|
||||||
let (var1, var2, num_uvar, int_uvar, num_type) = unique_int(var_store);
|
let (num_uvar, num_type) = unique_int(var_store);
|
||||||
|
|
||||||
exists(
|
exists(
|
||||||
vec![*var, num_uvar, int_uvar, var1, var2],
|
vec![*var, num_uvar],
|
||||||
And(vec![
|
And(vec![
|
||||||
Eq(
|
Eq(
|
||||||
Type::Variable(*var),
|
Type::Variable(*var),
|
||||||
|
@ -519,10 +514,10 @@ pub fn constrain_expr(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Float(var, _) => {
|
Float(var, _) => {
|
||||||
let (var1, var2, num_uvar, float_uvar, num_type) = unique_float(var_store);
|
let (num_uvar, num_type) = unique_float(var_store);
|
||||||
|
|
||||||
exists(
|
exists(
|
||||||
vec![*var, num_uvar, float_uvar, var1, var2],
|
vec![*var, num_uvar],
|
||||||
And(vec![
|
And(vec![
|
||||||
Eq(
|
Eq(
|
||||||
Type::Variable(*var),
|
Type::Variable(*var),
|
||||||
|
|
|
@ -5853,6 +5853,11 @@ pub fn num_argument_to_int_or_float(subs: &Subs, var: Variable) -> IntOrFloat {
|
||||||
// Recurse on the second argument
|
// Recurse on the second argument
|
||||||
num_argument_to_int_or_float(subs, attr_args[1])
|
num_argument_to_int_or_float(subs, attr_args[1])
|
||||||
}
|
}
|
||||||
|
Content::Alias(Symbol::NUM_F64, args, _) | Content::Alias(Symbol::NUM_F32, args, _) => {
|
||||||
|
debug_assert!(args.is_empty());
|
||||||
|
|
||||||
|
IntOrFloat::FloatType
|
||||||
|
}
|
||||||
other => {
|
other => {
|
||||||
panic!(
|
panic!(
|
||||||
"Unrecognized Num type argument for var {:?} with Content: {:?}",
|
"Unrecognized Num type argument for var {:?} with Content: {:?}",
|
||||||
|
|
|
@ -367,7 +367,7 @@ pub fn binary64_type() -> SolvedType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn binary64_alias_content() -> SolvedType {
|
pub fn binary64_alias_content() -> SolvedType {
|
||||||
single_private_tag(Symbol::NUM_AT_BINARY64, vec![])
|
single_private_tag(Symbol::NUM_AT_BINARY64, vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ pub fn dict_type(key: SolvedType, value: SolvedType) -> SolvedType {
|
||||||
SolvedType::Apply(Symbol::DICT_DICT, vec![key, value])
|
SolvedType::Apply(Symbol::DICT_DICT, vec![key, value])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn single_private_tag(symbol: Symbol, type_arguments: Vec<SolvedType>) -> SolvedType {
|
pub fn single_private_tag(symbol: Symbol, type_arguments: Vec<SolvedType>) -> SolvedType {
|
||||||
SolvedType::TagUnion(
|
SolvedType::TagUnion(
|
||||||
vec![(TagName::Private(symbol), type_arguments)],
|
vec![(TagName::Private(symbol), type_arguments)],
|
||||||
Box::new(SolvedType::EmptyTagUnion),
|
Box::new(SolvedType::EmptyTagUnion),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue