25894 Commits

Author SHA1 Message Date
Robin Voetter
cc13864dfb spirv: lower enum_tag constants 2023-09-23 12:36:44 -07:00
Robin Voetter
aeaaa953a0 spirv: assign type names to (error) unions 2023-09-23 12:36:44 -07:00
Robin Voetter
ece52640eb spirv: construct error union at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter
ced8a2c3a6 spirv: add type_map to map AIR types to SPIR-V types
This will help us both to make the implementation a little
more efficient by caching emission for certain types like structs,
and also allow us to attach extra information about types that we
can use while lowering without performing a search over the entire
type tree for some property.
2023-09-23 12:36:44 -07:00
Robin Voetter
79f7481575 spirv: disable failing tests 2023-09-23 12:36:44 -07:00
Ryan Liptak
865b2e259b Fix reportRetryableWin32ResourceError
Follow up to https://github.com/ziglang/zig/pull/17069.

This TODO being left in was a complete oversight.

Before, any 'retryable' error would hit:

error: thread 2920 panic: access of union field 'success' while field 'failure_retryable' is active

Now, it will be reported/handled properly:

C:\Users\Ryan\Programming\Zig\zig\test\standalone\windows_resources\res\zig.rc:1:1: error: FileNotFound
2023-09-23 11:01:02 -07:00
mlugg
ce919ccf45 Sema: do not emit dbg_var_val and dbg_var_ptr instructions for comptime-only types 2023-09-23 14:45:59 +01:00
mlugg
05f78adeaf Sema: don't attempt to reinterpret comptime-only types when mutating comptime memory
I have no idea how correct this code is, but I'm working on a full
rewrite of this logic anyway, and this certainly seems more correct than
before.
2023-09-23 13:51:18 +01:00
mlugg
644041b3a4 Sema: refactor detection of comptime-known consts
This was previously implemented by analyzing the AIR prior to the ZIR
`make_ptr_const` instruction. This solution was highly delicate, and in
particular broke down whenever there was a second `alloc` between the
`store` and `alloc` instructions, which is especially common in
destructure statements.

Sema now uses a different strategy to detect whether a `const` is
comptime-known. When the `alloc` is created, Sema begins tracking all
pointers and stores which refer to that allocation in temporary local
state. If any store is not comptime-known or has a higher runtime index
than the allocation, the allocation is marked as being runtime-known.
When we reach the `make_ptr_const` instruction, if the allocation is not
marked as runtime-known, it must be comptime-known. Sema will use the
set of `store` instructions to re-initialize the value in comptime
memory. We optimize for the common case of a single `store` instruction
by not creating a comptime alloc in this case, instead directly plucking
the result value from the instruction.

Resolves: #16083
2023-09-23 13:51:18 +01:00
mlugg
fc3ff26237 TypedValue: print undef @ptrFromInt pointers correctly 2023-09-23 13:51:18 +01:00
Andrew Kelley
0710314de6
Merge pull request #15490 from kcbanner/skip_oom_steps
build_runner: add --skip-oom-steps
2023-09-22 15:09:46 -07:00
Andrew Kelley
5ae8469653 CI: let's not start using --skip-oom-steps quite yet 2023-09-22 15:09:09 -07:00
kcbanner
53d1282f0c build: add --skip-oom-steps
Specifying this argument causes steps that specify a max_rss that exceeds the
total max_rss value of the runner to be skipped, instead of failing.
2023-09-22 15:08:51 -07:00
mlugg
e011c31ee8 Sema: optimize comptime @memset by setting all elements at once
Previously, @memset at comptime performed N pointer stores. This is less
efficient than just storing a whole array of values at once. The
difference can be quite drastic when reinterpreting memory - a test case
which is 40s on master branch now takes under a second on a debug
compiler build.

Resolves: #17214
2023-09-22 14:42:27 -07:00
Andrew Kelley
272a57eeed Revert "CI: update x86_64 windows tarballs"
This reverts commit bb98ffbe7fc8d21f48286432fe685312fd9b07cc.

This caused master branch to fail the CI. We do need to figure out why
these assertions are tripping but let's do it in a branch other than
master.
2023-09-22 12:53:36 -07:00
Aven Bross
6c54ed73f7 Added basic support for wasm32-emscripten target 2023-09-22 12:49:03 -07:00
Wooster
4585cb1e2f AstGen: fix @export with undeclared identifier crashing
This required a third `if (found_already == null)` in another place in
AstGen.zig for this special case of `@export`.

