mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Create can::module::ModuleParams for convenience
This commit is contained in:
parent
e80e3e5b2d
commit
519ff56a85
12 changed files with 164 additions and 137 deletions
|
@ -3,13 +3,12 @@ use crate::pattern::{constrain_pattern, PatternState};
|
|||
use roc_can::abilities::{PendingAbilitiesStore, PendingMemberType};
|
||||
use roc_can::constraint::{Constraint, Constraints, Generalizable};
|
||||
use roc_can::expected::{Expected, PExpected};
|
||||
use roc_can::expr::{AnnotatedMark, Declarations};
|
||||
use roc_can::expr::Declarations;
|
||||
use roc_can::module::ModuleParams;
|
||||
use roc_can::pattern::Pattern;
|
||||
use roc_collections::MutMap;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::subs::Variable;
|
||||
use roc_types::types::{AnnotationSource, Category, Type, Types};
|
||||
|
||||
pub fn constrain_module(
|
||||
|
@ -18,12 +17,12 @@ pub fn constrain_module(
|
|||
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
|
||||
abilities_store: &PendingAbilitiesStore,
|
||||
declarations: &Declarations,
|
||||
params_pattern: &Option<(Variable, AnnotatedMark, Loc<Pattern>)>,
|
||||
opt_module_params: &Option<ModuleParams>,
|
||||
home: ModuleId,
|
||||
) -> Constraint {
|
||||
let constraint = crate::expr::constrain_decls(types, constraints, home, declarations);
|
||||
|
||||
let constraint = match params_pattern {
|
||||
let constraint = match opt_module_params {
|
||||
Some(params_pattern) => {
|
||||
constrain_params(types, constraints, home, constraint, params_pattern)
|
||||
}
|
||||
|
@ -51,7 +50,7 @@ fn constrain_params(
|
|||
constraints: &mut Constraints,
|
||||
home: ModuleId,
|
||||
constraint: Constraint,
|
||||
(pattern_var, _, loc_pattern): &(Variable, AnnotatedMark, Loc<Pattern>),
|
||||
module_params: &ModuleParams,
|
||||
) -> Constraint {
|
||||
let mut env = Env {
|
||||
home,
|
||||
|
@ -59,23 +58,13 @@ fn constrain_params(
|
|||
resolutions_to_make: vec![],
|
||||
};
|
||||
|
||||
let index = constraints.push_variable(*pattern_var);
|
||||
let index = constraints.push_variable(module_params.whole_var);
|
||||
let expected_params = constraints.push_pat_expected_type(PExpected::NoExpectation(index));
|
||||
|
||||
let mut state = PatternState::default();
|
||||
|
||||
let closed_con = match loc_pattern.value {
|
||||
Pattern::RecordDestructure {
|
||||
whole_var: _,
|
||||
ext_var,
|
||||
destructs: _,
|
||||
} => {
|
||||
// Disallow record extension for module params
|
||||
let empty_rec = constraints.push_type(types, Types::EMPTY_RECORD);
|
||||
constraints.store(empty_rec, ext_var, file!(), line!())
|
||||
}
|
||||
_ => internal_error!("Only record destructures are allowed in module params. This should've been caught earlier."),
|
||||
};
|
||||
let empty_rec = constraints.push_type(types, Types::EMPTY_RECORD);
|
||||
let closed_con = constraints.store(empty_rec, module_params.record_ext_var, file!(), line!());
|
||||
|
||||
state.constraints.push(closed_con);
|
||||
|
||||
|
@ -83,8 +72,8 @@ fn constrain_params(
|
|||
types,
|
||||
constraints,
|
||||
&mut env,
|
||||
&loc_pattern.value,
|
||||
loc_pattern.region,
|
||||
&module_params.pattern().value,
|
||||
module_params.region,
|
||||
expected_params,
|
||||
&mut state,
|
||||
);
|
||||
|
@ -100,7 +89,7 @@ fn constrain_params(
|
|||
Generalizable(true),
|
||||
);
|
||||
|
||||
constraints.exists([*pattern_var], cons)
|
||||
constraints.exists([module_params.whole_var], cons)
|
||||
}
|
||||
|
||||
fn constrain_symbols_from_requires(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue