24525 Commits

Author SHA1 Message Date
Eric Joldasov
d04a262a3d
std.math: hard deprecate obsolete constants (soft deprecated in 0.10)
Followup to 5b8ac9821dd25c3e5282130b4d93d6c5b7debb08.
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:45:12 +06:00
Eric Joldasov
eb4439f1e4
std.meta: remove Vector (deprecated in 0.10)
Followup to d42d31f72f38165f70c2850e9cc63da44b3b470c.
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:45:08 +06:00
Andrew Kelley
df6319418a
Merge pull request #15880 from mlugg/feat/better-switch-zir-2
Simplify and compact switch ZIR, and resolve union payload captures with PTR
2023-06-13 08:45:12 -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
529ef75101
Merge pull request #15569 from ziglang/intern-pool-3
Use InternPool for all types and constant values
2023-06-12 22:50:50 -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
4b7c1e5c30 tools: add LLDB pretty printer for InternPool.NullTerminatedString 2023-06-12 18:24:21 -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
52e7934a21 std.dwarf: fix findCompileUnit when ranges offset is given by const 2023-06-12 14:22:45 -07:00
mlugg
1ec14988e1 build: add -Dno-bin option
This is useful for development, as it speeds up the process of getting
semantic analysis errors significantly.
2023-06-12 14:22:32 -07:00
mlugg
415dbe93d4 link: fix compile error with only-c 2023-06-12 14:22:19 -07:00
mlugg
9e61ba19e9 std.crypto.tls.Client: fix @memcpy crash in limitedOverlapCopy
Resolves: #15928
2023-06-12 14:22:09 -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
Jacob Young
f94c66825e langref: fix error set order 2023-06-10 20:51:10 -07:00
Jacob Young
44d8cf9331 wasm: address behavior test regressions 2023-06-10 20:51:10 -07:00
Jacob Young
dce80f67d4 Sema: fix crashes accessing undefined values 2023-06-10 20:51:10 -07:00
mlugg
7702af5eb2 Sema: fix int arithmetic overflow checks
Previously, these checks worked by performing the arithmetic operation,
then checking whether the result fit in the type in question. Since all
values are now typed, this approach was no longer valid, and was
tripping some assertions due to trying to store too-large values in
smaller types.

Now, `intAdd`, `intSub`, `intMul` and `intDiv` all check for overflow,
and if it happens, re-do the operation with the result being a
`comptime_int`, and reporting the error (and vector index) to the caller
so that the error can be reported.

After this change, all test cases are passing.
2023-06-10 20:51:10 -07:00
mlugg
2a6b91874a stage2: pass most test cases under InternPool
All but 2 test cases now pass (tested on x86_64 Linux, native only). The
remaining two signify an issue requiring a larger refactor, which I will
do in a separate commit.

Notable changes:
* Fix uninitialized memory when allocating objects from free lists
* Implement TypedValue printing for pointers
* Fix some TypedValue printing logic
* Work around non-existence of InternPool.remove implementation
2023-06-10 20:51:10 -07:00
Andrew Kelley
ab86b20248 std.hash: improve small-key hashing in Wyhash
Instead of carrying an optimized version of wyhash in the compiler for
small keys, put it into the std lib where it belongs.

...except it does not match the official test cases. This will need to
be fixed before merging into master. This is an extremely
contributor-friendly task.

Related issue: #15916
2023-06-10 20:51:09 -07:00
Andrew Kelley
7c12e064c4 Sema: reword compile error about LLVM extensions and C import 2023-06-10 20:47:59 -07:00
Jacob Young
e23b0a01e6 InternPool: fix yet more key lifetime issues 2023-06-10 20:47:59 -07:00
Jacob Young
6a15fc87ad Sema: handle generic types when coercing functions in memory
This used to be handled by `Type.eql`, but that is now a single comparison.
2023-06-10 20:47:59 -07:00
Jacob Young
ad54f47b95 InternPool: optimize previous fix
Just because we can't dedup, doesn't mean we can't use `string_bytes`.
2023-06-10 20:47:59 -07:00
mlugg
0fd52cdc5e InternPool: avoid aggregate null bytes storage
This is a workaround for InternPool currently not handling
non-null-terminated strings. It avoids using the `bytes` storage for
aggregates if there are any null bytes.

In the future this should be changed so that the `bytes` storage can be
used regardless of whether there are any null bytes. This is important
for use cases such as `@embedFile`.

However, this fixes a bug for now, and after this commit, stage2
self-hosts again.

mlugg: stage5 passes all enabled behavior tests on my system.

Commit message edited by Andrew Kelley <andrew@ziglang.org>
2023-06-10 20:47:59 -07:00
mlugg
0f80652efb Sema: remove leftover references to value_arena
Notably, there was a bug where the fields of reified structs and unions
were allocated into an arena which was leaked. These are now in the
Module.tmp_hack_arena.
2023-06-10 20:47:59 -07:00
Jacob Young
7a59cd2863 Sema: hack around UAF 2023-06-10 20:47:59 -07:00
Jacob Young
da24ea7f36 Sema: rewrite monomorphed_funcs usage
In an effort to delete `Value.hashUncoerced`, generic instantiation has
been redesigned.  Instead of just storing instantiations in
`monomorphed_funcs`, partially instantiated generic argument types are
also cached.  This isn't quite the single `getOrPut` that it used to be,
but one `get` per generic argument plus one get for the instantiation,
with an equal number of `put`s per unique instantiation isn't bad.
2023-06-10 20:47:59 -07:00
Jacob Young
04e66e6b4d InternPool: add optional coercion 2023-06-10 20:47:59 -07:00
Jacob Young
fdfe730487 InternPool: fix more key lifetime issues 2023-06-10 20:47:59 -07:00
Jacob Young
bc3b56f957 llvm: fix undefined pointer type 2023-06-10 20:47:59 -07:00
Andrew Kelley
35550c840b Module: fix populateTestFunctions UAF 2023-06-10 20:47:59 -07:00