Fixes #17188
2023-09-22 12:23:57 -07:00
Andrew Kelley
3fc7413574
Merge pull request #17069 from squeek502/resinator
Add a `.rc` -> `.res` compiler to the Zig compiler
2023-09-22 12:18:50 -07:00
Andrew Kelley
867e61e10b CI: update macos tarballs
Updates from LLVM release/17.x to 17.0.1
2023-09-22 09:43:31 -07:00
Andrew Kelley
bb98ffbe7f CI: update x86_64 windows tarballs
Updates from LLVM release/17.x to 17.0.1
2023-09-22 09:42:15 -07:00
Andrew Kelley
a8d2ed8065
Merge pull request #17172 from ziglang/ip-structs
compiler: move struct types into InternPool proper
2023-09-22 09:38:41 -07:00
Andrew Kelley
221295b7db wasm: fix regression of C ABI
It seems the webassembly backend does not want the exception that
`structFieldAlignmentExtern` makes for 128-bit integers. Perhaps that
logic should be modified to check if the target is wasm.

Without this, this branch fails the C ABI tests for wasm, causing this:
```
wasm-ld: warning: function signature mismatch: zig_struct_u128
>>> defined as (i64, i64) -> void in cfuncs.o
>>> defined as (i32) -> void in test-c-abi-wasm32-wasi-musl-ReleaseFast.wasm.o
```
2023-09-21 22:25:58 -07:00
Andrew Kelley
747440677d LLVM: fix UAF when lowering debug info for structs
Gotta call the get() function inside the loop if the loop adds anything
to InternPool.
2023-09-21 21:55:41 -07:00
Ryan Liptak
572956ce24 classifyFileExt: Use case-insensitive matching for .rc and .res 2023-09-21 21:30:21 -07:00
Andrew Kelley
81b5df347a compiler: fix structFieldName crash for tuples
When struct types have no field names, the names are implicitly
understood to be strings corresponding to the field indexes in
declaration order. It used to be the case that a NullTerminatedString
would be stored for each field in this case, however, now, callers must
handle the possibility that there are no names stored at all. This
commit introduces `legacyStructFieldName`, a function to fake the
previous behavior. Probably something better could be done by reworking
all the callsites of this function.
2023-09-21 17:29:34 -07:00
mlugg
edfada4317 Sema: mark transitive failure when @import refers to a failed file 2023-09-21 16:27:52 -07:00
Andrew Kelley
55bc8a7fa9 compiler: fix compilation for 32-bit targets 2023-09-21 15:27:25 -07:00
mlugg
2e5d13e9cf Sema: queue type resolution when analyzing ret_ptr during inline call 2023-09-21 14:48:41 -07:00
mlugg
9965d960b5 type: give empty unions 1-byte alignment
Zero-byte alignment is no longer valid for runtime types. I made most of
these changes in an earlier commit, but missed this case.
2023-09-21 14:48:41 -07:00
Andrew Kelley
d3f3de73ba Sema: less aggressive type resolution for field_val
This is an alternate version of c675daac7d0d6328ad89297e8938a6b17b59c489
2023-09-21 14:48:41 -07:00
mlugg
1b672e41c5 InternPool,Sema,type,llvm: alignment fixes
This changeset fixes the handling of alignment in several places. The
new rules are:
* `@alignOf(T)` where `T` is a runtime zero-bit type is at least 1,
  maybe greater.
* Zero-bit fields in `extern` structs *do* force alignment, potentially
  offsetting following fields.
* Zero-bit fields *do* have addresses within structs which can be
  observed and are consistent with `@offsetOf`.

