Use Vec instead of VecMap for scope module sources

This commit is contained in:
Agus Zubiaga 2024-07-01 18:20:20 -03:00
parent 702092859e
commit 42c58d8efe
No known key found for this signature in database
2 changed files with 7 additions and 11 deletions

View file

@ -33,7 +33,6 @@ pub struct Scope {
pub modules: ScopeModules, pub modules: ScopeModules,
/// Identifiers that are imported /// Identifiers that are imported
// todo(agus): move to ScopeModules?
imported_symbols: Vec<(Ident, Symbol, Region)>, imported_symbols: Vec<(Ident, Symbol, Region)>,
/// Shadows of an ability member, for example a local specialization of `eq` for the ability /// Shadows of an ability member, for example a local specialization of `eq` for the ability

View file

@ -641,7 +641,7 @@ impl LookedupSymbol {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ScopeModules { pub struct ScopeModules {
modules: VecMap<ModuleName, ModuleId>, modules: VecMap<ModuleName, ModuleId>,
sources: VecMap<ModuleId, ScopeModuleSource>, // todo(agus): why not Vec? sources: Vec<ScopeModuleSource>,
params: Vec<Option<Symbol>>, params: Vec<Option<Symbol>>,
} }
@ -698,17 +698,16 @@ impl ScopeModules {
params_symbol: Option<Symbol>, params_symbol: Option<Symbol>,
region: Region, region: Region,
) -> Result<(), ScopeModuleSource> { ) -> Result<(), ScopeModuleSource> {
if let Some(existing_module_id) = self.modules.get(&module_name) { if let Some((index, existing_module_id)) = self.modules.get_with_index(&module_name) {
if *existing_module_id == module_id { if *existing_module_id == module_id {
return Ok(()); return Ok(());
} }
return Err(*self.sources.get(existing_module_id).unwrap()); return Err(*self.sources.get(index).unwrap());
} }
self.modules.insert(module_name, module_id); self.modules.insert(module_name, module_id);
self.sources self.sources.push(ScopeModuleSource::Import(region));
.insert(module_id, ScopeModuleSource::Import(region));
self.params.push(params_symbol); self.params.push(params_symbol);
Ok(()) Ok(())
} }
@ -1078,14 +1077,12 @@ macro_rules! define_builtins {
let capacity = $total + 1; let capacity = $total + 1;
let mut modules = VecMap::with_capacity(capacity); let mut modules = VecMap::with_capacity(capacity);
let mut sources = VecMap::with_capacity(capacity); let mut sources = Vec::with_capacity(capacity);
let mut params = Vec::with_capacity(capacity); let mut params = Vec::with_capacity(capacity);
// todo(agus): Use insert
if !home_id.is_builtin() { if !home_id.is_builtin() {
modules.insert(home_name, home_id); modules.insert(home_name, home_id);
sources.insert(home_id, ScopeModuleSource::Current); sources.push(ScopeModuleSource::Current);
params.push(None); params.push(None);
} }
@ -1093,7 +1090,7 @@ macro_rules! define_builtins {
let name: ModuleName = name_str.into(); let name: ModuleName = name_str.into();
modules.insert(name, id); modules.insert(name, id);
sources.insert(id, ScopeModuleSource::Builtin); sources.push(ScopeModuleSource::Builtin);
params.push(None); params.push(None);
}; };