12417 Commits

Author SHA1 Message Date
Krzysztof Wolicki
0c1bfe271e autodoc: Correct a comment about types from std.builtin 2023-06-28 19:03:24 +02:00
Krzysztof Wolicki
2984a75804 autodoc: Try to handle all InternPool.Index types good enough 2023-06-28 19:03:24 +02:00
Alex Kladov
4620972d08 Sema: preserve extern struct field alignment
In

    extern struct { x: u32, y: u16 }

we actually know that y's alignment is `@alignOf(u32)`, and not just
`@alignOf(u16)`.

closes: #16134
2023-06-28 16:36:32 +02:00
Motiejus Jakštys
910ad92e0e ld: support -version-script
gettext uses this version and, surely enough, it is supported by lld
2023-06-28 09:32:10 +02:00
r00ster91
2463f4df77 addrspace: small cleanups 2023-06-27 19:50:17 -04:00
r00ster91
8385b2c379 Sema.analyzeBodyInner: fix some spaces 2023-06-27 19:50:17 -04:00
r00ster91
11c32c756f fix u65529 and above overflowing in more places
See also #15537
2023-06-27 19:08:24 -04:00
Krzysztof Wolicki
7f648c297e autodoc: Added u0, i0 to correctly indexed types 2023-06-27 19:07:39 +02:00
Luuk de Gram
622c5f3200
Merge pull request #16207 from Luukdegram/wasi-threads
WASI: Implement experimental threading support
2023-06-27 18:28:26 +02:00
mlugg
ff37ccd298 Air: store interned values in Air.Inst.Ref
Previously, interned values were represented as AIR instructions using
the `interned` tag. Now, the AIR ref directly encodes the InternPool
index. The encoding works as follows:
* If the ref matches one of the static values, it corresponds to the same InternPool index.
* Otherwise, if the MSB is 0, the ref corresponds to an InternPool index.
* Otherwise, if the MSB is 1, the ref corresponds to an AIR instruction index (after removing the MSB).

Note that since most static InternPool indices are low values (the
exceptions being `.none` and `.var_args_param_type`), the first rule is
almost a nop.
2023-06-27 01:21:32 -07:00
Jacob Young
d881d841ed Sema: use tmp_hack_arena as a temporary solution for lifetime issues
All of this code is expected to get rewritten anyway.

