481 Commits

Author SHA1 Message Date
HydroH
7aa42f47b7
allow @errorcast to cast error sets to error unions 2024-03-28 10:23:32 +00:00
mlugg
845226a7c9
cases: necessary changes from branch 2024-03-26 17:06:14 +00:00
mlugg
9c3670fc93
compiler: implement analysis-local comptime-mutable memory
This commit changes how we represent comptime-mutable memory
(`comptime var`) in the compiler in order to implement the intended
behavior that references to such memory can only exist at comptime.

It does *not* clean up the representation of mutable values, improve the
representation of comptime-known pointers, or fix the many bugs in the
comptime pointer access code. These will be future enhancements.

Comptime memory lives for the duration of a single Sema, and is not
permitted to escape that one analysis, either by becoming runtime-known
or by becoming comptime-known to other analyses. These restrictions mean
that we can represent comptime allocations not via Decl, but with state
local to Sema - specifically, the new `Sema.comptime_allocs` field. All
comptime-mutable allocations, as well as any comptime-known const allocs
containing references to such memory, live in here. This allows for
relatively fast checking of whether a value references any
comptime-mtuable memory, since we need only traverse values up to
pointers: pointers to Decls can never reference comptime-mutable memory,
and pointers into `Sema.comptime_allocs` always do.

This change exposed some faulty pointer access logic in `Value.zig`.
I've fixed the important cases, but there are some TODOs I've put in
which are definitely possible to hit with sufficiently esoteric code. I
plan to resolve these by auditing all direct accesses to pointers (most
of them ought to use Sema to perform the pointer access!), but for now
this is sufficient for all realistic code and to get tests passing.

This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema
arena for comptime memory mutations, which is possible since comptime
memory is now local to the current Sema.

This change should allow `Decl` to store only an `InternPool.Index`
rather than a full-blown `ty: Type, val: Value`. This commit does not
perform this refactor.
2024-03-25 14:49:41 +00:00
Andrew Kelley
95cb939440
Merge pull request #19333 from Vexu/fixes
Miscellaneous error fixes
2024-03-17 15:26:55 -07:00
Veikka Tuominen
f983adfc10 Sema: fix printing of inferred error set of generic fn
Closes #19332
2024-03-17 13:33:05 +02:00
Jacob Young
d10c52c194 AstGen: disallow alignment on function types
A pointer type already has an alignment, so this information does not
need to be duplicated on the function type.  This already has precedence
with addrspace which is already disallowed on function types for this
reason.  Also fixes `@TypeOf(&func)` to have the correct addrspace and
alignment.
2024-03-17 03:06:17 +01:00
mlugg
48af67c152
Zcu: rename implicitly-named decls to avoid overriding by explicit decls 2024-03-14 07:40:05 +00:00
mlugg
00969062a9
compiler: detect duplicate test names in AstGen
There is no reason to perform this detection during semantic analysis.
In fact, doing so is problematic, because we wish to utilize detection
of existing decls in a namespace in incremental compilation.
2024-03-14 07:40:05 +00:00
Tristan Ross
6067d39522
std.builtin: make atomic order fields lowercase 2024-03-11 07:09:10 -07:00
Tristan Ross
099f3c4039
std.builtin: make container layout fields lowercase 2024-03-11 07:09:07 -07:00
mlugg
e1d8187028
cases: correct after #18816
I changed an error messages and fixed a minor bug while implementing
this proposal, which led to a few compile error cases failing.
2024-03-06 21:26:38 +00:00
John Schmidt
7a045ede7c Check for inactive union field when calling fn at comptime
Reuse `unionFieldPtr` here to ensure that all the safety checks are
included.

Closes https://github.com/ziglang/zig/issues/18546.
2024-02-26 16:55:17 -08:00
Andrew Kelley
3e79c0f18c
Merge pull request #18859 from schmee/switch-union-capture-align
Sema: preserve field alignment in union pointer captures
2024-02-26 16:52:39 -08:00
John Schmidt
00ff123b1e Sema: fix compile error for switching on undefined union
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-26 16:51:37 -08:00
mlugg
7461309b73 Sema: validate that runtime-known inferred alloc does not have comptime-only type
Resolves: #18997
2024-02-19 21:48:50 +00:00
mlugg
b2f28a104d
cases: account for changed compile errors 2024-02-16 12:15:39 +00:00
Veikka Tuominen
51d67c7c8f Sema: add declared here notes in fail
This ensures that the note is added in more places and that `errMsg` needs to be used in fewer places.
2024-02-12 12:54:32 -08:00
Veikka Tuominen
731ff120d0 Sema: catch runtime stores to comptime variables through calls 2024-02-09 13:51:51 -08:00
Andrew Kelley
54bbc73f85
Merge pull request #18712 from Vexu/std.options
std: make options a struct instance instead of a namespace
2024-02-09 13:38:42 -08:00
John Schmidt
dbcd53def0 Preserve field alignment in union pointer captures 2024-02-08 23:49:03 +01:00
David Rubin
24fb6d1f30
Make @intFromEnum an error for empty enums 2024-02-06 21:04:09 +02:00
David Rubin
122387943b
Fix OOB when enum field out of order in different file 2024-02-03 19:52:05 +00:00
David Rubin
eb4024036d
Add error hint when looping over ErrorUnion 2024-02-03 19:16:27 +00:00
Veikka Tuominen
07dbff4f44 std.start: remove event loop integration 2024-02-01 15:22:36 +02:00
Pavel Verigo
96a5f7c8ed Sema: fix casting runtime value to enum with comptime int tag type 2024-01-29 01:43:19 +02:00
Krzysztof Wolicki
61ba225709
Sema: tuples have no names to be used for reporting errors in finishStructInit 2024-01-26 15:22:15 +02:00
Veikka Tuominen
eeec34ccb6 Sema: implement comptime error return traces 2024-01-22 18:08:56 -08:00
David Rubin
1b8f7e46fa
AstGen: detect duplicate field names
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
2024-01-20 17:23:47 +00:00
Meghan Denny
46d592e485 do not enforce function parameters to be marked comptime if only called at comptime 2024-01-19 15:31:18 -08:00
David Rubin
6e5bdb5397
add type check to zirSwitchBlockErrUnion 2024-01-18 00:46:00 +00:00
Techatrix
ec358d6db5 sema: fix safe integer arithmetic operations on undefined values
Previously `@as(i64, undefined) +% 1` would produce `@as(@TypeOf(undefined), undefined)` which now gives `@as(i64, undefined)`.
Previously `@as(i64, undefined) +| 1` would hit an assertion which now gives `@as(i64, undefined)`.
2024-01-16 16:27:31 -08:00
travisstaloch
f3353708d8
AstGen: use correct token_src for switch, if and while exprs
fixes #18579
2024-01-16 18:22:44 +02:00
Techatrix
06410f58bd AstGen: properly handle ill-formed switch on error 2024-01-16 05:55:26 +01:00
Techatrix
8b9425c248 AstGen: add error message for capture error by ref in switch on error 2024-01-16 05:55:26 +01:00
Andrew Kelley
32e88251e4 update test case for new const/var compile error
commit 8afafa717f5c036595a3a781c63b6be7b478c025 was created when this
error did not exist yet.
2024-01-15 01:53:41 -07:00
dweiller
8afafa717f sema: allow slicing *T with comptime known [0..1] 2024-01-14 17:26:45 -08:00
Andrew Kelley
bd46410419 Revert "Merge pull request #18410 from dweiller/by-length-slice-bug"
This reverts commit d9d840a33ac8abb0e616de862f592821a7f4a35e, reversing
changes made to a04d4330945565b8d6f298ace993f6954c42d0f3.

This is not an adequate implementation of the missing safety check, as
evidenced by the changes to std.json that are reverted in this commit.

Reopens #18382
Closes #18510
2024-01-13 23:21:44 -07:00
Meghan Denny
3d6c26525f sema: forbid asm output to const locals 2024-01-12 16:23:42 -08:00
Bogdan Romanyuk
4a1a5ee47b
AstGen: add error for redundant comptime var in comptime scope (#18242) 2024-01-09 20:09:39 -05:00
dweiller
69ab687156 test: add tests for switch_block_err_union 2024-01-09 14:42:12 +11:00
Veikka Tuominen
804cee3b93 categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
Carl Åstholm
501a2350ab sema: Prevent reifying non-empty union with empty tag type 2024-01-04 22:38:31 +02:00
dweiller
1748511058 sema: add compile error for OOB by-length slice of array 2023-12-31 15:36:58 +11:00
Andrew Kelley
3d23ba9c35 Revert "Sema: forbid @breakpoint from being called at comptime"
This reverts commit f88b523065fbb8afbd723fd6e803ace0334b713c.

Let's please go through the language proposal process for this change. I
don't see any justification for this breaking change even in the commit
message.
2023-12-11 12:24:15 -07:00
Bogdan Romanyuk
f88b523065
Sema: forbid @breakpoint from being called at comptime 2023-12-11 17:52:19 +02:00
Veikka Tuominen
69195d0cd4 AstGen: add error for using inline loops in comptime only scopes 2023-12-08 16:54:32 -08:00
Veikka Tuominen
39a966b0a4 Sema: improve error location for array cat/mul 2023-11-30 13:15:40 +02:00
Bogdan Romanyuk
2252dcc508
Compiler: move checking function-scope-only builtins to AstGen 2023-11-25 17:29:07 +00:00
Bogdan Romanyuk
aa31096cbd
Sema: disallow call to undefined function 2023-11-23 02:08:15 +00:00
Andrew Kelley
d5e21a4f1a std: remove meta.trait
In general, I don't like the idea of std.meta.trait, and so I am
providing some guidance by deleting the entire namespace from the
standard library and compiler codebase.

My main criticism is that it's overcomplicated machinery that bloats
compile times and is ultimately unnecessary given the existence of Zig's
strong type system and reference traces.

Users who want this can create a third party package that provides this
functionality.

closes #18051
2023-11-22 13:24:27 -05:00