aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
AgeCommit message (Collapse)Author
2024-08-26remove some stale codeDavid Rubin
- Don't create an `inner_sema` in `unionFields` - Remove assertions of the sema owner, when we literally just set it
2024-08-25sema: `resolve{Struct,Union}Inner` don't throw away SemasDavid Rubin
before this, calls to `resolveTypeFieldsStruct` (now renamed to the more correct `resolveStructFieldTypes`) would just throw away the sema that `resolveStructInner` created and create its own. There is no reason to do this, and we fix it to preserve the sema through it all.
2024-08-25sema: rework type resolution to use Zcu when possibleDavid Rubin
2024-08-21compiler: handle eval branch quota in memoized callsmlugg
In a `memoized_call`, store how many backwards braches the call performs. Add this to `sema.branch_count` when using a memoized call. If this exceeds the quota, perform a non-memoized call to get a correct "exceeded X backwards branches" error. Also, do not memoize calls which do `@setEvalBranchQuota` or similar, as this affects global state which must apply to the caller. Change some eval branch quotas so that the compiler itself still builds correctly. This commit manually changes a file in Aro which is automatically generated. The sources which generate the file are not in this repo. Upstream Aro should make the suitable changes on their end before the next sync of Aro sources into the Zig repo.
2024-08-18Zir: add instructions to fetch std.builtin typesmlugg
This replaces the constant `Zir.Inst.Ref` tags (and the analagous tags in `Air.Inst.Ref`, `InternPool.Index`) referring to types in `std.builtin` with a ZIR instruction `extended(builtin_type(...))` which instructs Sema to fetch such a type, effectively as if it were a shorthand for the ZIR for `@import("std").builtin.xyz`. Previously, this was achieved through constant tags in `Ref`. The analagous `InternPool` indices began as `simple_type` values, and were later rewritten to the correct type information. This system was kind of brittle, and more importantly, isn't compatible with incremental compilation of std, since incremental compilation relies on the ability to recreate types at different indices when they change. Replacing the old system with this instruction slightly increases the size of ZIR, but it simplifies logic and allows incremental compilation to work correctly on the standard library. This shouldn't have a significant impact on ZIR size or compiler performance, but I will take measurements in the PR to confirm this.
2024-08-18frontend: handle incremental updates of replaced runtime functionsmlugg
2024-08-18frontend: removed resolved IES data for outdated functionsmlugg
Without this, incremental updates which would change inferred error sets fail, since they assume the IES is resolved and equals the old set, resulting in false positive compile errors when e.g. coercing to an IES.
2024-08-17compiler: add some doc commentsmlugg
2024-08-17frontend: incremental compilation progressmlugg
Another big commit, sorry! This commit makes all fixes necessary for incremental updates of the compiler itself (specifically, adding a breakpoint to `zirCompileLog`) to succeed, at least on the frontend. The biggest change here is a reform to how types are handled. It works like this: * When a type is first created in `zirStructDecl` etc, its namespace is scanned. If the type requires resolution, an `interned` dependency is declared for the containing `AnalUnit`. * `zirThis` also declared an `interned` dependency for its `AnalUnit` on the namespace's owner type. * If the type's namespace changes, the surrounding source declaration changes hash, so `zirStructDecl` etc will be hit again. We check whether the namespace has been scanned this generation, and re-scan it if not. * Namespace lookups also check whether the namespace in question requires a re-scan based on the generation. This is because there's no guarantee that the `zirStructDecl` is re-analyzed before the namespace lookup is re-analyzed. * If a type's structure (essentially its fields) change, then the type's `Cau` is considered outdated. When the type is re-analyzed due to being outdated, or the `zirStructDecl` is re-analyzed by being transitively outdated, or a corresponding `zirThis` is re-analyzed by being transitively outdated, the struct type is recreated at a new `InternPool` index. The namespace's owner is updated (but not re-scanned, since that is handled by the mechanisms above), and the old type, while remaining a valid `Index`, is removed from the map metadata so it will never be found by lookups. `zirStructDecl` and `zirThis` store an `interned` dependency on the *new* type.
2024-08-17InternPool: don't remove outdated typesmlugg
When a type becomes outdated, there will still be lingering references to the old index -- for instance, any declaration whose value was that type holds a reference to that index. These references may live for an arbitrarily long time in some cases. So, we can't just remove the type from the pool -- the old `Index` must remain valid! Instead, we want to preserve the old `Index`, but avoid it from ever appearing in lookups. (It's okay if analysis of something referencing the old `Index` does weird stuff -- such analysis are guaranteed by the incremental compilation model to always be unreferenced.) So, we use the new `InternPool.putKeyReplace` to replace the shard entry for this index with the newly-created index.
2024-08-17frontend: incremental progressmlugg
This commit makes more progress towards incremental compilation, fixing some crashes in the frontend. Notably, it fixes the regressions introduced by #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.
2024-08-16Dwarf: rework self-hosted debug info from scratchJacob Young
This is in preparation for incremental and actually being able to debug executables built by the x86_64 backend.
2024-08-11frontend: give all container types namespacesmlugg
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.
2024-08-11compiler: split Decl into Nav and Caumlugg
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 #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>
2024-07-22add new builtin: `@disableInstrumentation`Andrew Kelley
This is needed to ensure that start code does not try to access thread local storage before it has set up thread local storage.
2024-07-21ip: use `getExternFunc` in `getCoerced`David Rubin
`ip.get` specifically doesn't allow `extern_func` keys to access it.
2024-07-16Merge pull request #20632 from jacobly0/codegen-threadJacob Young
InternPool: enable separate codegen/linking thread
2024-07-16InternPool: enable separate codegen/linking threadJacob Young
Let's see what happens :)
2024-07-16InternPool: reduce max tid width by one bitJacob Young
@mlugg keeps stealing my bits!
2024-07-16InternPool: fix various data structure invariantsJacob Young
2024-07-16InternPool: fix `DependencyIterator` iterationJacob Young
2024-07-15Sema: support pointer subtractionWooster
2024-07-13InternPool: add and use a mutate mutex for each listJacob Young
This allows the mutate mutex to only be locked during actual grows, which are rare. For the lists that didn't previously have a mutex, this change has little effect since grows are rare and there is zero contention on a mutex that is only ever locked by one thread. This change allows `extra` to be mutated without racing with a grow.
2024-07-10InternPool: fix optimization assertion failureJacob Young
2024-07-10InternPool: make `global_error_set` thread-safeJacob Young
2024-07-10InternPool: fix extra mutation racesJacob Young
2024-07-10InternPool: make `maps` thread-safeJacob Young
2024-07-10InternPool: make `tracked_insts` thread-safeJacob Young
2024-07-10InternPool: make `files` more thread-safeJacob Young
2024-07-10InternPool: fix undefined decl fully qualified nameJacob Young
This is now possible after moving `File.Index` to `*File` mapping into intern pool.
2024-07-10InternPool: add `FileIndex` to `*File` mappingJacob Young
2024-07-10InternPool: fix race on struct flagsJacob Young
2024-07-10InternPool: fix race on `FuncInstance.branch_quota`Jacob Young
2024-07-10Zcu: cache fully qualified name on DeclJacob Young
This avoids needing to mutate the intern pool from backends.
2024-07-09InternPool: implement thread-safe allocated listsJacob Young
2024-07-08InternPool: fix multi-thread buildJacob Young
2024-07-07InternPool: fix dumping of simple typesJacob Young
2024-07-07InternPool: start documenting new thread-safe fieldsJacob Young
2024-07-07InternPool: implement and use thread-safe list for extra and limbsJacob Young
2024-07-07InternPool: remove usage of data with simple indicesJacob Young
This allows them to be atomically replaced.
2024-07-07InternPool: temporarily disable multi-threaded behaviorJacob Young
This reduces the cost of the new data structure until the multi-threaded behavior is actually used.
2024-07-07InternPool: implement and use thread-safe list for itemsJacob Young
2024-07-07InternPool: implement and use thread-safe list for stringsJacob Young
2024-07-07InternPool: replace garbage with an arenaJacob Young
This was just a badly implemented arena anyway.
2024-07-07InternPool: use thread-safe hash map for stringsJacob Young
2024-07-07InternPool: implement thread-safe hash mapJacob Young
2024-07-07Zcu: pass `PerThread` to intern pool string functionsJacob Young
2024-07-07Zcu: introduce `PerThread` and pass to all the functionsJacob Young
2024-07-04frontend: TrackedInst stores FileIndex instead of path digestAndrew Kelley
The purpose of using path digest was to reference a file in a serializable manner. Now that there is a stable index associated with files, it is a superior way to accomplish that goal, since removes one layer of indirection, and makes TrackedInst 8 bytes instead of 20. The saved Zig Compiler State file for "hello world" goes from 1.3M to 1.2M with this change.
2024-07-04Zcu: extract permanent state from FileAndrew Kelley
Primarily, this commit removes 2 fields from File, relying on the data being stored in the `files` field, with the key as the path digest, and the value as the struct decl corresponding to the File. This table is serialized into the compiler state that survives between incremental updates. Meanwhile, the File struct remains ephemeral data that can be reconstructed the first time it is needed by the compiler process, as well as operated on by independent worker threads. A key outcome of this commit is that there is now a stable index that can be used to refer to a File. This will be needed when serializing error messages to survive incremental compilation updates.