mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Unify let-introduction in a single path
Remove branches on determining how let-bindings are introduced to the scope. This is maybe a little more inefficient, but I think it is a huge simplification. One additional change this required was changing how fx suffixes are checked. The current implementation would add additional constraints for patterns in let bindings conditionally. However, this is unnecessary. I believe it is sufficient to check the fx suffix by running the checks on all introduced symbols after the type is well known (i.e. the body is checked).
This commit is contained in:
parent
bd2dd66c96
commit
54cc5e4c29
4 changed files with 102 additions and 223 deletions
|
@ -6,7 +6,7 @@ use roc_can::pattern::Pattern::{self, *};
|
|||
use roc_can::pattern::{DestructType, ListPatterns, RecordDestruct, TupleDestruct};
|
||||
use roc_collections::all::{HumanIndex, SendMap};
|
||||
use roc_collections::VecMap;
|
||||
use roc_module::ident::{IdentSuffix, Lowercase};
|
||||
use roc_module::ident::Lowercase;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::subs::Variable;
|
||||
|
@ -249,16 +249,7 @@ pub fn constrain_pattern(
|
|||
expected: PExpectedTypeIndex,
|
||||
state: &mut PatternState,
|
||||
) {
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
pattern,
|
||||
region,
|
||||
expected,
|
||||
state,
|
||||
true,
|
||||
);
|
||||
constrain_pattern_help(types, constraints, env, pattern, region, expected, state);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
@ -270,7 +261,6 @@ pub fn constrain_pattern_help(
|
|||
region: Region,
|
||||
expected: PExpectedTypeIndex,
|
||||
state: &mut PatternState,
|
||||
is_shallow: bool,
|
||||
) {
|
||||
match pattern {
|
||||
Underscore => {
|
||||
|
@ -300,27 +290,6 @@ pub fn constrain_pattern_help(
|
|||
.push(constraints.is_open_type(type_index));
|
||||
}
|
||||
|
||||
// Identifiers introduced in nested patterns get let constraints
|
||||
// and therefore don't need fx_pattern_suffix constraints.
|
||||
if is_shallow {
|
||||
match symbol.suffix() {
|
||||
IdentSuffix::None => {
|
||||
// Unsuffixed identifiers should be constrained after we know if they're functions
|
||||
state
|
||||
.delayed_fx_suffix_constraints
|
||||
.push(constraints.fx_pattern_suffix(*symbol, type_index, region));
|
||||
}
|
||||
IdentSuffix::Bang => {
|
||||
// Bang suffixed identifiers are always required to be functions
|
||||
// We constrain this before the function's body,
|
||||
// so that we don't think it's pure and complain about leftover statements
|
||||
state
|
||||
.constraints
|
||||
.push(constraints.fx_pattern_suffix(*symbol, type_index, region));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.headers.insert(
|
||||
*symbol,
|
||||
Loc {
|
||||
|
@ -350,7 +319,6 @@ pub fn constrain_pattern_help(
|
|||
subpattern.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -584,7 +552,6 @@ pub fn constrain_pattern_help(
|
|||
loc_pattern.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
|
||||
pat_type
|
||||
|
@ -683,7 +650,6 @@ pub fn constrain_pattern_help(
|
|||
loc_guard.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
|
||||
RecordField::Demanded(pat_type)
|
||||
|
@ -807,7 +773,6 @@ pub fn constrain_pattern_help(
|
|||
loc_pat.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -864,7 +829,6 @@ pub fn constrain_pattern_help(
|
|||
loc_pattern.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -930,7 +894,6 @@ pub fn constrain_pattern_help(
|
|||
loc_arg_pattern.region,
|
||||
arg_pattern_expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
|
||||
// Next, link `whole_var` to the opaque type of "@Id who"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue