mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Merge remote-tracking branch 'origin/trunk' into single-quote-literal
This commit is contained in:
commit
f7c0e2ef19
634 changed files with 47014 additions and 21117 deletions
|
@ -1,4 +1,6 @@
|
|||
use crate::builtins::{empty_list_type, float_literal, int_literal, list_type, num_u32, str_type};
|
||||
use crate::builtins::{
|
||||
empty_list_type, float_literal, int_literal, list_type, num_literal, num_u32, str_type,
|
||||
};
|
||||
use crate::pattern::{constrain_pattern, PatternState};
|
||||
use roc_can::annotation::IntroducedVariables;
|
||||
use roc_can::constraint::Constraint::{self, *};
|
||||
|
@ -10,20 +12,20 @@ use roc_can::expr::Expr::{self, *};
|
|||
use roc_can::expr::{ClosureData, Field, WhenBranch};
|
||||
use roc_can::pattern::Pattern;
|
||||
use roc_collections::all::{ImMap, Index, MutSet, SendMap};
|
||||
use roc_error_macros::todo_opaques;
|
||||
use roc_module::ident::{Lowercase, TagName};
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::subs::Variable;
|
||||
use roc_types::types::AnnotationSource::{self, *};
|
||||
use roc_types::types::Type::{self, *};
|
||||
use roc_types::types::{Category, PReason, Reason, RecordField};
|
||||
use roc_types::types::{AnnotationSource, Category, PReason, Reason, RecordField};
|
||||
|
||||
/// This is for constraining Defs
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Info {
|
||||
pub vars: Vec<Variable>,
|
||||
pub constraints: Vec<Constraint>,
|
||||
pub def_types: SendMap<Symbol, Located<Type>>,
|
||||
pub def_types: SendMap<Symbol, Loc<Type>>,
|
||||
}
|
||||
|
||||
impl Info {
|
||||
|
@ -57,7 +59,7 @@ pub struct Env {
|
|||
|
||||
fn constrain_untyped_args(
|
||||
env: &Env,
|
||||
arguments: &[(Variable, Located<Pattern>)],
|
||||
arguments: &[(Variable, Loc<Pattern>)],
|
||||
closure_type: Type,
|
||||
return_type: Type,
|
||||
) -> (Vec<Variable>, PatternState, Type) {
|
||||
|
@ -96,17 +98,11 @@ pub fn constrain_expr(
|
|||
expected: Expected<Type>,
|
||||
) -> Constraint {
|
||||
match expr {
|
||||
Int(var, precision, _, _) => int_literal(*var, *precision, expected, region),
|
||||
Num(var, _, _) => exists(
|
||||
vec![*var],
|
||||
Eq(
|
||||
crate::builtins::num_num(Type::Variable(*var)),
|
||||
expected,
|
||||
Category::Num,
|
||||
region,
|
||||
),
|
||||
),
|
||||
Float(var, precision, _, _) => float_literal(*var, *precision, expected, region),
|
||||
&Int(var, precision, _, _, bound) => int_literal(var, precision, expected, region, bound),
|
||||
&Num(var, _, _, bound) => num_literal(var, expected, region, bound),
|
||||
&Float(var, precision, _, _, bound) => {
|
||||
float_literal(var, precision, expected, region, bound)
|
||||
}
|
||||
EmptyRecord => constrain_empty_record(region, expected),
|
||||
Expr::Record { record_var, fields } => {
|
||||
if fields.is_empty() {
|
||||
|
@ -605,7 +601,7 @@ pub fn constrain_expr(
|
|||
FromAnnotation(
|
||||
name.clone(),
|
||||
*arity,
|
||||
TypedWhenBranch {
|
||||
AnnotationSource::TypedWhenBranch {
|
||||
index: Index::zero_based(index),
|
||||
region: ann_source.region(),
|
||||
},
|
||||
|
@ -921,6 +917,8 @@ pub fn constrain_expr(
|
|||
exists(vars, And(arg_cons))
|
||||
}
|
||||
|
||||
OpaqueRef { .. } => todo_opaques!(),
|
||||
|
||||
RunLowLevel { args, ret_var, op } => {
|
||||
// This is a modified version of what we do for function calls.
|
||||
|
||||
|
@ -1081,7 +1079,7 @@ fn constrain_when_branch(
|
|||
}
|
||||
}
|
||||
|
||||
fn constrain_field(env: &Env, field_var: Variable, loc_expr: &Located<Expr>) -> (Type, Constraint) {
|
||||
fn constrain_field(env: &Env, field_var: Variable, loc_expr: &Loc<Expr>) -> (Type, Constraint) {
|
||||
let field_type = Variable(field_var);
|
||||
let field_expected = NoExpectation(field_type.clone());
|
||||
let constraint = constrain_expr(env, loc_expr.region, &loc_expr.value, field_expected);
|
||||
|
@ -1129,11 +1127,7 @@ pub fn constrain_decls(home: ModuleId, decls: &[Declaration]) -> Constraint {
|
|||
constraint
|
||||
}
|
||||
|
||||
fn constrain_def_pattern(
|
||||
env: &Env,
|
||||
loc_pattern: &Located<Pattern>,
|
||||
expr_type: Type,
|
||||
) -> PatternState {
|
||||
fn constrain_def_pattern(env: &Env, loc_pattern: &Loc<Pattern>, expr_type: Type) -> PatternState {
|
||||
let pattern_expected = PExpected::NoExpectation(expr_type);
|
||||
|
||||
let mut state = PatternState {
|
||||
|
@ -1450,8 +1444,8 @@ fn instantiate_rigids(
|
|||
introduced_vars: &IntroducedVariables,
|
||||
new_rigids: &mut Vec<Variable>,
|
||||
ftv: &mut ImMap<Lowercase, Variable>, // rigids defined before the current annotation
|
||||
loc_pattern: &Located<Pattern>,
|
||||
headers: &mut SendMap<Symbol, Located<Type>>,
|
||||
loc_pattern: &Loc<Pattern>,
|
||||
headers: &mut SendMap<Symbol, Loc<Type>>,
|
||||
) -> Type {
|
||||
let mut annotation = annotation.clone();
|
||||
let mut rigid_substitution: ImMap<Variable, Type> = ImMap::default();
|
||||
|
@ -1474,7 +1468,7 @@ fn instantiate_rigids(
|
|||
|
||||
if let Some(new_headers) = crate::pattern::headers_from_annotation(
|
||||
&loc_pattern.value,
|
||||
&Located::at(loc_pattern.region, annotation.clone()),
|
||||
&Loc::at(loc_pattern.region, annotation.clone()),
|
||||
) {
|
||||
for (symbol, loc_type) in new_headers {
|
||||
for var in loc_type.value.variables() {
|
||||
|
@ -1771,7 +1765,7 @@ fn constrain_field_update(
|
|||
var: Variable,
|
||||
region: Region,
|
||||
field: Lowercase,
|
||||
loc_expr: &Located<Expr>,
|
||||
loc_expr: &Loc<Expr>,
|
||||
) -> (Variable, Type, Constraint) {
|
||||
let field_type = Type::Variable(var);
|
||||
let reason = Reason::RecordUpdateValue(field);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue