-
Notifications
You must be signed in to change notification settings - Fork 90
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
Allow implicit top-level namespaces when parsing files #1416
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a first pass, will take another look after you've had a chance to address comments
A few questions to the PR description. "We detect the "root" of the project by calculating the largest common prefix of the file paths."
"manually evoking qsc on two files in different parts of your computer -- what is the "root"?"
|
In this scenario, the namespace doesn't matter much because you will never refer to items in the current file from another file, due to being in single-file mode. That being said, the project root is detected as the whole path (although once again, this doesn't matter): you can see that in this test case.
This is the one shortcoming of this PR. Mine mentioned it here. The implementation required for the alternative approach was very fragile and not worth it. We jointly decided that it would be better to surface a warning or error if your
Yes. Ideally you would have your source files organized inside of a project and use our soon-to-be-released dependency management solution to be on the happy path. |
d0a63a0
to
f1b9d1d
Compare
7de201e
to
cf402fa
Compare
Benchmark for 70d5d46Click to view benchmark
|
This PR allows for implicit top-level namespaces.
Prior to this PR, all Q# had to be wrapped in namespace declarations:
Now, users can optionally omit the top-level namespace declaration. This is nice, because it removes a level of necessary indentation.
If the explicit namespace declaration is omitted, the file path is used to determine the namespace name. For example, in
~/code/qsharp/project_dir/src/Foo/Bar/Baz.qs
, the file:defines a callable in the namespace
Foo.Bar.Baz
.We detect the "root" of the project by calculating the largest common prefix of the file paths. This is the most versatile approach, in my opinion, without having to introduce project-based logic into the compiler itself (that is, add a
qsc_project
dependency toqsc_frontend
-- which would be cyclical viaqsc_lint
). It allows us to have a perfect UX for the happy path following a canonical project layout, and reasonable UX for other situations (e.g., manually evokingqsc
on two files in different parts of your computer -- what is the "root"?).