Properly remove aliases from exposed_symbols

This commit is contained in:
Richard Feldman 2020-02-11 20:54:23 -05:00
parent 8eb91807e4
commit 0e6b75bc1c
2 changed files with 13 additions and 11 deletions

View File

@ -100,7 +100,7 @@ pub fn canonicalize_module_defs<'a>(
} }
} }
let (defs, populated_scope, output) = canonicalize_defs( let (defs, scope, output) = canonicalize_defs(
&mut env, &mut env,
Output::default(), Output::default(),
var_store, var_store,
@ -155,13 +155,21 @@ pub fn canonicalize_module_defs<'a>(
} }
} }
for (symbol, _alias) in scope.aliases() { let mut aliases = MutMap::default();
for (symbol, alias) in scope.into_aliases() {
// Remove this from exposed_symbols, // Remove this from exposed_symbols,
// so that at the end of the process, // so that at the end of the process,
// we can see if there were any // we can see if there were any
// exposed symbols which did not have // exposed symbols which did not have
// corresponding defs. // corresponding defs.
exposed_symbols.remove(symbol); exposed_symbols.remove(&symbol);
// TODO store aliases as a MutMap inside Scope
// (and manually remove them when exiting a scope)
// and we can use it directly instead of rebuilding it
// piece by piece like this.
aliases.insert(symbol, alias);
} }
// By this point, all exposed symbols should have been removed from // By this point, all exposed symbols should have been removed from
@ -180,12 +188,6 @@ pub fn canonicalize_module_defs<'a>(
references.insert(symbol); references.insert(symbol);
} }
let mut aliases = MutMap::default();
for (symbol, alias) in populated_scope.aliases() {
aliases.insert(*symbol, alias.clone());
}
Ok(ModuleOutput { Ok(ModuleOutput {
aliases, aliases,
declarations, declarations,

View File

@ -42,8 +42,8 @@ impl Scope {
self.symbols.iter() self.symbols.iter()
} }
pub fn aliases(&self) -> impl Iterator<Item = &(Symbol, Alias)> { pub fn into_aliases(self) -> ImMap<Symbol, Alias> {
self.aliases.iter() self.aliases
} }
pub fn contains_ident(&self, ident: &Ident) -> bool { pub fn contains_ident(&self, ident: &Ident) -> bool {