aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
AgeCommit message (Collapse)Author
2024-02-26move Zcu.LazySrcLoc to std.zig.LazySrcLocAndrew Kelley
Part of an effort to ship more of the compiler in source form.
2024-02-27Merge pull request #19062 from mlugg/dbg-var-blocksMatthew Lugg
compiler: decide dbg_var scoping based on AIR blocks
2024-02-26Fix tuple default valuesJohn Schmidt
- Add default values to the list of comptime-known elements in `zirValidatePtrArrayInit` - In `structFieldValueComptime`, only assert `haveFieldInits` if we enter the`fieldIsComptime` branch (otherwise they are not needed).
2024-02-26Check for inactive union field when calling fn at comptimeJohn Schmidt
Reuse `unionFieldPtr` here to ensure that all the safety checks are included. Closes https://github.com/ziglang/zig/issues/18546.
2024-02-26Merge pull request #18859 from schmee/switch-union-capture-alignAndrew Kelley
Sema: preserve field alignment in union pointer captures
2024-02-26Sema: fix compile error for switching on undefined unionJohn Schmidt
Before this fix, passing an undefined union value to `Sema.switchCond` returned an undefined value of the union type, not the tag type, since `Value.unionTag` forwards undefined values unchanged. This leads us into the `.Union` branch in `Sema.zirSwitchBlock` which is unreachable, now we take the `.Enum` branch instead.
2024-02-26Sema: evaluate generic instantiations in fn decls capture scopeJohn Schmidt
The generic call `S.foo()` was evaluated with the capture scope of the owner decl (i.e the `test` block), when it should use the capture scope of the function declaration.
2024-02-26compiler: decide dbg_var scoping based on AIR blocksmlugg
This commit eliminates the `dbg_block_{begin,end}` instructions from both ZIR and AIR. Instead, lexical scoping of `dbg_var_{ptr,val}` instructions is decided based on the AIR block they exist within. This is a much more robust system, and also results in a huge drop in ZIR bytes - around 7% for Sema.zig. This required some enhancements to Sema to prevent elision of blocks when they are required for debug variable scoping. This can be observed by looking at the AIR for the following simple test program with and without `-fstrip`: ```zig export fn f() void { { var a: u32 = 0; _ = &a; } { var a: u32 = 0; _ = &a; } } ``` When `-fstrip` is passed, no AIR blocks are generated. When `-fno-strip` is passed, the ZIR blocks are lowered to true AIR blocks to give correct lexical scoping to the debug vars. The changes here incidentally reolve #19060. A corresponding behavior test has been added. Resolves: #19060
2024-02-25Merge pull request #19080 from jacobly0/llvm-per-mod-stripAndrew Kelley
llvm: implement per-module stripping
2024-02-25Merge pull request #18906 from jacobly0/x86_64-testsAndrew Kelley
x86_64: pass more tests
2024-02-25test: rework how filtering worksJacob Young
* make test names contain the fully qualified name * make test filters match the fully qualified name * allow multiple test filters, where a test is skipped if it does not match any of the specified filters
2024-02-25llvm: implement per-module strippingJacob Young
This avoids llvm module verification errors when the strip option is different across modules.
2024-02-25Sema: implement vector coercionsJacob Young
These used to be lowered elementwise in air, and now are a single air instruction that can be lowered elementwise in the backend if necessary.
2024-02-21Sema: fix peer type resolution for arrays of coercible elementsgarrison hinson-hasty
2024-02-19Sema: validate that runtime-known inferred alloc does not have comptime-only ↵mlugg
type Resolves: #18997
2024-02-16Sema: improved source location for @panic operand coercion errormlugg
Similar to the previous commit, errors coercing the panic message to `[]const u8` now point at the operand to `@panic` rather than the actual builtin call.
2024-02-16Sema: correct source location for return value coercion errorsmlugg
When coercing the operand of a `ret_node` etc instruction, the source location for errors used to point to the entire `return` statement. Instead, we now point to the operand, as would be expected if there was an explicit `as_node` instruction (like there used to be).
2024-02-16Zir: make src_node of type declarations non-optionalmlugg
Previously, the `src_node` field of `struct_decl`, `union_decl`, `enum_decl`, and `opaque_decl` was optional, included in trailing data only if a flag in `Small` was set. However, this was unnecessary logic: AstGen always provided the source node. We can simplify a few bits of logic by making this field non-optional, moving it into non-trailing data. There was one place where the field was actually omitted before: the root struct of a file was at source node 0, so the node was coincidentally elided. Therefore, this commit has a fixed cost of 4 bytes of ZIR per file.
2024-02-16AstGen: migrate `ty` result locations to `coerced_ty`mlugg
In most cases where AstGen is coercing to a fixed type (such as `u29`, `type`, `std.builtin.CallingConvention) we do not necessarily require an explicit coercion instruction. Instead, Sema knows the type that is required, and can perform the coercion after the fact. This means we can use the `coerced_ty` result location kind, saving unnecessary coercion instructions and therefore ZIR bytes. This required a few enhancements to Sema to introduce missing coercions.
2024-02-16Sema: eliminate `src` fieldmlugg
`sema.src` is a failed experiment. It introduces complexity, and makes often unwarranted assumptions about the existence of instructions providing source locations, requiring an unreasonable amount of caution in AstGen for correctness. Eliminating it simplifies the whole frontend. This required adding source locations to a few instructions, but the cost in ZIR bytes should be counteracted by the other work on this branch.
2024-02-16InternPool: make more use of `NullTerminatedString.Slice`Jacob Young
This should avoid the random pointer invalidation crashes. Closes #18954
2024-02-12Sema: add declared here notes in `fail`Veikka Tuominen
This ensures that the note is added in more places and that `errMsg` needs to be used in fewer places.
2024-02-09Sema: catch runtime stores to comptime variables through callsVeikka Tuominen
2024-02-08Improvements after code reviewJohn Schmidt
2024-02-08Preserve field alignment in union pointer capturesJohn Schmidt
2024-02-06Make `@intFromEnum` an error for empty enumsDavid Rubin
2024-02-06Merge pull request #18814 from mlugg/incremental-dependenciesMatthew Lugg
Begin re-implementing incremental compilation
2024-02-05compiler: rename value.zig to Value.zigAndrew Kelley
This commit only does the file rename to be friendlier to version control conflicts.
2024-02-05spirv: basic shader supportAli Chraghi
2024-02-04x86_64: fix errors compiling the compilerJacob Young
This fixes issues targetting both `x86_64-linux` and `x86_64-macos` with the self-hosted backend.
2024-02-04compiler: lock incremental dependency tracking behind --debug-incrementalmlugg
This logic (currently) has a non-trivial cost (particularly in terms of peak RSS) for tracking dependencies. Until incremental compilation is in use in the wild, it doesn't make sense for users to pay that cost.
2024-02-04Zcu: refactor Decl.analysis fieldmlugg
* Functions failing codegen now set this failure on the function analysis state. Decl analysis `codegen_failure` is reserved for failures generating constant values. * `liveness_failure` is consolidated into `codegen_failure`, as we do not need to distinguish these, and Liveness.Verify is just a debugging feature anyway. * `sema_failure_retryable` and `codegen_failure_retryable` are removed. Instead, retryable failures are recorded in the new `Zcu.retryable_failures` list. On an incremental update, this list is flushed, and all elements are marked as outdated so that we re-attempt analysis and code generation. Also remove the `generation` fields from `Zcu` and `Decl` as these are not needed by our new strategy for incremental updates.
2024-02-04Zir: store extra source hashes required for incrementalmlugg
Also add corresponding invaidation logic to Zcu. Therefore, the only invalidation logic which is not yet in place is `decl_val` dependencies.
2024-02-04compiler: re-introduce dependencies for incremental compilationmlugg
Sema now tracks dependencies appropriately. Early logic in Zcu for resolving outdated decls/functions is in place. The setup used does not support `usingnamespace`; compilations using this construct are not yet supported by this incremental compilation model.
2024-02-03Fix OOB when enum field out of order in different fileDavid Rubin
2024-02-03Add error hint when looping over `ErrorUnion`David Rubin
2024-02-02InternPool: use separate key for slicesmlugg
This change eliminates some problematic recursive logic in InternPool, and provides a safer API.
2024-01-30Sema: fix union init with zero size fieldPavel Verigo
2024-01-29llvm: ensure returned undef is 0xaa bytes when runtime safety is enabledVeikka Tuominen
Closes #13178
2024-01-29Fix some comptime packed struct issuesSuperAuguste
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2024-01-29Sema: do not emit `@errorCast` safety check when dest is adhoc inferred ↵Veikka Tuominen
error set Closes #17354
2024-01-29Sema: fix casting runtime value to enum with comptime int tag typePavel Verigo
2024-01-26Merge pull request #18654 from mlugg/incremental-the-secondAndrew Kelley
InternPool: introduce TrackedInst to prepare for incremental compilation
2024-01-26Sema: tuples have no names to be used for reporting errors in finishStructInitKrzysztof Wolicki
2024-01-23InternPool: introduce TrackedInstmlugg
It is problematic for the cached `InternPool` state to directly reference ZIR instruction indices, as these are not stable across incremental updates. The existing ZIR mapping logic attempts to handle this by iterating the existing Decl graph for a file after `AstGen` and update ZIR indices on `Decl`s, struct types, etc. However, this is unreliable due to generic instantiations, and relies on specialized logic for everything which may refer to a ZIR instruction (e.g. a struct's owner decl). I therefore determined that a prerequisite change for incremental compilation would be to rework how we store these indices. This commit introduces a `TrackedInst` type which provides a stable index (`TrackedInst.Index`) for a single ZIR instruction in the compilation. The `InternPool` now stores these values in place of ZIR instruction indices. This makes the ZIR mapping logic relatively trivial: after `AstGen` completes, we simply iterate all `TrackedInst` values and update those indices which have changed. In future, if the corresponding ZIR instruction has been removed, we must also invalidate any dependencies on this instruction to trigger any required re-analysis, however the dependency system does not yet exist.
2024-01-23Zir: represent declarations via an instructionmlugg
This commit changes how declarations (`const`, `fn`, `usingnamespace`, etc) are represented in ZIR. Previously, these were represented in the container type's extra data (e.g. as trailing data on a `struct_decl`). However, this introduced the complexity of the ZIR mapping logic having to also correlate some ZIR extra data indices. That isn't really a problem today, but it's tricky for the introduction of `TrackedInst` in the commit following this one. Instead, these type declarations now simply contain a trailing list of ZIR indices to `declaration` instructions, which directly encode all data related to the declaration (including containing the declaration's body). Additionally, the ZIR for `align` etc have been split out into their own bodies. This is not strictly necessary, but it's much simpler to understand for an insignificant cost in bytes, and will simplify the resolution of #131 (where we may need to evaluate the pointer type, including align etc, without immediately evaluating the value body).
2024-01-23Sema: use Sema.typeAbiSize rather than Type.abiSizeAndrew Kelley
This resolves the type instead of asserting that the type is resolved, fixing a crash.
2024-01-22Sema: implement comptime error return tracesVeikka Tuominen
2024-01-20Sema: replace uses of `toUnsignedInt` with `toUnsignedIntAdvanced`Veikka Tuominen
During semantic analysis the value may be an unresolved lazy value which makes using `toUnsignedInt` invalid. Add assertions to detect similar issues in the future. Closes #18624
2024-01-20AstGen: detect duplicate field namesDavid Rubin
This logic was previously in Sema, which was unnecessary complexity, and meant the issue was not detected unless the declaration was semantically analyzed. This commit finishes the work which 941090d started. Resolves: #17916