Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduces memory footprint of collecting unifications. #6479

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sway-core/src/semantic_analysis/ast_node/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl ty::TyCodeBlock {
}

ctx.engines.te().clear_unifications();
ctx.namespace()
.module(ctx.engines)
.current_lexical_scope()
.items
.clear_symbols_unique_while_collecting_unifications();

// We are typechecking the code block AST nodes twice.
// The first pass does all the unifications to the variables types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl TyDecl {
.namespace()
.module(engines)
.current_items()
.check_symbol_unique(&var_decl.name.clone())
.check_symbols_unique_while_collecting_unifications(&var_decl.name.clone())
.ok();

if let Some(ResolvedDeclaration::Typed(ty::TyDecl::VariableDecl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl Items {
})
}

pub(crate) fn check_symbol_unique(
pub(crate) fn check_symbols_unique_while_collecting_unifications(
&self,
name: &Ident,
) -> Result<ResolvedDeclaration, CompileError> {
Expand All @@ -718,6 +718,12 @@ impl Items {
})
}

pub(crate) fn clear_symbols_unique_while_collecting_unifications(&self) {
self.symbols_unique_while_collecting_unifications
.write()
.clear();
}

pub fn get_items_for_type(
&self,
engines: &Engines,
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Module {
}

/// Returns the current lexical scope associated with this module.
fn current_lexical_scope(&self) -> &LexicalScope {
pub fn current_lexical_scope(&self) -> &LexicalScope {
self.lexical_scopes
.get(self.current_lexical_scope_id)
.unwrap()
Expand Down
Loading