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

Implements fully working hierarchical lexical scopes. #6784

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

esdrubal
Copy link
Contributor

@esdrubal esdrubal commented Dec 11, 2024

Description

This PR implements the missing elements for the hierarchical lexical scopes.
TypeCheckContext no longer uses cloned namespaces. Instead, we push and pop lexical scopes.
For this to work multiple places that used current_items now either use root_items or traverse the lexical scopes.

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).
  • 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.
  • I have requested a review from the relevant team or maintainers.

@esdrubal esdrubal added code quality compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Dec 11, 2024
@esdrubal esdrubal self-assigned this Dec 11, 2024
@esdrubal esdrubal force-pushed the esdrubal/hierarchical_lexical_scopes branch from 920ca89 to aaed7cc Compare December 12, 2024 15:09
Copy link

codspeed-hq bot commented Dec 12, 2024

CodSpeed Performance Report

Merging #6784 will degrade performances by 58.21%

Comparing esdrubal/hierarchical_lexical_scopes (c47a31f) with master (faf399e)

Summary

❌ 2 regressions
✅ 20 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master esdrubal/hierarchical_lexical_scopes Change
completion 21 ms 23.6 ms -11.38%
hover 1.8 ms 4.3 ms -58.21%

@esdrubal esdrubal force-pushed the esdrubal/hierarchical_lexical_scopes branch 2 times, most recently from c5f0f07 to 62fd6dd Compare December 12, 2024 15:47
@esdrubal esdrubal marked this pull request as ready for review December 13, 2024 09:22
@esdrubal esdrubal requested review from a team as code owners December 13, 2024 09:22
@@ -36,14 +36,14 @@ impl ResolvedFunctionDecl {
}
}

pub(super) type SymbolMap = im::OrdMap<Ident, ResolvedDeclaration>;
pub(super) type SymbolUniqueMap = im::OrdMap<IdentUnique, ResolvedDeclaration>;
pub(super) type SymbolMap = HashMap<Ident, ResolvedDeclaration>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is HashMap here fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine because we are sorting each iterator before using them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a comment that justifies the usage here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use OrdMap but it introduces a significant performance drop:

Benchmark master esdrubal/hierarchical_lexical_scopes Change
compile 5.3 s 8.1 s -34.4%

@esdrubal esdrubal force-pushed the esdrubal/hierarchical_lexical_scopes branch 2 times, most recently from 792e419 to 8d57419 Compare January 7, 2025 10:46
@esdrubal esdrubal requested review from a team as code owners January 7, 2025 17:09
@esdrubal esdrubal force-pushed the esdrubal/hierarchical_lexical_scopes branch 2 times, most recently from 90c1d89 to f2f0b31 Compare January 8, 2025 10:05
unreachable!();
};

ctx.insert_trait_implementation(
Copy link
Contributor

@tritao tritao Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining why this is now necessary?

@@ -379,6 +416,14 @@ impl Module {
})
.collect::<Vec<_>>()
}

pub fn get_impl_spans_for_decl(&self, engines: &Engines, ty_decl: &TyDecl) -> Vec<Span> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should move this to some other file.

tritao
tritao previously approved these changes Jan 8, 2025
@esdrubal esdrubal force-pushed the esdrubal/hierarchical_lexical_scopes branch from b18daec to c47a31f Compare January 9, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants