-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
compiler: split Decl
into Nav
and Cau
#20964
Conversation
Holy line count, Batman! |
e96b967
to
30cea80
Compare
f33ee13
to
1631b46
Compare
The type `Zcu.Decl` in the compiler is problematic: over time it has gained many responsibilities. Every source declaration, container type, generic instantiation, and `@extern` has a `Decl`. The functions of these `Decl`s are in some cases entirely disjoint. After careful analysis, I determined that the two main responsibilities of `Decl` are as follows: * A `Decl` acts as the "subject" of semantic analysis at comptime. A single unit of analysis is either a runtime function body, or a `Decl`. It registers incremental dependencies, tracks analysis errors, etc. * A `Decl` acts as a "global variable": a pointer to it is consistent, and it may be lowered to a specific symbol by the codegen backend. This commit eliminates `Decl` and introduces new types to model these responsibilities: `Cau` (Comptime Analysis Unit) and `Nav` (Named Addressable Value). Every source declaration, and every container type requiring resolution (so *not* including `opaque`), has a `Cau`. For a source declaration, this `Cau` performs the resolution of its value. (When ziglang#131 is implemented, it is unsolved whether type and value resolution will share a `Cau` or have two distinct `Cau`s.) For a type, this `Cau` is the context in which type resolution occurs. Every non-`comptime` source declaration, every generic instantiation, and every distinct `extern` has a `Nav`. These are sent to codegen/link: the backends by definition do not care about `Cau`s. This commit has some minor technically-breaking changes surrounding `usingnamespace`. I don't think they'll impact anyone, since the changes are fixes around semantics which were previously inconsistent (the behavior changed depending on hashmap iteration order!). Aside from that, this changeset has no significant user-facing changes. Instead, it is an internal refactor which makes it easier to correctly model the responsibilities of different objects, particularly regarding incremental compilation. The performance impact should be negligible, but I will take measurements before merging this work into `master`. Co-authored-by: Jacob Young <[email protected]> Co-authored-by: Jakub Konka <[email protected]>
Eliding the namespace when a container type has no decls was an experiment in saving memory, but it ended up causing more trouble than it was worth in various places. So, take the small memory hit for reified types, and just give every container type a namespace.
1631b46
to
153e7d6
Compare
Performance tests are indicating that analysis performance suffers considerably, but codegen is improved enough to make up for it. I'm not surprised that codegen improved, but I am surprised at how significant these changes are (both for analysis and codegen). I'd be inclined to go ahead with merge, since for actual compilations this PR doesn't seem to represent a perf regression, but if @andrewrk is uncomfortable with the Analyze Behavior
Build Behavior (x86_64-linux selfhosted)
Analyze Hello World
Build Hello World (x86_64-linux selfhosted)
|
can you take a data point for building the self-hosted compiler? behavior tests and hello world are a bit of outliers. |
These data points are for building the self-hosted compiler with
Analyze
Build (x86_64-linux selfhosted)
|
This fixes the regressions introduced by ziglang#20964. It also cleans up the "outdated file root" mechanism by virtue of deleting it. We now detect outdated file roots just after updating ZIR refs, and re-scan their namespaces. @jacobly0, this deletes some asserts in `InternPool` which didn't look appropriate to me, in order to deal with ziglang#20697.
This commit makes more progress towards incremental compilation, fixing some crashes in the frontend. Notably, it fixes the regressions introduced by ziglang#20964. It also cleans up the "outdated file root" mechanism, by virtue of deleting it: we now detect outdated file roots just after updating ZIR refs, and re-scan their namespaces.
This commit makes more progress towards incremental compilation, fixing some crashes in the frontend. Notably, it fixes the regressions introduced by ziglang#20964. It also cleans up the "outdated file root" mechanism, by virtue of deleting it: we now detect outdated file roots just after updating ZIR refs, and re-scan their namespaces.
This commit makes more progress towards incremental compilation, fixing some crashes in the frontend. Notably, it fixes the regressions introduced by ziglang#20964. It also cleans up the "outdated file root" mechanism, by virtue of deleting it: we now detect outdated file roots just after updating ZIR refs, and re-scan their namespaces.
This commit makes more progress towards incremental compilation, fixing some crashes in the frontend. Notably, it fixes the regressions introduced by ziglang#20964. It also cleans up the "outdated file root" mechanism, by virtue of deleting it: we now detect outdated file roots just after updating ZIR refs, and re-scan their namespaces.
The type
Zcu.Decl
in the compiler is problematic: over time it has gained many responsibilities. Every source declaration, container type, generic instantiation, and@extern
has aDecl
. The functions of theseDecl
s are in some cases entirely disjoint.After careful analysis, I determined that the two main responsibilities of
Decl
are as follows:Decl
acts as the "subject" of semantic analysis at comptime. A single unit of analysis is either a runtime function body, or aDecl
. It registers incremental dependencies, tracks analysis errors, etc.Decl
acts as a "global variable": a pointer to it is consistent, and it may be lowered to a specific symbol by the codegen backend.This commit eliminates
Decl
and introduces new types to model these responsibilities:Cau
(Comptime Analysis Unit) andNav
(Named Addressable Value).Every source declaration, and every container type requiring resolution (so not including
opaque
), has aCau
. For a source declaration, thisCau
performs the resolution of its value. (When #131 is implemented, it is unsolved whether type and value resolution will share aCau
or have two distinctCau
s.) For a type, thisCau
is the context in which type resolution occurs.Every non-
comptime
source declaration, every generic instantiation, and every distinctextern
has aNav
. These are sent to codegen/link: the backends by definition do not care aboutCau
s.This commit has some minor technically-breaking changes surrounding
usingnamespace
. I don't think they'll impact anyone, since the changes are fixes around semantics which were previously inconsistent (the behavior changed depending on hashmap iteration order!).Aside from that, this changeset has no user-facing changes. Instead, it is an internal refactor which makes it easier to correctly model the responsibilities of different objects, particularly regarding incremental compilation. The performance impact should be negligible, but I will take measurements before merging this work into
master
.