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

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

View file

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

View file

@ -2,13 +2,43 @@ use roc_module::symbol::Symbol;
use roc_types::subs::Variable;
/// The scope of the solver, as symbols are introduced.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct Scope {
symbols: Vec<Symbol>,
variables: Vec<Variable>,
}
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)> + '_ {
let it1 = self.symbols.iter().copied();
let it2 = self.variables.iter().copied();