24515 Commits

Author SHA1 Message Date
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
Andrew Kelley
f1c900c72e compiler: avoid use of undefined memory
InternPool is nice in some ways but it also comes with its own set of
footguns. This commit fixes 5 instances. I see quite a few Valgrind
warnings remaining when running the behavior tests.

Perhaps the solution is to have stringToSlice return a struct with start
and length as indexes, which has a format function?
2023-06-10 20:47:59 -07:00
Andrew Kelley
69b7b91092 compiler: eliminate Decl.value_arena and Sema.perm_arena
The main motivation for this commit is eliminating Decl.value_arena.
Everything else is dominoes.

Decl.name used to be stored in the GPA, now it is stored in InternPool.
It ended up being simpler to migrate other strings to be interned as
well, such as struct field names, union field names, and a few others.
This ended up requiring a big diff, sorry about that. But the changes
are pretty nice, we finally start to take advantage of InternPool's
existence.

global_error_set and error_name_list are simplified. Now it is a single
ArrayHashMap(NullTerminatedString, void) and the index is the error tag
value.

Module.tmp_hack_arena is re-introduced (it was removed in
eeff407941560ce8eb5b737b2436dfa93cfd3a0c) in order to deal with
comptime_args, optimized_order, and struct and union fields. After
structs and unions get moved into InternPool properly, tmp_hack_arena
can be deleted again.
2023-06-10 20:47:58 -07:00
Andrew Kelley
34dae73005 std.hash: auto hash signed ints as bitcasts of unsigned ints 2023-06-10 20:47:58 -07:00
mlugg
e0179640d5 Sema: intern values of mutable decls after analysis
This is necessary with the upcoming removal of Decl.value_arena to
prevent UAF of these values.
2023-06-10 20:47:58 -07:00
Jacob Young
e8bcdca044 Sema: fix in-memory coercion during comptime load 2023-06-10 20:47:58 -07:00
Jacob Young
dc18739a73 process: add more missing const 2023-06-10 20:47:58 -07:00
Jacob Young
e2174428e8 wasm: implement missing case 2023-06-10 20:47:58 -07:00
Jacob Young
8299ddfe4f InternPool: fix more key lifetime issues
Reminder to look into deleting `get` and make keys less pointery and
more long lived.
2023-06-10 20:47:58 -07:00
mlugg
9b48fc2833 Allocate capture scopes in gpa instead of Decl.value_arena
This eliminates the last major use of value_arena, in preparation to
remove it.
2023-06-10 20:47:58 -07:00
Jacob Young
cab79b0877 lib: add const to avoid regression
Not sure if this was meant to be legal or not, but either way this code
should have been using const anyway.
2023-06-10 20:47:58 -07:00