aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
AgeCommit message (Collapse)Author
2024-08-17Sema: don't set union tag type if it's not an enummlugg
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-17Sema: don't delete reified enum type with error in fieldmlugg
An enum type is kind of like a struct or union type, in that field errors are happening during type resolution. The only difference is that type resolution happens at the time the type is created. So, errors in fields should not cause the type to be deleted: we've already added a reference entry, and incremenetal dependencies which must be invalidated if the compile error is fixed. Once we call `WipEnumType.prepare`, we should never call `WipEnumType.cancel`. This is analagous to logic for enum declarations in `Sema.zirEnumDecl`.
2024-08-17compiler: be more cautious about source locationsmlugg
Two fixes here. * Prevent a crash when sorting the list of analysis errors when some errors refer to lost source locations. These errors can be sorted anywhere in the list, because they are (in theory) guaranteed to never be emitted by the `resolveReferences` logic. This case occurs, for instance, when a declaration has compile errors in the initial update and is deleted in the second update. * Prevent a crash when resolving the source location for `entire_file` errors for a non-existent file. This is the bug underlying #20954. Resolves: #20954.
2024-08-17Sema: disable comptime call memoization under -fincrementalmlugg
2024-08-17frontend: yet more incremental workmlugg
2024-08-17Zcu: construct full reference graphmlugg
This commit updates `Zcu.resolveReferences` to traverse the graph of `AnalUnit` references (starting from the 1-3 roots of analysis) in order to determine which `AnalUnit`s are referenced in an update. Errors for unreferenced entities are omitted from the error bundle. However, note that unreferenced `Nav`s are not removed from the binary.
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-16add an error for stack allocations in naked functions (#21082)David Rubin
closes #72
2024-08-14Merge pull request #21031 from linusg/std-target-namingAndrew Kelley
std.Target: Function naming cleanup
2024-08-13nvptx: add implementations for GPU builtinsRobin Voetter
2024-08-12all: Handle spirv in addition to spirv(32,64) where applicable.Alex Rønne Petersen
Some of this is arbitrary since spirv (as opposed to spirv32/spirv64) refers to the version with logical memory layout, i.e. no 'real' pointers. This change at least matches what clang does.
2024-08-12std.Target: Rename c_type_* functions to camel caseLinus Groh
From https://ziglang.org/documentation/master/#Names: > If `x` is otherwise callable, then `x` should be `camelCase`.
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-08-08language: add module name field to `@src`Andrew Kelley
closes #20963
2024-07-28std.Target.Cpu.Arch: Remove the `aarch64_32` tag.Alex Rønne Petersen
This is a misfeature that we inherited from LLVM: * https://reviews.llvm.org/D61259 * https://reviews.llvm.org/D61939 (`aarch64_32` and `arm64_32` are equivalent.) I truly have no idea why this triple passed review in LLVM. It is, to date, the *only* tag in the architecture component that is not, in fact, an architecture. In reality, it is just an ILP32 ABI for AArch64 (*not* AArch32). The triples that use `aarch64_32` look like `aarch64_32-apple-watchos`. Yes, that triple is exactly what you think; it has no ABI component. They really, seriously did this. Since only Apple could come up with silliness like this, it should come as no surprise that no one else uses `aarch64_32`. Later on, a GNU ILP32 ABI for AArch64 was developed, and support was added to LLVM: * https://reviews.llvm.org/D94143 * https://reviews.llvm.org/D104931 Here, sanity seems to have prevailed, and a triple using this ABI looks like `aarch64-linux-gnu_ilp32` as you would expect. As can be seen from the diffs in this commit, there was plenty of confusion throughout the Zig codebase about what exactly `aarch64_32` was. So let's just remove it. In its place, we'll use `aarch64-watchos-ilp32`, `aarch64-linux-gnuilp32`, and so on. We'll then translate these appropriately when talking to LLVM. Hence, this commit adds the `ilp32` ABI tag (we already have `gnuilp32`).
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-21Sema: fix OOB access in coerceTupleToStruct (#19620)Bogdan Romanyuk
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2024-07-21fix: remove misleading error note for failed array coercionsWillLillis
2024-07-21fix: Add error notes for method calls on double pointers (#20686)Will Lillis
2024-07-20Fix typos in code comments in `src/`sobolevn
2024-07-18Sema: return module-relative path for `@src()`mlugg
This is one possible approach to fixing an issue with reproducible builds where the compiler's cwd changes the paths returned by `@src()`.
2024-07-16Sema: typomlugg
2024-07-16Sema: fix bad mergemlugg
2024-07-16Merge pull request #20637 from mlugg/comptime-resolution-stratMatthew Lugg
Type,Value: mark `ResolveStrat` parameter of type queries as `comptime`
2024-07-16Merge pull request #20646 from ziglang/fix-updateZirRefsAndrew Kelley
frontend: fix updateZirRefs
2024-07-16Sema: add error note for failed coercions to optional types and error unionsWill Lillis
2024-07-16Value: eliminate static recursion loop from value printingmlugg
2024-07-15frontend: move updateZirRefs to be single-threadedAndrew Kelley
for simplicity's sake. This makes it O(M) instead of O(N*M) where N is tracked insts and M is number of changed source files.
2024-07-15Sema: support pointer subtractionWooster
2024-07-15Merge pull request #20633 from ziglang/long-live-zigAndrew Kelley
make zig compiler processes live across rebuilds
2024-07-15Sema: disallow casting to opaquefmaggi
2024-07-14frontend: add -fincremental, -fno-incremental flagAndrew Kelley
Remove --debug-incremental This flag is also added to the build system. Importantly, this tells Compile step whether or not to keep the compiler running between rebuilds. It defaults off because it is currently crashing zirUpdateRefs.
2024-07-14Merge pull request #20593 from jacobly0/more-racesAndrew Kelley
InternPool: fix more races
2024-07-13zcu: fixup incorrect pass-by-value of Zcukcbanner
2024-07-13Compilation: introduce work stages for better work distributionJacob Young
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-12Zcu: allow atomic operations on packed structsJacob Young
Same validation rules as the backing integer would have.
2024-07-10InternPool: make `global_error_set` thread-safeJacob Young
2024-07-10InternPool: make `tracked_insts` 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-10Air: store param names directly instead of referencing Zirmlugg
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-07InternPool: implement and use thread-safe list for extra and limbsJacob Young
2024-07-07InternPool: implement and use thread-safe list for itemsJacob Young
2024-07-07Zcu: pass `PerThread` to intern pool string functionsJacob Young