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

Language Service no longer needs to auto-add open Microsoft.Quantum.Measurement; #1336

Closed
swernli opened this issue Mar 28, 2024 · 0 comments · Fixed by #1415
Closed

Language Service no longer needs to auto-add open Microsoft.Quantum.Measurement; #1336

swernli opened this issue Mar 28, 2024 · 0 comments · Fixed by #1415
Assignees
Labels
bug Something isn't working

Comments

@swernli
Copy link
Collaborator

swernli commented Mar 28, 2024

As of #1233, Microsoft.Quantum.Measurement is part of the prelude and no longer needs to be open. However, the Language Service doesn't know this and still inserts open directives for that namespace when auto-completing things. We should include that namespace in the prelude logic there too.

@swernli swernli added the bug Something isn't working label Mar 28, 2024
github-merge-queue bot pushed a commit that referenced this issue May 17, 2024
_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:
1. Naked namespaces (files without namespace declarations)
2. Package publishing and sharing
3. Explicit item imports
4. Exports and re-exports
5. and the rest of the stuff
[here](#493 (comment))

Key changes include:
1. `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.
7. `NamespaceId` usage: This replaces our previous flat map-style
`Rc<str> -> Res` item tracking.
8. `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.
9. 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:

1. Katas used a form of shadowing that wasn't tested in our compiler.
This PR [adds a
test](https://github.com/microsoft/qsharp/pull/1312/files#diff-7a3aa16f18f6d132b9e54a6b6ebd53e6c3b41cea805c8f8db9c456b533a3c96bR2787)
for that.
2. Pursuing #1321 could help differentiate user-facing and
compiler-engineer-facing string representations of structs, which are
increasingly conflated.
3. There's potential for refactoring `ast`, `fir`, and `hir` to use
shared generic types, reducing duplicate `Ident`/etc types.
4. 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.
5. 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.

Also closes #1336

---------

Co-authored-by: Mine Starks <mineyalc@microsoft.com>
Co-authored-by: Mine Starks <16928427+minestarks@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants