Commit graph

24776 commits

Author SHA1 Message Date
Andrew Kelley
8bc759e094 compiler: free up two ZIR tags 2023-06-26 15:57:07 -07:00
Andrew Kelley
3faa550dc2 stage2 async progress
After analyzing function body, check call instructions and determine
whether it is an async function or not.

LLVM backend: support lowering trivial async functions
2023-06-26 15:57:07 -07:00
Andrew Kelley
e45b10f3d4 stage2: implement suspend blocks
* AstGen: suspend blocks are always void
 * add new AIR instructions: suspend_begin and suspend_end
 * Module: after a function's body is analyzed, conclude that it is not
   async if it wasn't proven async during analysis.
 * LLVM: implement lowering of suspend_begin and suspend_end.

There is a lot to do in this branch. I started a branch-local TODO list
in the BRANCH_TODO file. All of these tasks should be finished before
merging into master.
2023-06-26 15:57:07 -07:00
Andrew Kelley
f1b7c76ae9 LLVM: implement call_async_alloc
It's based on a runtime alloca based on the frame size. This allows us
to lower async function calls before lowering the callee, and allows
updating callees without updating the callers.

Sema: add `std.debug.Trace` integration for `unneeded`. This helps us
debug when `LazySrcLoc.unneeded` was incorrectly used.
2023-06-26 15:57:07 -07:00
Andrew Kelley
a6eb83bd1b AIR: add call_async_alloc instruction
This is for async calls that also act as an alloca. This helps avoid
unnecessarily complicated machinery for the simple case of
`var a = async b();`.

The `call_async` instruction has a frame pointer and returns void
always, which will be used for the other form: `a = async b();`.
2023-06-26 15:57:06 -07:00
Andrew Kelley
e70c34cdb7 stage2: implement async_call
* AstGen emits async_call instruction for variable declarations of
   async calls.
 * Sema analyzes async_call instruction.
 * Liveness handles call_async AIR instruction.
 * Fix Type.eql for async frame types.
2023-06-26 15:57:06 -07:00
Andrew Kelley
5a8c445779 stage2: add call_async ZIR instruction
This is to be used when the source code looks like this:

    var a = async b();

The instruction acts both as an alloc as well as a function call using
that alloc as the result location. This avoids multiple ZIR instructions
as well as complicated "inferred pointer" semantic analysis for a common
case.

AstGen is not yet updated to emit this new instruction.
2023-06-26 15:57:06 -07:00
Meghan Denny
7322aa1183 std.Uri: allow getting the mutable result from (un)escape 2023-06-26 15:46:04 +03:00
Jan200101
42ca357604 std.Build: omit newline from last line 2023-06-26 04:25:14 -07:00
Jobat
d5ebe3e395 Change capacity to take a non-pointer parameter
I don't believe there's a requirement for this to take a pointer, as the underlying function doesn't.
2023-06-26 02:05:28 -07: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
Roman Frołow
dce1999c80 is has -> has 2023-06-25 23:30:25 -07: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
7013567f8a x86_64: disable failing behavior test 2023-06-25 19:14:03 -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
Maciej 'vesim' Kuliński
d98147414d update Ascon.zig to use @min builtin 2023-06-25 15:39:17 -07: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
David CARLIER
d07149c56d std.c: few freebsd's kinfo api fixes.
following up on 4a0508e and 3dd0afe.

- kinfo_vmentry, removing kve_ prefix.
- kinfo_getproc, returns one entry at most.
2023-06-25 12:27:45 -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
Evin Yulo
17e12960b5 remove mention of stage1 from langref 2023-06-25 21:13:56 +03:00
mlugg
b66865d059
std.pdb: fix incorrect field alignment in ptrCast 2023-06-25 14:13:52 +01: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
fec7565da6
behavior: add tests for cast builtins coercing to optional and error union 2023-06-25 13:28:32 +01:00
mlugg
d249629ef1
cases: add tests for errors introduced by cast builtin result type inference 2023-06-25 13:28:32 +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
mlugg
5311916928
langref: neaten up @errSetCast example 2023-06-25 13:28:31 +01:00
Josh Wolfe
3f04231600 std: re-pub new json symbols in json.zig 2023-06-25 04:56:38 -07: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
f10b9e8fd7.
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
Andrew Kelley
146b79af15
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
2023-06-24 16:58:19 -07:00
mlugg
21ac0beb43 update zig1.wasm
Needed due to the breaking changes to casting builtins, which are used
by the compiler when building itself.

Note from Andrew: I re-ran update-zig1 on my PC and replaced this
commit.

Signed-off-by: Andrew Kelley <andrew@ziglang.org>
2023-06-24 16:56:54 -07:00