Add module param identifiers to solve's scope

This commit is contained in:
Agus Zubiaga 2024-05-30 20:11:51 -03:00
parent 717463079a
commit dd0e28240a
No known key found for this signature in database
6 changed files with 45 additions and 3 deletions

View file

@ -51,6 +51,7 @@ pub fn infer_expr(
exposed_by_module: &Default::default(), exposed_by_module: &Default::default(),
derived_module, derived_module,
function_kind: FunctionKind::LambdaSet, function_kind: FunctionKind::LambdaSet,
params_pattern: None,
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
checkmate: None, checkmate: None,
}; };

View file

@ -4613,6 +4613,7 @@ fn run_solve_solve(
aliases, aliases,
rigid_variables, rigid_variables,
abilities_store: pending_abilities, abilities_store: pending_abilities,
params_pattern,
.. ..
} = module; } = module;
@ -4660,6 +4661,7 @@ fn run_solve_solve(
derived_module, derived_module,
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
checkmate, checkmate,
params_pattern: params_pattern.map(|(_, _, pattern)| pattern.value),
}; };
let solve_output = roc_solve::module::run_solve( let solve_output = roc_solve::module::run_solve(

View file

@ -80,6 +80,9 @@ pub struct SolveConfig<'a> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
/// The checkmate collector for this module. /// The checkmate collector for this module.
pub checkmate: Option<roc_checkmate::Collector>, pub checkmate: Option<roc_checkmate::Collector>,
/// Module params pattern
pub params_pattern: Option<roc_can::pattern::Pattern>,
} }
pub struct SolveOutput { pub struct SolveOutput {

View file

@ -129,15 +129,18 @@ fn run_help(
exposed_by_module, exposed_by_module,
derived_module, derived_module,
function_kind, function_kind,
params_pattern,
.. ..
} = config; } = config;
let mut pools = Pools::default(); let mut pools = Pools::default();
// todo(agus): Do we need state here?
let state = State { let state = State {
scope: Scope::default(), scope: Scope::new(None),
mark: Mark::NONE.next(), mark: Mark::NONE.next(),
}; };
let rank = Rank::toplevel(); let rank = Rank::toplevel();
let arena = Bump::new(); let arena = Bump::new();
@ -186,6 +189,7 @@ fn run_help(
abilities_store, abilities_store,
&mut obligation_cache, &mut obligation_cache,
&mut awaiting_specializations, &mut awaiting_specializations,
params_pattern,
); );
RunSolveOutput { RunSolveOutput {
@ -244,9 +248,10 @@ fn solve(
abilities_store: &mut AbilitiesStore, abilities_store: &mut AbilitiesStore,
obligation_cache: &mut ObligationCache, obligation_cache: &mut ObligationCache,
awaiting_specializations: &mut AwaitingSpecializations, awaiting_specializations: &mut AwaitingSpecializations,
params_pattern: Option<roc_can::pattern::Pattern>,
) -> State { ) -> State {
let initial = Work::Constraint { let initial = Work::Constraint {
scope: &Scope::default(), scope: &Scope::new(params_pattern),
rank, rank,
constraint, constraint,
}; };

View file

@ -2,13 +2,43 @@ use roc_module::symbol::Symbol;
use roc_types::subs::Variable; use roc_types::subs::Variable;
/// The scope of the solver, as symbols are introduced. /// The scope of the solver, as symbols are introduced.
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug)]
pub struct Scope { pub struct Scope {
symbols: Vec<Symbol>, symbols: Vec<Symbol>,
variables: Vec<Variable>, variables: Vec<Variable>,
} }
impl Scope { impl Scope {
pub fn new(params_pattern: Option<roc_can::pattern::Pattern>) -> Self {
match params_pattern {
Some(params_pattern) => match params_pattern {
roc_can::pattern::Pattern::RecordDestructure {
whole_var: _,
ext_var: _,
destructs,
} => {
let mut symbols = Vec::with_capacity(destructs.len());
let mut variables = Vec::with_capacity(destructs.len());
for destruct in destructs {
symbols.push(destruct.value.symbol);
variables.push(destruct.value.var);
}
Self { symbols, variables }
}
_ => unreachable!(
"other pattern types should have parsed: {:?}",
params_pattern
),
},
None => Self {
symbols: Vec::default(),
variables: Vec::default(),
},
}
}
pub fn vars_by_symbol(&self) -> impl Iterator<Item = (Symbol, Variable)> + '_ { pub fn vars_by_symbol(&self) -> impl Iterator<Item = (Symbol, Variable)> + '_ {
let it1 = self.symbols.iter().copied(); let it1 = self.symbols.iter().copied();
let it2 = self.variables.iter().copied(); let it2 = self.variables.iter().copied();

View file

@ -438,6 +438,7 @@ fn check_derived_typechecks_and_golden(
pending_derives: Default::default(), pending_derives: Default::default(),
exposed_by_module: &exposed_for_module.exposed_by_module, exposed_by_module: &exposed_for_module.exposed_by_module,
derived_module: Default::default(), derived_module: Default::default(),
params_pattern: None,
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
checkmate: None, checkmate: None,