Use exists_with_aliases more

This commit is contained in:
Richard Feldman 2020-02-21 18:02:28 -08:00
parent 396f4c0f18
commit 3d7ad71270
3 changed files with 37 additions and 17 deletions

View File

@ -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"),

View File

@ -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)]

View File

@ -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,