mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
WIP
This commit is contained in:
parent
fd8dfd284d
commit
ec099bbdec
12 changed files with 103 additions and 118 deletions
|
@ -1,7 +1,7 @@
|
||||||
use bumpalo::{collections::Vec as BumpVec, Bump};
|
use bumpalo::{collections::Vec as BumpVec, Bump};
|
||||||
|
|
||||||
use roc_can::expected::{Expected, PExpected};
|
use roc_can::expected::{Expected, PExpected};
|
||||||
use roc_collections::all::{BumpMap, BumpMapDefault, Index, SendMap};
|
use roc_collections::all::{BumpMap, BumpMapDefault, HumanIndex, SendMap};
|
||||||
use roc_module::{
|
use roc_module::{
|
||||||
ident::{Lowercase, TagName},
|
ident::{Lowercase, TagName},
|
||||||
symbol::Symbol,
|
symbol::Symbol,
|
||||||
|
@ -163,7 +163,7 @@ pub fn constrain_expr<'a>(
|
||||||
|
|
||||||
let elem_expected = Expected::ForReason(
|
let elem_expected = Expected::ForReason(
|
||||||
Reason::ElemInList {
|
Reason::ElemInList {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
list_elem_type.shallow_clone(),
|
list_elem_type.shallow_clone(),
|
||||||
region,
|
region,
|
||||||
|
@ -339,7 +339,7 @@ pub fn constrain_expr<'a>(
|
||||||
|
|
||||||
let reason = Reason::FnArg {
|
let reason = Reason::FnArg {
|
||||||
name: opt_symbol,
|
name: opt_symbol,
|
||||||
arg_index: Index::zero_based(index),
|
arg_index: HumanIndex::zero_based(index),
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_arg = Expected::ForReason(reason, arg_type.shallow_clone(), region);
|
let expected_arg = Expected::ForReason(reason, arg_type.shallow_clone(), region);
|
||||||
|
@ -538,7 +538,7 @@ pub fn constrain_expr<'a>(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
arity,
|
arity,
|
||||||
AnnotationSource::TypedIfBranch {
|
AnnotationSource::TypedIfBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
num_branches,
|
num_branches,
|
||||||
region: ann_source.region(),
|
region: ann_source.region(),
|
||||||
},
|
},
|
||||||
|
@ -559,7 +559,7 @@ pub fn constrain_expr<'a>(
|
||||||
name,
|
name,
|
||||||
arity,
|
arity,
|
||||||
AnnotationSource::TypedIfBranch {
|
AnnotationSource::TypedIfBranch {
|
||||||
index: Index::zero_based(branches.len()),
|
index: HumanIndex::zero_based(branches.len()),
|
||||||
num_branches,
|
num_branches,
|
||||||
region: ann_source.region(),
|
region: ann_source.region(),
|
||||||
},
|
},
|
||||||
|
@ -596,7 +596,7 @@ pub fn constrain_expr<'a>(
|
||||||
body,
|
body,
|
||||||
Expected::ForReason(
|
Expected::ForReason(
|
||||||
Reason::IfBranch {
|
Reason::IfBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
total_branches: branches.len(),
|
total_branches: branches.len(),
|
||||||
},
|
},
|
||||||
Type2::Variable(*expr_var),
|
Type2::Variable(*expr_var),
|
||||||
|
@ -616,7 +616,7 @@ pub fn constrain_expr<'a>(
|
||||||
final_else_expr,
|
final_else_expr,
|
||||||
Expected::ForReason(
|
Expected::ForReason(
|
||||||
Reason::IfBranch {
|
Reason::IfBranch {
|
||||||
index: Index::zero_based(branches.len()),
|
index: HumanIndex::zero_based(branches.len()),
|
||||||
total_branches: branches.len() + 1,
|
total_branches: branches.len() + 1,
|
||||||
},
|
},
|
||||||
Type2::Variable(*expr_var),
|
Type2::Variable(*expr_var),
|
||||||
|
@ -691,7 +691,7 @@ pub fn constrain_expr<'a>(
|
||||||
when_branch,
|
when_branch,
|
||||||
PExpected::ForReason(
|
PExpected::ForReason(
|
||||||
PReason::WhenMatch {
|
PReason::WhenMatch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
cond_type.shallow_clone(),
|
cond_type.shallow_clone(),
|
||||||
pattern_region,
|
pattern_region,
|
||||||
|
@ -700,7 +700,7 @@ pub fn constrain_expr<'a>(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
*arity,
|
*arity,
|
||||||
AnnotationSource::TypedWhenBranch {
|
AnnotationSource::TypedWhenBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
region: ann_source.region(),
|
region: ann_source.region(),
|
||||||
},
|
},
|
||||||
typ.shallow_clone(),
|
typ.shallow_clone(),
|
||||||
|
@ -733,14 +733,14 @@ pub fn constrain_expr<'a>(
|
||||||
when_branch,
|
when_branch,
|
||||||
PExpected::ForReason(
|
PExpected::ForReason(
|
||||||
PReason::WhenMatch {
|
PReason::WhenMatch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
cond_type.shallow_clone(),
|
cond_type.shallow_clone(),
|
||||||
pattern_region,
|
pattern_region,
|
||||||
),
|
),
|
||||||
Expected::ForReason(
|
Expected::ForReason(
|
||||||
Reason::WhenBranch {
|
Reason::WhenBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
branch_type.shallow_clone(),
|
branch_type.shallow_clone(),
|
||||||
// TODO: when_branch.value.region,
|
// TODO: when_branch.value.region,
|
||||||
|
@ -1065,7 +1065,7 @@ pub fn constrain_expr<'a>(
|
||||||
|
|
||||||
let reason = Reason::LowLevelOpArg {
|
let reason = Reason::LowLevelOpArg {
|
||||||
op: *op,
|
op: *op,
|
||||||
arg_index: Index::zero_based(index),
|
arg_index: HumanIndex::zero_based(index),
|
||||||
};
|
};
|
||||||
let expected_arg =
|
let expected_arg =
|
||||||
Expected::ForReason(reason, arg_type.shallow_clone(), Region::zero());
|
Expected::ForReason(reason, arg_type.shallow_clone(), Region::zero());
|
||||||
|
@ -1681,7 +1681,7 @@ fn constrain_tag_pattern<'a>(
|
||||||
let expected = PExpected::ForReason(
|
let expected = PExpected::ForReason(
|
||||||
PReason::TagArg {
|
PReason::TagArg {
|
||||||
tag_name: tag_name.clone(),
|
tag_name: tag_name.clone(),
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
pattern_type,
|
pattern_type,
|
||||||
region,
|
region,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::expected::{Expected, PExpected};
|
use crate::expected::{Expected, PExpected};
|
||||||
use roc_collections::all::{MutSet, SendMap};
|
use roc_collections::soa::{Index, Slice};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use roc_types::types::{Category, PatternCategory, Type};
|
use roc_types::types::{Category, PatternCategory, Type};
|
||||||
use roc_types::{subs::Variable, types::VariableDetail};
|
use roc_types::{subs::Variable, types::VariableDetail};
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ pub struct Constraints {
|
||||||
constraints: Vec<Constraint>,
|
constraints: Vec<Constraint>,
|
||||||
types: Vec<Type>,
|
types: Vec<Type>,
|
||||||
variables: Vec<Variable>,
|
variables: Vec<Variable>,
|
||||||
def_types: Vec<(Symbol, Located<Index<Type>>)>,
|
def_types: Vec<(Symbol, Loc<Index<Type>>)>,
|
||||||
let_constraints: Vec<LetConstraint>,
|
let_constraints: Vec<LetConstraint>,
|
||||||
categories: Vec<Category>,
|
categories: Vec<Category>,
|
||||||
pattern_categories: Vec<PatternCategory>,
|
pattern_categories: Vec<PatternCategory>,
|
||||||
|
@ -18,6 +18,26 @@ pub struct Constraints {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Constraints {
|
impl Constraints {
|
||||||
|
pub const EMPTY_RECORD: Index<Type> = Index::new(0);
|
||||||
|
pub const EMPTY_TAG_UNION: Index<Type> = Index::new(1);
|
||||||
|
|
||||||
|
pub const CATEGORY_RECORD: Index<Category> = Index::new(0);
|
||||||
|
|
||||||
|
pub fn push_type(&mut self, typ: Type) -> Index<Type> {
|
||||||
|
match typ {
|
||||||
|
Type::EmptyRec => Self::EMPTY_RECORD,
|
||||||
|
Type::EmptyTagUnion => Self::EMPTY_TAG_UNION,
|
||||||
|
other => Index::push_new(&mut self.types, other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push_category(&mut self, category: Category) -> Index<Category> {
|
||||||
|
match category {
|
||||||
|
Category::Record => Self::CATEGORY_RECORD,
|
||||||
|
other => Index::push_new(&mut self.categories, other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn equal_types(
|
pub fn equal_types(
|
||||||
&mut self,
|
&mut self,
|
||||||
typ: Type,
|
typ: Type,
|
||||||
|
@ -65,19 +85,18 @@ impl Constraints {
|
||||||
Slice::new(start as _, length as _)
|
Slice::new(start as _, length as _)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn def_types_slice<I>(&mut self, it: I) -> Slice<(Symbol, Located<Type>)>
|
fn def_types_slice<I>(&mut self, it: I) -> Slice<(Symbol, Loc<Type>)>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (Symbol, Located<Type>)>,
|
I: IntoIterator<Item = (Symbol, Loc<Type>)>,
|
||||||
{
|
{
|
||||||
let start = self.def_types.len();
|
let start = self.def_types.len();
|
||||||
|
|
||||||
for (symbol, loc_type) in it {
|
for (symbol, loc_type) in it {
|
||||||
let type_index = Index::new(self.types.len() as _);
|
let type_index = Index::new(self.types.len() as _);
|
||||||
let Located { region, value } = loc_type;
|
let Loc { region, value } = loc_type;
|
||||||
self.types.push(value);
|
self.types.push(value);
|
||||||
|
|
||||||
self.def_types
|
self.def_types.push((symbol, Loc::at(region, type_index)));
|
||||||
.push((symbol, Located::at(region, type_index)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let length = self.def_types.len() - start;
|
let length = self.def_types.len() - start;
|
||||||
|
@ -118,7 +137,7 @@ impl Constraints {
|
||||||
where
|
where
|
||||||
I1: IntoIterator<Item = Variable>,
|
I1: IntoIterator<Item = Variable>,
|
||||||
I2: IntoIterator<Item = Variable>,
|
I2: IntoIterator<Item = Variable>,
|
||||||
I3: IntoIterator<Item = (Symbol, Located<Type>)>,
|
I3: IntoIterator<Item = (Symbol, Loc<Type>)>,
|
||||||
{
|
{
|
||||||
let defs_and_ret_constraint = Index::new(self.constraints.len() as _);
|
let defs_and_ret_constraint = Index::new(self.constraints.len() as _);
|
||||||
|
|
||||||
|
@ -163,60 +182,6 @@ pub enum Constraint {
|
||||||
pub struct LetConstraint {
|
pub struct LetConstraint {
|
||||||
pub rigid_vars: Slice<Variable>,
|
pub rigid_vars: Slice<Variable>,
|
||||||
pub flex_vars: Slice<Variable>,
|
pub flex_vars: Slice<Variable>,
|
||||||
pub def_types: Slice<(Symbol, Located<Type>)>,
|
pub def_types: Slice<(Symbol, Loc<Type>)>,
|
||||||
pub defs_and_ret_constraint: Index<(Constraint, Constraint)>,
|
pub defs_and_ret_constraint: Index<(Constraint, Constraint)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub struct Index<T> {
|
|
||||||
index: u32,
|
|
||||||
_marker: std::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Index<T> {
|
|
||||||
pub const fn new(index: u32) -> Self {
|
|
||||||
Self {
|
|
||||||
index,
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub struct Slice<T> {
|
|
||||||
start: u32,
|
|
||||||
length: u16,
|
|
||||||
_marker: std::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Default for Slice<T> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Slice<T> {
|
|
||||||
pub const fn new(start: u32, length: u16) -> Self {
|
|
||||||
Self {
|
|
||||||
start,
|
|
||||||
length,
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn len(&self) -> usize {
|
|
||||||
self.length as _
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn is_empty(&self) -> bool {
|
|
||||||
self.length == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn indices(&self) -> std::ops::Range<usize> {
|
|
||||||
self.start as usize..(self.start as usize + self.length as usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_iter(&self) -> impl Iterator<Item = Index<T>> {
|
|
||||||
self.indices().map(|i| Index::new(i as _))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -161,13 +161,13 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
pub struct Index(usize);
|
pub struct HumanIndex(usize);
|
||||||
|
|
||||||
impl Index {
|
impl HumanIndex {
|
||||||
pub const FIRST: Self = Index(0);
|
pub const FIRST: Self = HumanIndex(0);
|
||||||
|
|
||||||
pub fn zero_based(i: usize) -> Self {
|
pub fn zero_based(i: usize) -> Self {
|
||||||
Index(i)
|
HumanIndex(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_zero_based(self) -> usize {
|
pub fn to_zero_based(self) -> usize {
|
||||||
|
@ -175,7 +175,7 @@ impl Index {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn one_based(i: usize) -> Self {
|
pub fn one_based(i: usize) -> Self {
|
||||||
Index(i - 1)
|
HumanIndex(i - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ordinal(self) -> std::string::String {
|
pub fn ordinal(self) -> std::string::String {
|
||||||
|
|
|
@ -3,3 +3,4 @@
|
||||||
#![allow(clippy::large_enum_variant)]
|
#![allow(clippy::large_enum_variant)]
|
||||||
|
|
||||||
pub mod all;
|
pub mod all;
|
||||||
|
pub mod soa;
|
||||||
|
|
|
@ -11,6 +11,14 @@ impl<T> Index<T> {
|
||||||
_marker: std::marker::PhantomData,
|
_marker: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn push_new(vector: &mut Vec<T>, value: T) -> Index<T> {
|
||||||
|
let index = Self::new(vector.len() as _);
|
||||||
|
|
||||||
|
vector.push(value);
|
||||||
|
|
||||||
|
index
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
@ -20,6 +28,16 @@ pub struct Slice<T> {
|
||||||
_marker: std::marker::PhantomData<T>,
|
_marker: std::marker::PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Default for Slice<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
start: Default::default(),
|
||||||
|
length: Default::default(),
|
||||||
|
_marker: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Slice<T> {
|
impl<T> Slice<T> {
|
||||||
pub const fn new(start: u32, length: u16) -> Self {
|
pub const fn new(start: u32, length: u16) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use roc_can::expected::PExpected;
|
||||||
use roc_can::expr::Expr::{self, *};
|
use roc_can::expr::Expr::{self, *};
|
||||||
use roc_can::expr::{ClosureData, Field, WhenBranch};
|
use roc_can::expr::{ClosureData, Field, WhenBranch};
|
||||||
use roc_can::pattern::Pattern;
|
use roc_can::pattern::Pattern;
|
||||||
use roc_collections::all::{ImMap, Index, MutSet, SendMap};
|
use roc_collections::all::{HumanIndex, ImMap, MutSet, SendMap};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
@ -229,7 +229,7 @@ pub fn constrain_expr(
|
||||||
for (index, loc_elem) in loc_elems.iter().enumerate() {
|
for (index, loc_elem) in loc_elems.iter().enumerate() {
|
||||||
let elem_expected = ForReason(
|
let elem_expected = ForReason(
|
||||||
Reason::ElemInList {
|
Reason::ElemInList {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
list_elem_type.clone(),
|
list_elem_type.clone(),
|
||||||
loc_elem.region,
|
loc_elem.region,
|
||||||
|
@ -293,7 +293,7 @@ pub fn constrain_expr(
|
||||||
|
|
||||||
let reason = Reason::FnArg {
|
let reason = Reason::FnArg {
|
||||||
name: opt_symbol,
|
name: opt_symbol,
|
||||||
arg_index: Index::zero_based(index),
|
arg_index: HumanIndex::zero_based(index),
|
||||||
};
|
};
|
||||||
let expected_arg = ForReason(reason, arg_type.clone(), region);
|
let expected_arg = ForReason(reason, arg_type.clone(), region);
|
||||||
let arg_con = constrain_expr(env, loc_arg.region, &loc_arg.value, expected_arg);
|
let arg_con = constrain_expr(env, loc_arg.region, &loc_arg.value, expected_arg);
|
||||||
|
@ -462,7 +462,7 @@ pub fn constrain_expr(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
arity,
|
arity,
|
||||||
AnnotationSource::TypedIfBranch {
|
AnnotationSource::TypedIfBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
num_branches,
|
num_branches,
|
||||||
region: ann_source.region(),
|
region: ann_source.region(),
|
||||||
},
|
},
|
||||||
|
@ -482,7 +482,7 @@ pub fn constrain_expr(
|
||||||
name,
|
name,
|
||||||
arity,
|
arity,
|
||||||
AnnotationSource::TypedIfBranch {
|
AnnotationSource::TypedIfBranch {
|
||||||
index: Index::zero_based(branches.len()),
|
index: HumanIndex::zero_based(branches.len()),
|
||||||
num_branches,
|
num_branches,
|
||||||
region: ann_source.region(),
|
region: ann_source.region(),
|
||||||
},
|
},
|
||||||
|
@ -517,7 +517,7 @@ pub fn constrain_expr(
|
||||||
&loc_body.value,
|
&loc_body.value,
|
||||||
ForReason(
|
ForReason(
|
||||||
Reason::IfBranch {
|
Reason::IfBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
total_branches: branches.len(),
|
total_branches: branches.len(),
|
||||||
},
|
},
|
||||||
Type::Variable(*branch_var),
|
Type::Variable(*branch_var),
|
||||||
|
@ -534,7 +534,7 @@ pub fn constrain_expr(
|
||||||
&final_else.value,
|
&final_else.value,
|
||||||
ForReason(
|
ForReason(
|
||||||
Reason::IfBranch {
|
Reason::IfBranch {
|
||||||
index: Index::zero_based(branches.len()),
|
index: HumanIndex::zero_based(branches.len()),
|
||||||
total_branches: branches.len() + 1,
|
total_branches: branches.len() + 1,
|
||||||
},
|
},
|
||||||
Type::Variable(*branch_var),
|
Type::Variable(*branch_var),
|
||||||
|
@ -592,7 +592,7 @@ pub fn constrain_expr(
|
||||||
when_branch,
|
when_branch,
|
||||||
PExpected::ForReason(
|
PExpected::ForReason(
|
||||||
PReason::WhenMatch {
|
PReason::WhenMatch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
cond_type.clone(),
|
cond_type.clone(),
|
||||||
pattern_region,
|
pattern_region,
|
||||||
|
@ -601,7 +601,7 @@ pub fn constrain_expr(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
*arity,
|
*arity,
|
||||||
AnnotationSource::TypedWhenBranch {
|
AnnotationSource::TypedWhenBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
region: ann_source.region(),
|
region: ann_source.region(),
|
||||||
},
|
},
|
||||||
typ.clone(),
|
typ.clone(),
|
||||||
|
@ -629,14 +629,14 @@ pub fn constrain_expr(
|
||||||
when_branch,
|
when_branch,
|
||||||
PExpected::ForReason(
|
PExpected::ForReason(
|
||||||
PReason::WhenMatch {
|
PReason::WhenMatch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
cond_type.clone(),
|
cond_type.clone(),
|
||||||
pattern_region,
|
pattern_region,
|
||||||
),
|
),
|
||||||
ForReason(
|
ForReason(
|
||||||
Reason::WhenBranch {
|
Reason::WhenBranch {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
branch_type.clone(),
|
branch_type.clone(),
|
||||||
when_branch.value.region,
|
when_branch.value.region,
|
||||||
|
@ -1007,7 +1007,7 @@ pub fn constrain_expr(
|
||||||
let mut add_arg = |index, arg_type: Type, arg| {
|
let mut add_arg = |index, arg_type: Type, arg| {
|
||||||
let reason = Reason::LowLevelOpArg {
|
let reason = Reason::LowLevelOpArg {
|
||||||
op: *op,
|
op: *op,
|
||||||
arg_index: Index::zero_based(index),
|
arg_index: HumanIndex::zero_based(index),
|
||||||
};
|
};
|
||||||
let expected_arg = ForReason(reason, arg_type.clone(), Region::zero());
|
let expected_arg = ForReason(reason, arg_type.clone(), Region::zero());
|
||||||
let arg_con = constrain_expr(env, Region::zero(), arg, expected_arg);
|
let arg_con = constrain_expr(env, Region::zero(), arg, expected_arg);
|
||||||
|
@ -1053,7 +1053,7 @@ pub fn constrain_expr(
|
||||||
let mut add_arg = |index, arg_type: Type, arg| {
|
let mut add_arg = |index, arg_type: Type, arg| {
|
||||||
let reason = Reason::ForeignCallArg {
|
let reason = Reason::ForeignCallArg {
|
||||||
foreign_symbol: foreign_symbol.clone(),
|
foreign_symbol: foreign_symbol.clone(),
|
||||||
arg_index: Index::zero_based(index),
|
arg_index: HumanIndex::zero_based(index),
|
||||||
};
|
};
|
||||||
let expected_arg = ForReason(reason, arg_type.clone(), Region::zero());
|
let expected_arg = ForReason(reason, arg_type.clone(), Region::zero());
|
||||||
let arg_con = constrain_expr(env, Region::zero(), arg, expected_arg);
|
let arg_con = constrain_expr(env, Region::zero(), arg, expected_arg);
|
||||||
|
@ -1320,7 +1320,7 @@ fn constrain_def(env: &Env, def: &Def, body_con: Constraint) -> Constraint {
|
||||||
|
|
||||||
let pattern_expected = PExpected::ForReason(
|
let pattern_expected = PExpected::ForReason(
|
||||||
PReason::TypedArg {
|
PReason::TypedArg {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
opt_name: opt_label,
|
opt_name: opt_label,
|
||||||
},
|
},
|
||||||
pattern_type.clone(),
|
pattern_type.clone(),
|
||||||
|
@ -1687,7 +1687,7 @@ pub fn rec_defs_help(
|
||||||
|
|
||||||
let pattern_expected = PExpected::ForReason(
|
let pattern_expected = PExpected::ForReason(
|
||||||
PReason::TypedArg {
|
PReason::TypedArg {
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
opt_name: opt_label,
|
opt_name: opt_label,
|
||||||
},
|
},
|
||||||
pattern_type.clone(),
|
pattern_type.clone(),
|
||||||
|
|
|
@ -5,3 +5,4 @@ pub mod builtins;
|
||||||
pub mod expr;
|
pub mod expr;
|
||||||
pub mod module;
|
pub mod module;
|
||||||
pub mod pattern;
|
pub mod pattern;
|
||||||
|
pub mod soa_expr;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use roc_can::constraint::{Constraint, PresenceConstraint};
|
||||||
use roc_can::expected::{Expected, PExpected};
|
use roc_can::expected::{Expected, PExpected};
|
||||||
use roc_can::pattern::Pattern::{self, *};
|
use roc_can::pattern::Pattern::{self, *};
|
||||||
use roc_can::pattern::{DestructType, RecordDestruct};
|
use roc_can::pattern::{DestructType, RecordDestruct};
|
||||||
use roc_collections::all::{Index, SendMap};
|
use roc_collections::all::{HumanIndex, SendMap};
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
@ -412,7 +412,7 @@ pub fn constrain_pattern(
|
||||||
let expected = PExpected::ForReason(
|
let expected = PExpected::ForReason(
|
||||||
PReason::TagArg {
|
PReason::TagArg {
|
||||||
tag_name: tag_name.clone(),
|
tag_name: tag_name.clone(),
|
||||||
index: Index::zero_based(index),
|
index: HumanIndex::zero_based(index),
|
||||||
},
|
},
|
||||||
pattern_type,
|
pattern_type,
|
||||||
region,
|
region,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use roc_collections::all::{Index, MutMap};
|
use roc_collections::all::{HumanIndex, MutMap};
|
||||||
use roc_module::ident::{Lowercase, TagIdIntType, TagName};
|
use roc_module::ident::{Lowercase, TagIdIntType, TagName};
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
use roc_std::RocDec;
|
use roc_std::RocDec;
|
||||||
|
@ -70,7 +70,7 @@ pub enum Error {
|
||||||
Redundant {
|
Redundant {
|
||||||
overall_region: Region,
|
overall_region: Region,
|
||||||
branch_region: Region,
|
branch_region: Region,
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::ir::DestructType;
|
use crate::ir::DestructType;
|
||||||
use roc_collections::all::Index;
|
use roc_collections::all::HumanIndex;
|
||||||
use roc_exhaustive::{
|
use roc_exhaustive::{
|
||||||
is_useful, Context, Ctor, Error, Guard, Literal, Pattern, RenderAs, TagId, Union,
|
is_useful, Context, Ctor, Error, Guard, Literal, Pattern, RenderAs, TagId, Union,
|
||||||
};
|
};
|
||||||
|
@ -189,7 +189,7 @@ fn to_nonredundant_rows(
|
||||||
return Err(Error::Redundant {
|
return Err(Error::Redundant {
|
||||||
overall_region,
|
overall_region,
|
||||||
branch_region: region,
|
branch_region: region,
|
||||||
index: Index::zero_based(checked_rows.len()),
|
index: HumanIndex::zero_based(checked_rows.len()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::pretty_print::Parens;
|
||||||
use crate::subs::{
|
use crate::subs::{
|
||||||
GetSubsSlice, RecordFields, Subs, UnionTags, VarStore, Variable, VariableSubsSlice,
|
GetSubsSlice, RecordFields, Subs, UnionTags, VarStore, Variable, VariableSubsSlice,
|
||||||
};
|
};
|
||||||
use roc_collections::all::{ImMap, ImSet, Index, MutSet, SendMap};
|
use roc_collections::all::{HumanIndex, ImMap, ImSet, MutSet, SendMap};
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
use roc_module::called_via::CalledVia;
|
use roc_module::called_via::CalledVia;
|
||||||
use roc_module::ident::{ForeignSymbol, Ident, Lowercase, TagName};
|
use roc_module::ident::{ForeignSymbol, Ident, Lowercase, TagName};
|
||||||
|
@ -1203,14 +1203,14 @@ pub struct TagUnionStructure<'a> {
|
||||||
pub enum PReason {
|
pub enum PReason {
|
||||||
TypedArg {
|
TypedArg {
|
||||||
opt_name: Option<Symbol>,
|
opt_name: Option<Symbol>,
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
},
|
},
|
||||||
WhenMatch {
|
WhenMatch {
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
},
|
},
|
||||||
TagArg {
|
TagArg {
|
||||||
tag_name: TagName,
|
tag_name: TagName,
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
},
|
},
|
||||||
PatternGuard,
|
PatternGuard,
|
||||||
OptionalField,
|
OptionalField,
|
||||||
|
@ -1219,12 +1219,12 @@ pub enum PReason {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum AnnotationSource {
|
pub enum AnnotationSource {
|
||||||
TypedIfBranch {
|
TypedIfBranch {
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
num_branches: usize,
|
num_branches: usize,
|
||||||
region: Region,
|
region: Region,
|
||||||
},
|
},
|
||||||
TypedWhenBranch {
|
TypedWhenBranch {
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
region: Region,
|
region: Region,
|
||||||
},
|
},
|
||||||
TypedBody {
|
TypedBody {
|
||||||
|
@ -1246,7 +1246,7 @@ impl AnnotationSource {
|
||||||
pub enum Reason {
|
pub enum Reason {
|
||||||
FnArg {
|
FnArg {
|
||||||
name: Option<Symbol>,
|
name: Option<Symbol>,
|
||||||
arg_index: Index,
|
arg_index: HumanIndex,
|
||||||
},
|
},
|
||||||
FnCall {
|
FnCall {
|
||||||
name: Option<Symbol>,
|
name: Option<Symbol>,
|
||||||
|
@ -1254,28 +1254,28 @@ pub enum Reason {
|
||||||
},
|
},
|
||||||
LowLevelOpArg {
|
LowLevelOpArg {
|
||||||
op: LowLevel,
|
op: LowLevel,
|
||||||
arg_index: Index,
|
arg_index: HumanIndex,
|
||||||
},
|
},
|
||||||
ForeignCallArg {
|
ForeignCallArg {
|
||||||
foreign_symbol: ForeignSymbol,
|
foreign_symbol: ForeignSymbol,
|
||||||
arg_index: Index,
|
arg_index: HumanIndex,
|
||||||
},
|
},
|
||||||
FloatLiteral,
|
FloatLiteral,
|
||||||
IntLiteral,
|
IntLiteral,
|
||||||
NumLiteral,
|
NumLiteral,
|
||||||
StrInterpolation,
|
StrInterpolation,
|
||||||
WhenBranch {
|
WhenBranch {
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
},
|
},
|
||||||
WhenGuard,
|
WhenGuard,
|
||||||
ExpectCondition,
|
ExpectCondition,
|
||||||
IfCondition,
|
IfCondition,
|
||||||
IfBranch {
|
IfBranch {
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
total_branches: usize,
|
total_branches: usize,
|
||||||
},
|
},
|
||||||
ElemInList {
|
ElemInList {
|
||||||
index: Index,
|
index: HumanIndex,
|
||||||
},
|
},
|
||||||
RecordUpdateValue(Lowercase),
|
RecordUpdateValue(Lowercase),
|
||||||
RecordUpdateKeys(Symbol, SendMap<Lowercase, Region>),
|
RecordUpdateKeys(Symbol, SendMap<Lowercase, Region>),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use roc_can::expected::{Expected, PExpected};
|
use roc_can::expected::{Expected, PExpected};
|
||||||
use roc_collections::all::{Index, MutSet, SendMap};
|
use roc_collections::all::{HumanIndex, MutSet, SendMap};
|
||||||
use roc_module::called_via::{BinOp, CalledVia};
|
use roc_module::called_via::{BinOp, CalledVia};
|
||||||
use roc_module::ident::{Ident, IdentStr, Lowercase, TagName};
|
use roc_module::ident::{Ident, IdentStr, Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
|
@ -350,7 +350,7 @@ fn to_expr_report<'b>(
|
||||||
num_branches,
|
num_branches,
|
||||||
..
|
..
|
||||||
} if num_branches == 2 => alloc.concat(vec![
|
} if num_branches == 2 => alloc.concat(vec![
|
||||||
alloc.keyword(if index == Index::FIRST {
|
alloc.keyword(if index == HumanIndex::FIRST {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
"else"
|
"else"
|
||||||
|
@ -1384,7 +1384,7 @@ fn to_pattern_report<'b>(
|
||||||
found,
|
found,
|
||||||
expected_type,
|
expected_type,
|
||||||
add_pattern_category(
|
add_pattern_category(
|
||||||
alloc,
|
HumanIndexlloc,
|
||||||
alloc.text("The first pattern is trying to match"),
|
alloc.text("The first pattern is trying to match"),
|
||||||
&category,
|
&category,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue