12417 Commits

Author SHA1 Message Date
Andrew Kelley
a10ddba921
Merge pull request #16064 from Luukdegram/wasm-linker
wasm/linker: symbol resolution improvements
2023-06-16 22:03:35 -07:00
Andrew Kelley
78c8cb4225
Merge pull request #16003 from g-w1/plan9-lazy-syms
Plan9: lots of fixes
2023-06-16 21:57:33 -07:00
Veikka Tuominen
0f5aff3441 zig build: add option to only print failed steps
The motivating case for this is that currently when a test fails
the CI log will include ~5k lines of listing steps that succeeded.
2023-06-16 15:17:59 -07:00
mlugg
2af5bd8aa8 Autodoc: fix crash when walking @min/@max with two operands
This was causing CI failures after the previous commit.
2023-06-16 13:44:25 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
mlugg
c4cc796695 Sema: consider type bounds when refining result type of @min/@max
I achieved this through a major refactor of the logic of analyzeMinMax.
This change should be compatible with vectors of comptime_int, which
Andrew said are supposed to work (but which currently do not).
2023-06-16 13:33:31 -07:00
Luuk de Gram
44b322ce64
wasm-linker: correctly resolve undefined functions
We now resolve undefined symbols during incremental-compilation
where we discard the current symbol if we detect we found
an existing symbol which is not the one currently being updated.
The symbol will always be discarded in favor of the existing symbol
in such a case.
2023-06-16 17:16:56 +02:00
Luuk de Gram
e3db210cf1
wasm: support calling alias'd function pointers
When lowering a decl value we verify whether its owner decl index
equals to the decl index of the decl being lowered. When this is not
the case, we are lowering an alias. So instead, we will now lower
the owner decl instead and call its symbol to ensure its type
is being correctly generated.
2023-06-16 17:16:56 +02:00
Luuk de Gram
1cfad29f10
codegen: fix union padding
This regressed during the internpool merges. This commit
reinstates the padding logic for unions.
2023-06-16 17:16:56 +02:00
Luuk de Gram
098b0b50ab
wasm: fix lowerParentPtr offsets
The was incorrectly merged during internPool. This commit forward
fixes that and reinstates the correct logic.
2023-06-16 17:16:56 +02:00
Luuk de Gram
729f822e31
wasm-linker: correctly resolve exported symbols
When compiling Zig code using the Wasm backend, we would previously
incorrectly resolve exported symbols as it would not correctly remove
existing symbols if they were to be overwritten. This meant that
undefined symbols could cause collisions although they should be
resolved by the exported symbol.
2023-06-16 17:16:55 +02:00
Jacob G-W
5343a2f566 plan9: revamp the relocation system to allow decl refs 2023-06-16 08:34:30 -04:00
Jacob G-W
153def1460 Elf: fix memory leak with lazy symbols 2023-06-16 08:34:30 -04:00
Jacob G-W
9e8c7b104e Plan9: Add support for lazy symbols
This includes a renaming from DeclBlock to Atom.
2023-06-16 08:34:30 -04:00
Jacob Young
2d6d2a1d11 cbe: add missing cast for @intToPtr values 2023-06-15 14:06:49 -07:00
Andrew Kelley
f5043ad6a3
Merge pull request #16042 from mlugg/fix/slice-len-comptime-mutation
Fix comptime mutation of slice len
2023-06-15 09:49:59 -07:00
mlugg
11d0dfb882 Sema: fix @intToPtr of zero value to optional pointer
Calling into coercion logic here is a little opaque, and more to the
point wholly unnecessary. Instead, the (very short) logic is now
implemented directly in Sema.

Resolves: #16033
2023-06-15 02:43:06 -07:00
mlugg
ce88c43a4e Sema: allow indexing tuple and vector pointers
Resolves: #13852
Resolves: #14705
2023-06-14 22:07:25 -07:00
mlugg
57f6e6729f
Sema: allow empty end index in zirSliceSentinel
This fixes a regression, and enables some related behavior tests which
were accidentally disabled.
2023-06-15 01:23:58 +01:00
mlugg
45e9617720
Sema: don't assume slice value is interned when loading from comptime pointer
Resolves: #16030
2023-06-15 01:23:52 +01:00
Andrew Kelley
496320d935
Merge pull request #15726 from mlugg/feat/peer-type-resolution-but-better
Sema: rewrite peer type resolution
2023-06-14 07:18:28 -07:00
mlugg
8a92beb088
Sema: move all in-memory coercion logic to InternPool
Previously, this logic was split between Sema.coerceValueInMemory and
InternPool.getCoerced. This led to issues when trying to coerce e.g. an
optional containing an aggregate, because we'd call through to
InternPool's version which only recurses on itself so could not coerce
aggregates. Unifying them is fairly simple, and also simplified a bit of
logic in Sema.

Also fixes a key lifetime bug in aggregate coercion.
2023-06-13 21:48:21 +01:00
mlugg
588f45a0a1
Sema: allow in-memory coercion of tuples
This allows tuples whose fields are in-memory coercible to themselves be
coerced in memory. No InMemoryCoercionResult field has been added, so in
future one could be added to improve error messages.
2023-06-13 21:48:21 +01:00
mlugg
c9531eb833
Sema: rewrite peer type resolution
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: #15138
Resolves: #15644
Resolves: #15693
Resolves: #15709
Resolves: #15752
2023-06-13 21:48:18 +01:00
Jan200101
d7b73af8f6 Never implicitly add rpaths for each lib dir, add NixOS libdir to rpath 2023-06-13 11:11:10 -07:00
IntegratedQuantum
02df9aa976 Add a compiler error for @mulAdd with int vectors. 2023-06-13 10:45:57 -07:00
mlugg
42dc7539c5
Fix bad source locations in switch capture errors
To do this, I expanded SwitchProngSrc a bit. Several of the tags there
aren't actually used by any current errors, but they're there for
consistency and if we ever need them.

Also delete a now-redundant test and fix another.
2023-06-13 12:55:27 +01:00
mlugg
bcb673d94a
Sema: resolve union payload switch captures with peer type resolution
This is a bit harder than it seems at first glance. Actually resolving
the type is the easy part: the interesting thing is actually getting the
capture value. We split this into three cases:

* If all payload types are the same (as is required in status quo), we
  can just do what we already do: get the first field value.
* If all payloads are in-memory coercible to the resolved type, we still
  fetch the first field, but we also emit a `bitcast` to convert to the
  resolved type.
* Otherwise, we need to handle each case separately. We emit a nested
  `switch_br` which, for each possible case, gets the corresponding
  union field, and coerces it to the resolved type. As an optimization,
  the inner switch's 'else' prong is used for any peer which is
  in-memory coercible to the target type, and the bitcast approach
  described above is used.

Pointer captures have the additional constraint that all payload types
must be in-memory coercible to the resolved type.

Resolves: #2812
2023-06-13 12:55:22 +01:00
mlugg
85e94fed1e
Eliminate switch_cond[_ref] ZIR tags
This finishes the process of consolidating switch expressions in ZIR
into as simple and compact a representation as is possible. There are
now just two ZIR tags dedicated to switch expressions: switch_block and
switch_block_ref, with the latter being for an operand passed by
reference.
2023-06-13 12:55:15 +01:00
mlugg
39510cc7d1
Eliminate switch_capture_tag ZIR instruction
This is a follow-up to a previous commit which eliminated switch_capture
and switch_capture_ref. All captures are now handled directly by
`switch_block`, which has also eliminated some unnecessary Block data in
Sema.
2023-06-13 12:55:01 +01:00
mlugg
ec27524da9
Sema: minor refactor to switch prong analysis 2023-06-13 12:54:20 +01:00
mlugg
00609e7edb
Eliminate switch_capture and switch_capture_ref ZIR tags
These tags are unnecessary, as this information can be more efficiently
encoded within the switch_block instruction itself. We also use a neat
little trick to avoid needing a dummy instruction (like is used for
errdefer captures): since the switch_block itself cannot otherwise be
referenced within a prong, we can repurpose its index within prongs to
refer to the captured value.
2023-06-13 12:53:18 +01:00
mlugg
cebd80032a
Move switch case value coercion from AstGen to Sema
This is in preparation for #2473. Also fixes a bug where switching on
bools allows invalid case combinations.
2023-06-13 12:50:49 +01:00
mlugg
a377bf87ce
Zir: remove unnecessary switch_capture_multi instructions
By indexing from the very first switch case rather than into scalar and
multi cases separately, the instructions for capturing in multi cases
become unnecessary, freeing up 2 ZIR tags.
2023-06-13 12:42:31 +01:00
ypsvlq
387f9568ad
Sema: check runtime safety is enabled when unwrapping error 2023-06-13 00:28:06 -07:00
Andrew Kelley
2ad073ec6d link/Plan9: fix UAF of symbol names
Long term, linker backends will need to manage their own string tables
for things like this because my mandate is: no long-lived pointers
allowed in any of the codepaths touched by incremental compilation, so
that we can serialize and deserialize trivially.

Short term, I solved this with a couple calls to Allocator.dupe,
incurring some harmless leaks.
2023-06-12 19:09:30 -07:00
mlugg
ff35a180dd Sema: intern values from resolved inferred allocs 2023-06-12 18:24:17 -07:00
Jacob Young
3d48c406c1 Sema: redo monomorphed funcs to make more sense
By correctly handling comptime-only types appearing in non-comptime
parameters (when the parameter is either anytype or generic), this
avoids an index out of bounds later when later filling out
`monomorphed_args` using what used to be slightly different logic.
2023-06-12 18:24:01 -07:00
mlugg
415dbe93d4 link: fix compile error with only-c 2023-06-12 14:22:19 -07:00
Jacob Young
028f2ed30f InternPool: fix one more compile error on 32-bit targets 2023-06-12 12:07:38 -07:00
Jacob Young
d37ebfcf23 InternPool: avoid as many slices pointing to string_bytes as possible
These are frequently invalidated whenever a string is interned, so avoid
creating pointers to `string_bytes` wherever possible.  This is an
attempt to fix random CI failures.
2023-06-11 23:45:09 -07:00
mlugg
54460e39ac Autodoc: make it work under InternPool 2023-06-11 22:04:15 -07:00
mlugg
5b6906c22e InternPool: fix dbHelper after 4976b58
You must now write '_ = &f' rather than just '_ = f' to ensure a
function is compiled into a binary.
2023-06-11 22:04:01 -07:00
mlugg
63604024f4 stage2: fix InternPool compile errors on 32-bit targets 2023-06-11 22:03:53 -07:00
Jacob Young
2afc689060 Sema: fix condition for emitting noreturn safety check 2023-06-11 03:01:37 -07:00
Jacob Young
7507a76879 link: use Wasm.string_table offsets for Wasm.undefs keys
This avoids having dangling pointers into `InternPool.string_bytes`.
2023-06-11 03:01:31 -07:00
Jacob Young
7e5dea6366 Sema: fix std.builtin.Type.EnumField.value when not auto-numbered 2023-06-11 03:01:26 -07:00
Jacob Young
0ec012e0c0 TypedValue: fix code formatting 2023-06-11 03:01:22 -07:00
Jacob Young
b9a4eae349 llvm: fix more name lifetimes
Hopefully this also fixes the non-reproducing CI failures.
2023-06-11 03:01:17 -07:00
Jacob Young
a01bc7776f llvm: fix name lifetime 2023-06-10 20:51:10 -07:00