Closes #16216
2023-06-27 00:46:31 -07:00
Jacob Young
9343c31c38 Sema: fix @min/@max type resolution with all runtime args
Closes #16229
2023-06-26 18:46:25 -07:00
Ali Chraghi
6bd5479306 std.sort.block: add safety check for lessThan return value 2023-06-26 17:50:10 -07:00
mlugg
88284c124a AstGen: fix result locations for elements of typed array init
Resolves: #16226
2023-06-26 16:20:33 -07:00
Luuk de Gram
87b8a0567b
default to single-threaded for WebAssembly
When targeting WebAssembly, we default to building a single-threaded build
as threads are still experimental. The user however can enable a multi-
threaded build by specifying '-fno-single-threaded'. It's a compile-error
to enable this flag, but not also enable shared-memory.
2023-06-26 20:00:58 +02:00
Luuk de Gram
062eb6f3c0
Compilation: allow threads for Wasm when shared-memory is enabled
When the user enabled the linker-feature 'shared-memory' we do not force
a singlethreaded build. The linker already verifies all other CPU features
required for threads are enabled. This is true for both WASI and
freestanding.
2023-06-26 20:00:57 +02:00
Luuk de Gram
3819371163
wasm-ld: implement --export-memory flag
This flag allows the user to force export the memory to the host
environment. This is useful when the memory is imported from the
host but must also be exported. This is (currently) required
to pass the memory validation for runtimes when using threads.
In this future this may become an error instead.
2023-06-26 20:00:57 +02:00
Jacob Young
c036f83fa0 Value: fix incorrect types returned from readFromMemory 2023-06-26 01:30:00 -07:00
jacobly0
cc2daae47e
Merge pull request #15771 from jacobly0/x86_64-behavior
x86_64: behavior
2023-06-26 02:45:48 -04:00
Andrew Kelley
40cf3f7ae5
Merge pull request #15995 from mlugg/fix/union-field-ptr-align
Sema: copy pointer alignment to union field pointers
2023-06-25 23:06:53 -07:00
Jacob Young
85902115d4 x86_64: cleanup @as invasion 2023-06-25 19:14:26 -04:00
Jacob Young
1a1930ec9b x86_64: fix test failure 2023-06-25 19:14:03 -04:00
Jacob Young
0e15b6e973 x86_64: fix incorrect encoding table entries
This was found by downstream tests.
2023-06-25 19:14:03 -04:00
Jacob Young
b4b1ad475b x86_64: truncate packed field value 2023-06-25 19:14:03 -04:00
Jacob Young
3f13987a76 x86_64: add missing padding to global unions 2023-06-25 19:14:03 -04:00
Jacob Young
e13aa915b2 x86_64: add error for saturating arithmetic 2023-06-25 19:14:03 -04:00
Jacob Young
5b74278510 x86_64: fix global pointers to packed struct fields 2023-06-25 19:14:03 -04:00
Jacob Young
9d0b8a27b6 x86_64: add unimplemented error for float @rem/@mod 2023-06-25 19:14:03 -04:00
Jacob Young
8d30cb3f22 x86_64: turn f80 operation crashes into errors 2023-06-25 19:14:03 -04:00
Jacob Young
b18a72ec35 x86_64: fix crash emitting a packed undefined u128 2023-06-25 19:14:03 -04:00
Jacob Young
054536f343 x86_64: fix unimplemented type crashes 2023-06-25 19:14:03 -04:00
Jacob Young
614c807702 x86_64: fix packed store crash 2023-06-25 19:14:03 -04:00
Eric Joldasov
0a868dacdd std.cstr: deprecate namespace
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-25 14:51:03 -07:00
Jakub Konka
852eb272bf macho: add fixes to __eh_frame parsing emitted by Nix C++ compiler 2023-06-25 14:33:00 -07:00
Andrew Kelley
df389b62de
Merge pull request #16192 from mlugg/builtins-infer-dest-ty-fixes
Follow-up to cast builtin result type inference
2023-06-25 12:38:56 -07:00
Jacob Young
b9c4857ed6 AstGen: add source location to certain const initializers
Before:

    assign_local_bad_coercion.zig:5:1: error: expected type 'u32', found 'u64'
    export fn constEntry() u32 {
    ^~~~~~
    assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64'
        var x: u32 = g();
                     ~^~

After:

    assign_local_bad_coercion.zig:6:21: error: expected type 'u32', found 'u64'
        const x: u32 = g();
                       ~^~
    assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64'
        var x: u32 = g();
                     ~^~
2023-06-25 12:00:48 -07:00
mlugg
80e493cb36
Sema: copy pointer alignment to struct field pointers 2023-06-25 14:13:52 +01:00
mlugg
2611d97fb0
Sema: copy pointer alignment to union field pointers
This implements the semantics as discussed in today's compiler meeting,
where the alignment of pointers to fields of default-layout unions
cannot exceed the field's alignment.

Resolves: #15878
2023-06-25 14:05:18 +01:00
mlugg
569ae762e1
compiler: allow cast builtins to coerce result to error union or optional
Also improves some error messages
2023-06-25 13:28:32 +01:00
mlugg
8afadee45a
AstGen: use usize as result type of for loop range operands 2023-06-25 13:28:31 +01:00
Frank Denis
e7f872c9c6
wasi-libc: compile emmalloc.c without strict aliasing (#16157)
emmalloc.c does a fair amount of type punning in order to access
the size of memory regions and traverse them.

Unfortunately, that can lead to unwanted optimizations.

This simple test case currently triggers a memory fault:

int main(void) {
    char * volatile p = malloc(1);
    p = realloc(p, 12);
    p = malloc(1);
    printf("%p\n", p);
}

Work around this by adding "-fno-strict-aliasing" when compiling
that file.
2023-06-25 11:24:54 +02:00
Ryan Liptak
b111702940 Recognize the .res extension and link it as if it were an object file
.res files are compiled Windows resource files that get linked into executables/libraries. The linker knows what to do with them, but previously you had to trick Zig into thinking it was an object file (by renaming it to have the .obj extension, for example).

After this commit, the following works:

    zig build-exe main.zig resource.res

or, in build.zig:

    exe.addObjectFile("resource.res");

Closes #6488
2023-06-25 01:42:12 -07:00
Andrew Kelley
9684947faa compiler: start moving safety-checks into backends
This actually used to be how it worked in stage1, and there was this
issue to change it: #2649

So this commit is a reversal to that idea. One motivation for that issue
was avoiding emitting the panic handler in compilations that do not have
any calls to panic. This commit only resolves the panic handler in the
event of a safety check function being emitted, so it does not have that
flaw.

The other reason given in that issue was for optimizations that elide
safety checks. It's yet to be determined whether that was a good idea or
not; this can get re-explored when we start adding optimization passes
to AIR.

This commit adds these AIR instructions, which are only emitted if
`backendSupportsFeature(.safety_checked_arithmetic)` is true:
 * add_safe
 * sub_safe
 * mul_safe

It removes these nonsensical AIR instructions:
 * addwrap_optimized
 * subwrap_optimized
 * mulwrap_optimized

The safety-checked arithmetic functions push the burden of invoking the
panic handler into the backend. This makes for a messier compiler
implementation, but it reduces the amount of AIR instructions emitted by
Sema, which reduces time spent in the secondary bottleneck of the
compiler. It also generates more compact LLVM IR, reducing time spent in
the primary bottleneck of the compiler.

Finally, it eliminates 1 stack allocation per safety-check which was
being used to store the resulting tuple. These allocations were going to
be annoying when combined with suspension points.
2023-06-25 01:41:08 -07:00
Andrew Kelley
82ad66b2f2 liveness: fix merge typo logic error
Oops, I made a terrible mistake when applying a small fixup when merging
f10b9e8fd72aae33b127c18e3f8a64a4f56b1b69.
2023-06-25 01:02:55 -07:00
Andrew Kelley
a31ba25a3d
Merge pull request #16188 from kcbanner/fix_cbe_airErrUnionPayloadPtrSet
cbe: fix crash caused by calling `mod.intValue` on `type_inferred_error_set`
2023-06-24 21:53:59 -07:00
mlugg
67997a699a cbe: codegen int_from_ptr of slice correctly
CBE was translating to access the `len` field rather than `ptr`.
Air.zig specifies that this operation is valid on a slice.
2023-06-24 16:56:40 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
mlugg
447ca4e3ff translate-c: update to new cast builtin syntax 2023-06-24 16:47:49 -07:00
mlugg
be0c69957e compiler: remove destination type from cast builtins
Resolves: #5909
2023-06-24 16:47:49 -07:00
Matteo Briani
8ced903d61
Add support for the "--version" linker argument (#16154)
closes #15549

Co-authored-by: Matteo Briani <matteo.briani@icvox.com>
2023-06-24 16:24:50 -04:00