diff --git a/sway-core/src/semantic_analysis/namespace/lexical_scope.rs b/sway-core/src/semantic_analysis/namespace/lexical_scope.rs index 915b0b94751..4e471633fd0 100644 --- a/sway-core/src/semantic_analysis/namespace/lexical_scope.rs +++ b/sway-core/src/semantic_analysis/namespace/lexical_scope.rs @@ -35,146 +35,7 @@ impl ResolvedFunctionDecl { } } -/// Scoped trait maps. -/// -/// These are used to distinguish between trait maps imported using star imports (`use a::*`), trait -/// maps imported using item imports (`use a::X`), and locally declared trait maps, since the latter -/// two may shadow the first. -#[derive(Clone, Debug, Default)] -pub(crate) struct ScopedTraitMaps { - pub(crate) local_decls: TraitMap, - pub(crate) item_imports: TraitMap, - pub(crate) glob_imports: TraitMap, -} - -impl ScopedTraitMaps { - pub fn get_items_for_type(&self, engines: &Engines, type_id: TypeId) -> Vec { - let item_imports = self.item_imports.get_items_for_type(engines, type_id); - let decls_and_item_imports = self.local_decls.get_items_for_type(engines, type_id) - .extend_from_slice(item_imports.as_slice()); - if !decls_and_item_imports.is_empty() { - decls_and_item_imports - } - else { - self.glob_imports.get_items_for_type(engines, type_id) - } - } - - pub fn get_impl_spans_for_type(&self, engines: &Engines, type_id: &TypeId) -> Vec { - let item_imports = self.item_imports.get_impl_spans_for_type(engines, type_id); - let decls_and_item_imports = self.local_decls.get_impl_spans_for_type(engines, type_id) - .extend_from_slice(item_imports.as_slice()); - if !decls_and_item_imports.is_empty() { - decls_and_item_imports - } - else { - self.glob_imports.get_impl_spans_for_type(engines, type_id) - } - } - - pub fn get_impl_spans_for_trait_name(&self, engines: &Engines, trait_name: &CallPath) -> Vec { - let item_imports = self.item_imports.get_impl_spans_for_trait_name(engines, trait_name); - let decls_and_item_imports = self.local_decls.get_impl_spans_for_trait_name(engines, trait_name) - .extend_from_slice(item_imports.as_slice()); - if !decls_and_item_imports.is_empty() { - decls_and_item_imports - } - else { - self.glob_imports.get_impl_spans_for_trait_name(engines, trait_name) - } - } - - pub fn get_trait_item_for_type(&self, handler: &Handler, engines: &Engines, symbol: &Ident, type_id: TypeId, as_trait: Option) -> Result { - let local_decl_candidates = self.local_decls.get_trait_item_for_type(handler, engines, symbol, type_id, as_trait); - let item_import_candidates = self.item_imports.get_trait_item_for_type(handler, engines, symbol, type_id, as_trait); - let total_local_and_item_import_candidates = local_decl_candidates.len() + item_import_candidates.len(); - if total_local_and_item_import_candidates > 1 { - Err(handler.emit_err( - CompileError::MultipleApplicableItemsInScope { - item_name: symbol.as_str().to_string(), - item_kind: "item".to_string(), - type_name: engines.help_out(type_id).to_string(), - as_traits: local_decl_candidates - .keys() - .map(|k| { - k.clone() - .split("::") - .collect::>() - .last() - .unwrap() - .to_string() - }) - .collect::>() - .extend( - item_import_candidates - .keys() - .map(|k| { - k.clone() - .split("::") - .collect::>() - .last() - .unwrap() - .to_string() - })), - span: symbol.span(), - }, - )) - } - else if total_local_and_item_import_candidates == 1 { - if local_decl_candidates == 1 { - Ok(local_decl_candidates.values().next().unwrap().clone()) - } else { - Ok(item_import_candidates.values().next().unwrap().clone()) - } - } - else { - // No local or item imported candidates. Check the star imported candidates - let glob_import_candidates = self.glob_imports.get_trait_item_for_type(handler, engines, symbol, type_id, as_trait); - if glob_import_candidates.len() > 1 { - Err(handler.emit_err( - CompileError::MultipleApplicableItemsInScope { - item_name: symbol.as_str().to_string(), - item_kind: "item".to_string(), - type_name: engines.help_out(type_id).to_string(), - as_traits: glob_import_candidates - .keys() - .map(|k| { - k.clone() - .split("::") - .collect::>() - .last() - .unwrap() - .to_string() - }) - .collect::>(), - span: symbol.span(), - }, - )) - } - else if glob_import_candidates.len() == 1 { - Ok(glob_import_candidates.values().next().unwrap().clone()) - } - else { - // No candidates found - Err(handler.emit_err(CompileError::SymbolNotFound { - name: symbol.clone(), - span: symbol.span(), - })) - } - } - } - - pub fn check_if_trait_constraints_are_satisfied_for_type(handler: &Handler, implementing_for: TypeId, trait_supertraits: &[TraitConstraint], access_span: &Span, engines: &Engines, try_inserting_trait_impl_on_failure: TryInsertingTraitImplOnFailure) -> Result<(), ErrorEmitted> { - - - } - - - // TODO: Error handling wrt. insertion should also happen here. -} - -pub(super) type ParsedSymbolMap = im::OrdMap; -pub(super) type SymbolMap = im::OrdMap; +pub(super) type SymbolMap = im::OrdMap; type SourceIdent = Ident; pub(super) type GlobSynonyms = im::HashMap>; pub(super) type ItemSynonyms = im::HashMap, ModulePathBuf, ty::TyDecl)>;