You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR introduces a feature called hierarchical namespaces, a module-like system that maintains backward compatibility. It is the foundational groundwork that will pave the way for:
Naked namespaces (files without namespace declarations)
VecIdent type introduction: This abstraction over Vec<Ident> represents the new namespaces in the AST. Alternate names could be DotIdent or Path, but those names were already loaded with meaning in our codebase. I'm open to feedback on nomenclature here.
NamespaceId usage: This replaces our previous flat map-style Rc<str> -> Res item tracking.
NamespaceTree: This tracks the namespace hierarchy separately in low-cost data structure, and allows us to keep our basic tys and terms maps relatively untouched.
Name resolution algorithm update: The algorithm in resolve.rs received a heavy facelift. Not only did I try to simplify the existing code, but I also added the required functionality to check candidate partially-opened or re-opened namespaces.
This PR maintains 100% backward compatibility with the existing resolution engine, preserving features like re-opening namespaces, shadowing semantics, merging namespaces via aliases, and absolute-path opens. It also introduces the ability to reference a function in a different namespace if its parent namespace is opened.
Additional notes:
Katas used a form of shadowing that wasn't tested in our compiler. This PR adds a test for that.
There's potential for refactoring ast, fir, and hir to use shared generic types, reducing duplicate Ident/etc types.
Completions functionality remains the same, but it's not yet aware of the ability to partially open namespaces (e.g. open Microsoft.Quantum. This will be addressed in future updates.
There is a performance regression, but we are performing a full tree-traversal namespace resolution algorithm in a place where we used to just do a constant table lookup. I have optimized this as much as I believe is reasonable for now, bringing the regression down from ~40%, where it was originally, to around 5-10% based on the benchmark run.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces #1364
This PR introduces a feature called hierarchical namespaces, a module-like system that maintains backward compatibility. It is the foundational groundwork that will pave the way for:
Key changes include:
VecIdent
type introduction: This abstraction overVec<Ident>
represents the new namespaces in the AST. Alternate names could beDotIdent
orPath
, but those names were already loaded with meaning in our codebase. I'm open to feedback on nomenclature here.NamespaceId
usage: This replaces our previous flat map-styleRc<str> -> Res
item tracking.NamespaceTree
: This tracks the namespace hierarchy separately in low-cost data structure, and allows us to keep our basictys
andterms
maps relatively untouched.resolve.rs
received a heavy facelift. Not only did I try to simplify the existing code, but I also added the required functionality to check candidate partially-opened or re-opened namespaces.This PR maintains 100% backward compatibility with the existing resolution engine, preserving features like re-opening namespaces, shadowing semantics, merging namespaces via aliases, and absolute-path opens. It also introduces the ability to reference a function in a different namespace if its parent namespace is opened.
Additional notes:
ast
,fir
, andhir
to use shared generic types, reducing duplicateIdent
/etc types.open Microsoft.Quantum
. This will be addressed in future updates.Also closes #1336