mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
expand aliases used in constraint gen
This commit is contained in:
parent
2478ae05b1
commit
8a50d48ce2
2 changed files with 52 additions and 3 deletions
|
@ -2,6 +2,7 @@ use roc_can::constraint::Constraint::{self, *};
|
||||||
use roc_can::constraint::LetConstraint;
|
use roc_can::constraint::LetConstraint;
|
||||||
use roc_can::expected::Expected::{self, *};
|
use roc_can::expected::Expected::{self, *};
|
||||||
use roc_collections::all::SendMap;
|
use roc_collections::all::SendMap;
|
||||||
|
use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
use roc_types::subs::Variable;
|
use roc_types::subs::Variable;
|
||||||
|
@ -13,7 +14,7 @@ use roc_types::types::Type::{self, *};
|
||||||
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
||||||
let num_type = Variable(num_var);
|
let num_type = Variable(num_var);
|
||||||
let reason = Reason::IntLiteral;
|
let reason = Reason::IntLiteral;
|
||||||
let expected_literal = ForReason(reason, Type::Apply(Symbol::NUM_INT, vec![]), region);
|
let expected_literal = ForReason(reason, num_int(), region);
|
||||||
|
|
||||||
exists(
|
exists(
|
||||||
vec![num_var],
|
vec![num_var],
|
||||||
|
@ -28,7 +29,7 @@ pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region)
|
||||||
pub fn float_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
pub fn float_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
||||||
let num_type = Variable(num_var);
|
let num_type = Variable(num_var);
|
||||||
let reason = Reason::FloatLiteral;
|
let reason = Reason::FloatLiteral;
|
||||||
let expected_literal = ForReason(reason, Type::Apply(Symbol::NUM_FLOAT, vec![]), region);
|
let expected_literal = ForReason(reason, num_float(), region);
|
||||||
|
|
||||||
exists(
|
exists(
|
||||||
vec![num_var],
|
vec![num_var],
|
||||||
|
@ -70,3 +71,51 @@ pub fn list_type(typ: Type) -> Type {
|
||||||
pub fn str_type() -> Type {
|
pub fn str_type() -> Type {
|
||||||
builtin_type(Symbol::STR_STR, Vec::new())
|
builtin_type(Symbol::STR_STR, Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn num_float() -> Type {
|
||||||
|
Type::Alias(
|
||||||
|
Symbol::NUM_FLOAT,
|
||||||
|
vec![],
|
||||||
|
Box::new(num_num(num_floatingpoint())),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn num_floatingpoint() -> Type {
|
||||||
|
let alias_content = Type::TagUnion(
|
||||||
|
vec![(TagName::Private(Symbol::NUM_AT_FLOATINGPOINT), vec![])],
|
||||||
|
Box::new(Type::EmptyTagUnion),
|
||||||
|
);
|
||||||
|
|
||||||
|
Type::Alias(Symbol::NUM_FLOATINGPOINT, vec![], Box::new(alias_content))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn num_int() -> Type {
|
||||||
|
Type::Alias(Symbol::NUM_INT, vec![], Box::new(num_num(num_integer())))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn num_integer() -> Type {
|
||||||
|
let alias_content = Type::TagUnion(
|
||||||
|
vec![(TagName::Private(Symbol::NUM_AT_INTEGER), vec![])],
|
||||||
|
Box::new(Type::EmptyTagUnion),
|
||||||
|
);
|
||||||
|
|
||||||
|
Type::Alias(Symbol::NUM_INTEGER, vec![], Box::new(alias_content))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn num_num(typ: Type) -> Type {
|
||||||
|
let alias_content = Type::TagUnion(
|
||||||
|
vec![(TagName::Private(Symbol::NUM_AT_NUM), vec![typ.clone()])],
|
||||||
|
Box::new(Type::EmptyTagUnion),
|
||||||
|
);
|
||||||
|
|
||||||
|
Type::Alias(
|
||||||
|
Symbol::NUM_NUM,
|
||||||
|
vec![("range".into(), typ)],
|
||||||
|
Box::new(alias_content),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub fn constrain_expr(
|
||||||
Num(var, _) => exists(
|
Num(var, _) => exists(
|
||||||
vec![*var],
|
vec![*var],
|
||||||
Eq(
|
Eq(
|
||||||
Type::Apply(Symbol::NUM_NUM, vec![Type::Variable(*var)]),
|
crate::builtins::num_num(Type::Variable(*var)),
|
||||||
expected,
|
expected,
|
||||||
Category::Num,
|
Category::Num,
|
||||||
region,
|
region,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue