-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
AstGen: detect and error on files included in multiple packages #13670
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
Conversation
Not sure, if this is the correct place to discuss, but I found no issue on package semantics yet:
|
Will this affect when package An example from Bun where interdependent packages are a useful language feature:
|
That use case should be fine - this PR doesn't make any package dependencies illegal, only multiple packages directly depending on the same source file. |
A file in multiple packages would be pretty horrible for IDE support as well. In a correct IDE, the very first thing you'd ask to do, eg, completions in |
Ooh, that's an interesting point too, hadn't considered that. This PR's basically good to go, I just need to ask a question in this Thursday's compiler meeting about how to restructure the compiler tests to make them actually work again |
I do agree. Solving this would add complexity with additional lookup in metadata for every request. It sounds better to allow users to prune unused code with tooling/the package manager. (Since the language semantics allow such analysis for most use cases.) |
Oops, I meant to reply to this ages ago, I'll have a think once I'm home |
55b9fe9
to
b871f2a
Compare
I think this deserves a regression test, as this is super annoying to track down if it regresses. But the decision is of course up to a core team member. |
I was just looking at adding a test for this error, and I'm not really sure how to do it. It can't live under @andrewrk Is there a strategy I've not thought of, or should I try and extend |
b871f2a
to
8401eff
Compare
e690afb
to
7968d29
Compare
By @Vexu's suggestion, since fetching the name from the parent package is error-prone and complex, and optimising Package for size isn't really a priority.
Previously, if a source file was referenced from multiple packages, it just became owned by the first one AstGen happened to reach; this was a problem, because it could lead to inconsistent behaviour in the compiler based on a race condition. This could be fixed by just analyzing such files multiple times - however, it was pointed out by Andrew that it might make more sense to enforce files being part of at most a single package. Having a file in multiple packages would not only impact compile times (due to Sema having to run multiple times on potentially a lot of code) but is also a confusing anti-pattern which more often than not is a mistake on the part of the user. Resolves: ziglang#13662
7968d29
to
5f9186d
Compare
Previously, if a source file was referenced from multiple packages, it just became owned by the first one AstGen happened to reach; this was a problem, because it could lead to inconsistent behaviour in the compiler based on a race condition. This could be fixed by just analyzing such files multiple times - however, it was pointed out by Andrew that it might make more sense to enforce files being part of at most a single package. Having a file in multiple packages would not only impact compile times (due to Sema having to run multiple times on potentially a lot of code) but is also a confusing anti-pattern which more often than not is a mistake on the part of the user.
This PR also changes how errors are formatted slightly. Previously,
entire_file
module errors were turned intoplain
errors for output, which caused the filename to be omitted (which was quite unhelpful). This tweaks them to be reported like any other error, just with no outputted source line. This only affectsentire_file
errors, which were just used for retryable AstGen/File errors.Resolves: #13662