Skip to content

Commit

Permalink
Use OrdMap instead of HashMap and sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jan 7, 2025
1 parent b728b91 commit 8d57419
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
12 changes: 6 additions & 6 deletions sway-core/src/semantic_analysis/namespace/lexical_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use crate::{

use super::{root::ResolvedDeclaration, TraitMap};

use im::OrdMap;
use parking_lot::RwLock;
use sway_error::{
error::{CompileError, ShadowingSource},
handler::{ErrorEmitted, Handler},
};
use sway_types::{span::Span, IdentUnique, Named, Spanned};

use std::{collections::HashMap, sync::Arc};
use std::sync::Arc;

pub enum ResolvedFunctionDecl {
Parsed(ParsedDeclId<FunctionDeclaration>),
Expand All @@ -36,14 +37,13 @@ impl ResolvedFunctionDecl {
}
}

pub(super) type SymbolMap = HashMap<Ident, ResolvedDeclaration>;
pub(super) type SymbolUniqueMap = HashMap<IdentUnique, ResolvedDeclaration>;
pub(super) type SymbolMap = OrdMap<Ident, ResolvedDeclaration>;
pub(super) type SymbolUniqueMap = OrdMap<IdentUnique, ResolvedDeclaration>;

type SourceIdent = Ident;

pub(super) type GlobSynonyms =
HashMap<Ident, Vec<(ModulePathBuf, ResolvedDeclaration, Visibility)>>;
pub(super) type ItemSynonyms = HashMap<
pub(super) type GlobSynonyms = OrdMap<Ident, Vec<(ModulePathBuf, ResolvedDeclaration, Visibility)>>;
pub(super) type ItemSynonyms = OrdMap<
Ident,
(
Option<SourceIdent>,
Expand Down
27 changes: 3 additions & 24 deletions sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,29 +202,15 @@ impl Root {
};

// Collect all items declared in the source module
let mut symbols = src_mod
.root_items()
.symbols
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
for symbol in src_mod.root_items().symbols.keys() {
let decl = &src_mod.root_items().symbols[symbol];
if is_ancestor(src, dst) || decl.visibility(engines).is_public() {
decls_and_item_imports.push((symbol.clone(), decl.clone(), src.to_vec()));
}
}
// Collect those item-imported items that the source module reexports
// These live in the same namespace as local declarations, so no shadowing is possible
let mut symbols = src_mod
.root_items()
.use_item_synonyms
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
for symbol in src_mod.root_items().use_item_synonyms.keys() {
let (_, path, decl, src_visibility) = &src_mod.root_items().use_item_synonyms[symbol];
if src_visibility.is_public() {
decls_and_item_imports.push((symbol.clone(), decl.clone(), get_path(path.clone())))
Expand All @@ -235,14 +221,7 @@ impl Root {
// by local declarations and item imports in the source module, so they are treated
// separately.
let mut glob_imports = vec![];
let mut symbols = src_mod
.root_items()
.use_glob_synonyms
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
for symbol in src_mod.root_items().use_glob_synonyms.keys() {
let bindings = &src_mod.root_items().use_glob_synonyms[symbol];
// Ignore if the symbol is shadowed by a local declaration or an item import in the source module
if !decls_and_item_imports
Expand Down

0 comments on commit 8d57419

Please sign in to comment.