These are not necessarily all implemented correctly yet (see disabled
test), but this commit fixes all regressions compared to master, and
makes one new test pass.
2023-09-21 14:48:41 -07:00
Andrew Kelley
cd242b7440 Sema: queue type resolution when adding a struct_field_val instruction 2023-09-21 14:48:40 -07:00
Andrew Kelley
7d9cf156c3 TypedValue: fix crash for tuples when printing 2023-09-21 14:48:40 -07:00
Andrew Kelley
dca17d3603 Sema: fix struct alignment regressions 2023-09-21 14:48:40 -07:00
Andrew Kelley
d06bf707ed compiler: make pointer type canonicalization always work
Previously it would canonicalize or not depending on some volatile
internal state of the compiler, now it forces resolution of the element
type to determine the alignment if it needs to.
2023-09-21 14:48:40 -07:00
Andrew Kelley
51b1a2a6cb Alignment: min/minStrict max/maxStrict
Carve out a path forward for being a little bit more intentional about
handling "default" alignment values.
2023-09-21 14:48:40 -07:00
Andrew Kelley
5ea3de55c4 Sema: fix dependency loop regression on struct field alignment 2023-09-21 14:48:40 -07:00
Andrew Kelley
2671aa9058 InternPool: fix nameIndex for tuples 2023-09-21 14:48:40 -07:00
Andrew Kelley
c79da0d731 Sema: allow users to provide alignment 0 to mean default 2023-09-21 14:48:40 -07:00
mlugg
ada83fa557 compiler: get codegen of behavior tests working on at least one backend
We're hitting false compile errors, but this is progress!
2023-09-21 14:48:40 -07:00
mlugg
0182b7242e TypedValue: do not crash when failing to dereference pointer
All of the logic in `Value.elemValue` is quite questionable, but
printing an error is definitely better than crashing. Notably, this
should stop us from hitting crashes when dumping AIR.
2023-09-21 14:48:40 -07:00
Andrew Kelley
2da62a7106 Sema: restore master branch field reordering behavior
Let's try to reduce the explosive scope of this branch.
2023-09-21 14:48:40 -07:00
Andrew Kelley
f739ac9c21 sema: delete dead code
Not sure what that code was supposed to be doing, it doesn't seem to be
reachable.
2023-09-21 14:48:40 -07:00
Andrew Kelley
baea62a8ad fix regressions from this branch 2023-09-21 14:48:40 -07:00
Andrew Kelley
483b3a3344 InternPool: implement only_possible_value prong of indexToKey
for the new struct and packed struct encodings.
2023-09-21 14:48:40 -07:00
Andrew Kelley
b65f3d8826 InternPool: implement extraStructType 2023-09-21 14:48:40 -07:00
Andrew Kelley
fa1beba74f InternPool: implement getStructType
This also modifies AstGen so that struct types use 1 bit each from the
flags to communicate if there are nonzero inits, alignments, or comptime
fields. This allows adding a struct type to the InternPool without
looking ahead in memory to find out the answers to these questions,
which is easier for CPUs as well as for me, coding this logic right now.
2023-09-21 14:48:40 -07:00
Andrew Kelley
accd5701c2 compiler: move struct types into InternPool proper
Structs were previously using `SegmentedList` to be given indexes, but
were not actually backed by the InternPool arrays.

After this, the only remaining uses of `SegmentedList` in the compiler
are `Module.Decl` and `Module.Namespace`. Once those last two are
migrated to become backed by InternPool arrays as well, we can introduce
state serialization via writing these arrays to disk all at once.

Unfortunately there are a lot of source code locations that touch the
struct type API, so this commit is still work-in-progress. Once I get it
compiling and passing the test suite, I can provide some interesting
data points such as how it affected the InternPool memory size and
performance comparison against master branch.

I also couldn't resist migrating over a bunch of alignment API over to
use the log2 Alignment type rather than a mismash of u32 and u64 byte
units with 0 meaning something implicitly different and special at every
location. Turns out you can do all the math you need directly on the
log2 representation of alignments.
2023-09-21 14:48:40 -07:00
Andrew Kelley
0345d78663 CI: install ninja on windows
The new CI images provided by GitHub no longer provide ninja.exe, so
this commit installs it explicitly, using the suggested method from
GitHub.

See https://github.com/actions/runner-images/issues/8343 for more
details.
2023-09-21 14:18:55 -07:00
Pat Tullmann
00f42909ad
langref: small fixes to wording and examples
Simplify wording and add some formatting in several locations.

Expand sentinel array tests to highlight (non-)handling of internal
sentinels.

Fix format of symbol names in function pointers example.

Clarify wording a bit on the builin atomic* documentation.

Remove the (second) builtin compileLog example that demonstrated a lack of
compileLog entries.

* langref: address comments from rohlem

Use "0-terminated" instead of "null-terminated".

Undo some changes that were not as clear an improvement as I though.

* langref: remove stray ""

Thanks to rohlem for spotting this typo.
2023-09-21 17:50:48 +03:00