mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Treat untyped unsuffixed functions as pure
This commit is contained in:
parent
70fa4d036c
commit
af6fc6306f
5 changed files with 186 additions and 24 deletions
|
@ -22,6 +22,7 @@ pub struct PatternState {
|
|||
pub vars: Vec<Variable>,
|
||||
pub constraints: Vec<Constraint>,
|
||||
pub delayed_is_open_constraints: Vec<Constraint>,
|
||||
pub delayed_fx_suffix_constraints: Vec<Constraint>,
|
||||
}
|
||||
|
||||
/// If there is a type annotation, the pattern state headers can be optimized by putting the
|
||||
|
@ -247,6 +248,28 @@ pub fn constrain_pattern(
|
|||
region: Region,
|
||||
expected: PExpectedTypeIndex,
|
||||
state: &mut PatternState,
|
||||
) {
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
pattern,
|
||||
region,
|
||||
expected,
|
||||
state,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn constrain_pattern_help(
|
||||
types: &mut Types,
|
||||
constraints: &mut Constraints,
|
||||
env: &mut Env,
|
||||
pattern: &Pattern,
|
||||
region: Region,
|
||||
expected: PExpectedTypeIndex,
|
||||
state: &mut PatternState,
|
||||
is_shallow: bool,
|
||||
) {
|
||||
match pattern {
|
||||
Underscore => {
|
||||
|
@ -276,9 +299,13 @@ pub fn constrain_pattern(
|
|||
.push(constraints.is_open_type(type_index));
|
||||
}
|
||||
|
||||
state
|
||||
.constraints
|
||||
.push(constraints.fx_pattern_suffix(*symbol, type_index, region));
|
||||
if is_shallow {
|
||||
// Identifiers introduced in nested patterns get let constraints
|
||||
// and therefore don't need fx_pattern_suffix constraints.
|
||||
state
|
||||
.delayed_fx_suffix_constraints
|
||||
.push(constraints.fx_pattern_suffix(*symbol, type_index, region));
|
||||
}
|
||||
|
||||
state.headers.insert(
|
||||
*symbol,
|
||||
|
@ -301,7 +328,7 @@ pub fn constrain_pattern(
|
|||
},
|
||||
);
|
||||
|
||||
constrain_pattern(
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
|
@ -309,6 +336,7 @@ pub fn constrain_pattern(
|
|||
subpattern.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -534,7 +562,7 @@ pub fn constrain_pattern(
|
|||
));
|
||||
state.vars.push(*guard_var);
|
||||
|
||||
constrain_pattern(
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
|
@ -542,6 +570,7 @@ pub fn constrain_pattern(
|
|||
loc_pattern.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
|
||||
pat_type
|
||||
|
@ -632,7 +661,7 @@ pub fn constrain_pattern(
|
|||
));
|
||||
state.vars.push(*guard_var);
|
||||
|
||||
constrain_pattern(
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
|
@ -640,6 +669,7 @@ pub fn constrain_pattern(
|
|||
loc_guard.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
|
||||
RecordField::Demanded(pat_type)
|
||||
|
@ -755,7 +785,7 @@ pub fn constrain_pattern(
|
|||
loc_pat.region,
|
||||
));
|
||||
|
||||
constrain_pattern(
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
|
@ -763,6 +793,7 @@ pub fn constrain_pattern(
|
|||
loc_pat.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -811,7 +842,7 @@ pub fn constrain_pattern(
|
|||
pattern_type,
|
||||
region,
|
||||
));
|
||||
constrain_pattern(
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
|
@ -819,6 +850,7 @@ pub fn constrain_pattern(
|
|||
loc_pattern.region,
|
||||
expected,
|
||||
state,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -876,7 +908,7 @@ pub fn constrain_pattern(
|
|||
// First, add a constraint for the argument "who"
|
||||
let arg_pattern_expected = constraints
|
||||
.push_pat_expected_type(PExpected::NoExpectation(arg_pattern_type_index));
|
||||
constrain_pattern(
|
||||
constrain_pattern_help(
|
||||
types,
|
||||
constraints,
|
||||
env,
|
||||
|
@ -884,6 +916,7 @@ pub fn constrain_pattern(
|
|||
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