mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Contrain module params pattern
This commit is contained in:
parent
674adf1fad
commit
8f69e75a95
2 changed files with 55 additions and 2 deletions
|
@ -1,11 +1,14 @@
|
||||||
use crate::expr::{constrain_def_make_constraint, constrain_def_pattern, Env};
|
use crate::expr::{constrain_def_make_constraint, constrain_def_pattern, Env};
|
||||||
|
use crate::pattern::{constrain_pattern, PatternState};
|
||||||
use roc_can::abilities::{PendingAbilitiesStore, PendingMemberType};
|
use roc_can::abilities::{PendingAbilitiesStore, PendingMemberType};
|
||||||
use roc_can::constraint::{Constraint, Constraints, Generalizable};
|
use roc_can::constraint::{Constraint, Constraints, Generalizable};
|
||||||
use roc_can::expected::Expected;
|
use roc_can::expected::{Expected, PExpected};
|
||||||
use roc_can::expr::Declarations;
|
use roc_can::expr::{AnnotatedMark, Declarations};
|
||||||
use roc_can::pattern::Pattern;
|
use roc_can::pattern::Pattern;
|
||||||
|
use roc_collections::MutMap;
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
use roc_types::subs::Variable;
|
||||||
use roc_types::types::{AnnotationSource, Category, Type, Types};
|
use roc_types::types::{AnnotationSource, Category, Type, Types};
|
||||||
|
|
||||||
pub fn constrain_module(
|
pub fn constrain_module(
|
||||||
|
@ -14,9 +17,18 @@ pub fn constrain_module(
|
||||||
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
|
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
|
||||||
abilities_store: &PendingAbilitiesStore,
|
abilities_store: &PendingAbilitiesStore,
|
||||||
declarations: &Declarations,
|
declarations: &Declarations,
|
||||||
|
params_pattern: &Option<(Variable, AnnotatedMark, Loc<Pattern>)>,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
let constraint = crate::expr::constrain_decls(types, constraints, home, declarations);
|
let constraint = crate::expr::constrain_decls(types, constraints, home, declarations);
|
||||||
|
|
||||||
|
let constraint = match params_pattern {
|
||||||
|
Some(params_pattern) => {
|
||||||
|
constrain_params(types, constraints, home, constraint, params_pattern)
|
||||||
|
}
|
||||||
|
None => constraint,
|
||||||
|
};
|
||||||
|
|
||||||
let constraint = constrain_symbols_from_requires(
|
let constraint = constrain_symbols_from_requires(
|
||||||
types,
|
types,
|
||||||
constraints,
|
constraints,
|
||||||
|
@ -33,6 +45,46 @@ pub fn constrain_module(
|
||||||
constraint
|
constraint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn constrain_params(
|
||||||
|
types: &mut Types,
|
||||||
|
constraints: &mut Constraints,
|
||||||
|
home: ModuleId,
|
||||||
|
constraint: Constraint,
|
||||||
|
(pattern_var, _, loc_pattern): &(Variable, AnnotatedMark, Loc<Pattern>),
|
||||||
|
) -> Constraint {
|
||||||
|
let mut env = Env {
|
||||||
|
home,
|
||||||
|
rigids: MutMap::default(),
|
||||||
|
resolutions_to_make: vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
let index = constraints.push_variable(*pattern_var);
|
||||||
|
let expected_params = constraints.push_pat_expected_type(PExpected::NoExpectation(index));
|
||||||
|
|
||||||
|
let mut state = PatternState::default();
|
||||||
|
|
||||||
|
constrain_pattern(
|
||||||
|
types,
|
||||||
|
constraints,
|
||||||
|
&mut env,
|
||||||
|
&loc_pattern.value,
|
||||||
|
loc_pattern.region,
|
||||||
|
expected_params,
|
||||||
|
&mut state,
|
||||||
|
);
|
||||||
|
|
||||||
|
let pattern_constraints = constraints.and_constraint(state.constraints);
|
||||||
|
|
||||||
|
constraints.let_constraint(
|
||||||
|
[],
|
||||||
|
state.vars,
|
||||||
|
state.headers,
|
||||||
|
pattern_constraints,
|
||||||
|
constraint,
|
||||||
|
Generalizable(true),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn constrain_symbols_from_requires(
|
fn constrain_symbols_from_requires(
|
||||||
types: &mut Types,
|
types: &mut Types,
|
||||||
constraints: &mut Constraints,
|
constraints: &mut Constraints,
|
||||||
|
|
|
@ -5065,6 +5065,7 @@ fn canonicalize_and_constrain<'a>(
|
||||||
module_output.symbols_from_requires,
|
module_output.symbols_from_requires,
|
||||||
&module_output.scope.abilities_store,
|
&module_output.scope.abilities_store,
|
||||||
&module_output.declarations,
|
&module_output.declarations,
|
||||||
|
&module_output.params_pattern,
|
||||||
module_id,
|
module_id,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue