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

compiler: split Decl into Nav and Cau #20964

Merged
merged 2 commits into from
Aug 11, 2024

Commits on Aug 11, 2024

  1. compiler: split Decl into Nav and Cau

    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 <jacobly0@users.noreply.github.com>
    Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
    3 people committed Aug 11, 2024
    Configuration menu
    Copy the full SHA
    548a087 View commit details
    Browse the repository at this point in the history
  2. frontend: give all container types namespaces

    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.
    mlugg committed Aug 11, 2024
    Configuration menu
    Copy the full SHA
    153e7d6 View commit details
    Browse the repository at this point in the history