mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Use exists_with_aliases more
This commit is contained in:
parent
396f4c0f18
commit
3d7ad71270
@ -680,29 +680,42 @@ fn constrain_empty_record(region: Region, expected: Expected<Type>) -> Constrain
|
||||
|
||||
/// Constrain top-level module declarations
|
||||
#[inline(always)]
|
||||
pub fn constrain_decls(home: ModuleId, decls: &[Declaration]) -> Constraint {
|
||||
pub fn constrain_decls(
|
||||
home: ModuleId,
|
||||
decls: &[Declaration],
|
||||
aliases: SendMap<Symbol, Alias>,
|
||||
) -> Constraint {
|
||||
let mut constraint = Constraint::SaveTheEnvironment;
|
||||
|
||||
for decl in decls.iter().rev() {
|
||||
// NOTE: rigids are empty because they are not shared between top-level definitions
|
||||
match decl {
|
||||
Declaration::Declare(def) => {
|
||||
constraint = constrain_def(
|
||||
&Env {
|
||||
home,
|
||||
rigids: ImMap::default(),
|
||||
},
|
||||
def,
|
||||
constraint,
|
||||
constraint = exists_with_aliases(
|
||||
aliases.clone(),
|
||||
Vec::new(),
|
||||
constrain_def(
|
||||
&Env {
|
||||
home,
|
||||
rigids: ImMap::default(),
|
||||
},
|
||||
def,
|
||||
constraint,
|
||||
),
|
||||
);
|
||||
}
|
||||
Declaration::DeclareRec(defs) => {
|
||||
constraint = constrain_recursive_defs(
|
||||
&Env {
|
||||
home,
|
||||
rigids: ImMap::default(),
|
||||
},
|
||||
defs,
|
||||
constraint,
|
||||
constraint = exists_with_aliases(
|
||||
aliases.clone(),
|
||||
Vec::new(),
|
||||
constrain_recursive_defs(
|
||||
&Env {
|
||||
home,
|
||||
rigids: ImMap::default(),
|
||||
},
|
||||
defs,
|
||||
constraint,
|
||||
),
|
||||
);
|
||||
}
|
||||
Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"),
|
||||
|
@ -12,8 +12,15 @@ use crate::types::{Alias, Constraint, LetConstraint, Type};
|
||||
pub fn constrain_module(
|
||||
home: ModuleId,
|
||||
decls: &[Declaration],
|
||||
aliases: &MutMap<Symbol, Alias>,
|
||||
) -> Constraint {
|
||||
constrain_decls(home, &decls)
|
||||
let mut send_aliases = SendMap::default();
|
||||
|
||||
for (symbol, alias) in aliases {
|
||||
send_aliases.insert(*symbol, alias.clone());
|
||||
}
|
||||
|
||||
constrain_decls(home, decls, send_aliases)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -1014,7 +1014,7 @@ fn parse_and_constrain(
|
||||
problems,
|
||||
..
|
||||
}) => {
|
||||
let constraint = constrain_module(module_id, &declarations);
|
||||
let constraint = constrain_module(module_id, &declarations, &aliases);
|
||||
let module = Module {
|
||||
module_id,
|
||||
declarations,
|
||||
|
Loading…
Reference in New Issue
Block a user