Skip to content

Commit a165145

Browse files
authored
Trait map optimizations (#7007)
## Description A couple PRs with trait map optimizations developed as part of trait coherence effort. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers.
1 parent 6c00a44 commit a165145

File tree

5 files changed

+221
-239
lines changed

5 files changed

+221
-239
lines changed

sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ impl ty::TyExpression {
25732573
base_name: &Ident,
25742574
projections: &[ty::ProjectionKind],
25752575
) -> Result<(TypeId, TypeId), ErrorEmitted> {
2576-
let ret = module.walk_scope_chain(|lexical_scope| {
2576+
let ret = module.walk_scope_chain_early_return(|lexical_scope| {
25772577
Self::find_subfield_type_helper(
25782578
lexical_scope,
25792579
handler,

sway-core/src/semantic_analysis/namespace/lexical_scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl Items {
678678
}
679679
};
680680

681-
let _ = module.walk_scope_chain(|lexical_scope| {
681+
let _ = module.walk_scope_chain_early_return(|lexical_scope| {
682682
if let Some((ident, decl)) = lexical_scope.items.symbols.get_key_value(&name) {
683683
append_shadowing_error(
684684
ident,

sway-core/src/semantic_analysis/namespace/module.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl Module {
291291
self.current_lexical_scope_id = parent_scope_id.unwrap(); // panics if pops do not match pushes
292292
}
293293

294-
pub fn walk_scope_chain<T>(
294+
pub fn walk_scope_chain_early_return<T>(
295295
&self,
296296
mut f: impl FnMut(&LexicalScope) -> Result<Option<T>, ErrorEmitted>,
297297
) -> Result<Option<T>, ErrorEmitted> {
@@ -310,23 +310,16 @@ impl Module {
310310
Ok(None)
311311
}
312312

313-
pub fn walk_scope_chain_mut<T>(
314-
&mut self,
315-
mut f: impl FnMut(&mut LexicalScope) -> Result<Option<T>, ErrorEmitted>,
316-
) -> Result<Option<T>, ErrorEmitted> {
317-
let mut lexical_scope_opt = Some(self.current_lexical_scope_mut());
313+
pub fn walk_scope_chain(&self, mut f: impl FnMut(&LexicalScope)) {
314+
let mut lexical_scope_opt = Some(self.current_lexical_scope());
318315
while let Some(lexical_scope) = lexical_scope_opt {
319-
let result = f(lexical_scope)?;
320-
if let Some(result) = result {
321-
return Ok(Some(result));
322-
}
316+
f(lexical_scope);
323317
if let Some(parent_scope_id) = lexical_scope.parent {
324-
lexical_scope_opt = self.get_lexical_scope_mut(parent_scope_id);
318+
lexical_scope_opt = self.get_lexical_scope(parent_scope_id);
325319
} else {
326320
lexical_scope_opt = None;
327321
}
328322
}
329-
Ok(None)
330323
}
331324

332325
pub fn get_items_for_type(
@@ -344,7 +337,7 @@ impl Module {
344337
symbol: &Ident,
345338
) -> Result<(ResolvedDeclaration, ModulePathBuf), ErrorEmitted> {
346339
let mut last_handler = Handler::default();
347-
let ret = self.walk_scope_chain(|lexical_scope| {
340+
let ret = self.walk_scope_chain_early_return(|lexical_scope| {
348341
last_handler = Handler::default();
349342
Ok(lexical_scope
350343
.items

0 commit comments

Comments
 (0)