12417 Commits

Author SHA1 Message Date
Andrew Kelley
684aee3220 frontend: fixes for function regressions in this branch
* Introduce InternPool.Tag.func_coerced to handle the case of a
   function body coerced to a new type. `InternPool.getCoerced` is now
   implemented for function bodies in this branch.
 * implement resolution of ad-hoc inferred error sets in
   `Sema.analyzeCall`.
 * fix generic_owner being set wrong for child Sema bodies of param
   expressions.
 * fix `Sema.resolveInferredErrorSetTy` when passed `anyerror`.
2023-07-18 19:02:06 -07:00
Andrew Kelley
927f6ec8ca frontend: fix inferred error sets of comptime/inline calls
Previously, they shared function index with the owner decl, but that
would clobber the data stored for inferred error sets of runtime calls.

Now there is an adhoc_inferred_error_set_type which models the problem
much more correctly.
2023-07-18 19:02:06 -07:00
Andrew Kelley
82db06fa67 InternPool: fix regression in getting error sets
Missing call to `addStringsToMap`.
2023-07-18 19:02:06 -07:00
Andrew Kelley
d98526f912 Type.print: fix inferred error set crash
The index is a function, not an inferred error set.
2023-07-18 19:02:05 -07:00
Andrew Kelley
b81d193021 InternPool: implement getFuncInstanceIes
and fix bug in equality checking for functions with inferred error sets.
2023-07-18 19:02:05 -07:00
Andrew Kelley
8f37b794a5 InternPool: fix debug info helpers for changes to functions
It still doesn't work correctly due to incorrect debug info for packed
structs.
2023-07-18 19:02:05 -07:00
Andrew Kelley
cbbb5cc2ec InternPool: implement getFuncInstance
This handles the case without an inferred error set. Still TODO is the
case with one.

Also fixes branchQuota returning a pointer to the wrong field.
2023-07-18 19:02:05 -07:00
Andrew Kelley
6d72f971af InternPool: implement getExternFunc 2023-07-18 19:02:05 -07:00
Andrew Kelley
8fd77395d6 InternPool: fix getErrorSetType
Before, it incorrectly passed an InternPool.Index where an extra array
index was expected (to the function which is renamed to `extraErrorSet`
in this commit).
2023-07-18 19:02:05 -07:00
Andrew Kelley
c193872c81 InternPool: implement indexToKey for func_instance and func_decl
Also delete incorrect frees an arena-allocated parameters.
2023-07-18 19:02:05 -07:00
Andrew Kelley
4a55fc6c53 InternPool: avoid false negatives for functions with inferred error sets
There is one case where function types may be inequal but we still want
to find the same function body instance in InternPool.

In the case of the functions having an inferred error set, the key used
to find an existing function body will necessarily have a unique
inferred error set type, because it refers to the function body
InternPool Index. To make this case work we omit the inferred error set
from the equality and hashing functions.
2023-07-18 19:02:05 -07:00
Andrew Kelley
f3dc53f6b5 compiler: rework inferred error sets
* move inferred error sets into InternPool.
   - they are now represented by pointing directly at the corresponding
     function body value.
 * inferred error set working memory is now in Sema and expires after
   the Sema for the function corresponding to the inferred error set is
   finished having its body analyzed.
 * error sets use a InternPool.Index.Slice rather than an actual slice
   to avoid lifetime issues.
2023-07-18 19:02:05 -07:00
Andrew Kelley
55e89255e1 compiler: begin untangling anonymous decls from source decls
The idea here is to move towards a future where anonymous decls are
represented entirely by an `InternPool.Index`. This was needed to start
implementing `InternPool.getFuncDecl` which requires moving creation and
deletion of Decl objects into InternPool.

 * remove `Namespace.anon_decls`
 * remove the concept of cleaning up resources from anonymous decls,
   relying on InternPool instead.
 * move namespace and decl object allocation into InternPool
2023-07-18 19:02:05 -07:00
Andrew Kelley
db33ee45b7 rework generic function calls
Abridged summary:

 * Move `Module.Fn` into `InternPool`.
 * Delete a lot of confusing and problematic `Sema` logic related to
   generic function calls.

This commit removes `Module.Fn` and replaces it with two new
`InternPool.Tag` values:

 * `func_decl` - corresponding to a function declared in the source
   code. This one contains line/column numbers, zir_body_inst, etc.

 * `func_instance` - one for each monomorphization of a generic
   function. Contains a reference to the `func_decl` from whence the
   instantiation came, along with the `comptime` parameter values (or
   types in the case of `anytype`)

Since `InternPool` provides deduplication on these values, these fields
are now deleted from `Module`:

 * `monomorphed_func_keys`
 * `monomorphed_funcs`
 * `align_stack_fns`

Instead of these, Sema logic for generic function instantiation now
unconditionally evaluates the function prototype expression for every
generic callsite. This is technically required in order for type
coercions to work. The previous code had some dubious, probably wrong
hacks to make things work, such as `hashUncoerced`. I'm not 100% sure
how we were able to eliminate that function and still pass all the
behavior tests, but I'm pretty sure things were still broken without
doing type coercion for every generic function call argument.

After the function prototype is evaluated, it produces a deduplicated
`func_instance` `InternPool.Index` which can then be used for the
generic function call.

Some other nice things made by this simplification are the removal of
`comptime_args_fn_inst` and `preallocated_new_func` from `Sema`, and the
messy logic associated with them.

I have not yet been able to measure the perf of this against master
branch. On one hand, it reduces memory usage and pointer chasing of the
most heavily used `InternPool` Tag - function bodies - but on the other
hand, it does evaluate function prototype expressions more than before.
We will soon find out.
2023-07-18 19:02:05 -07:00
Jacob Young
70c71935c7 cbe: fix pointers to aliases of extern values 2023-07-18 17:58:39 -07:00
Loris Cro
a187141056
Autodoc tokenizer (#16409)
* autodoc: init work to refactor exprName

* autodoc: Implement more expressions in exprName refactor

* autodoc: more work

* autodoc: More exprName to ex refactoring

* autodoc: Remove whitespace flag from renderer; Add pre tags in
value and variable drawing in renderContainer

* autodoc: add inline styling to pre blocks

* autodoc: move renderer code to main.js

* autodoc: More exprName to ex refactoring; Fn signatures rendered with new code

* autodoc: Fix function rendering. Add more things to ex

* autodoc: nuke exprName

---------

Co-authored-by: Krzysztof Wolicki <der.teufel.mail@gmail.com>
2023-07-14 16:27:09 +02:00
Casey Banner
094cd92615
macho: fix __unwind_info sentinel entry not always being the upper bound (#16395)
macho: record highest address of unwind records before folding

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2023-07-14 11:47:00 +00:00
antlilja
16d17addcb Update translate-c to new splat syntax 2023-07-12 15:35:57 -07:00
antlilja
4bce7b1db9 Remove len parameter from splat builtin function
Resolve the result type of the splat builtin instead of requiring a
length parameter.
2023-07-12 15:35:57 -07:00
Anton Lilja
711b4e93e2
Fixes crash when a struct is given as the first parameter to the unionInit builtin (#16385) 2023-07-11 23:37:42 -07:00
Anton Lilja
ff0e2ab398
Fixes wrong error location for unionInit when first parameter is not a type (#16384) 2023-07-11 23:35:50 -07:00
Andrew Kelley
660955c0d6
Merge pull request #15775 from r00ster91/newlines
remove some newlines and other minor cleanups
2023-07-11 23:06:12 -07:00
Xavier Bouchoux
7a8002a5cf remove arbitrary stderr size limit when spawning a child process tool 2023-07-11 00:17:08 -07:00
Luuk de Gram
dbc560904a
Merge pull request #16345 from ziglang/15920
Emit check for memory intrinsics for WebAssembly
2023-07-11 09:11:22 +02:00
Luuk de Gram
37e2a04da8
add stand alone test to verify bulk-memory features
This adds a standalone test case to ensure the runtime does not trap
when performing a memory.copy or memory.fill instruction while the
destination or source address is out-of-bounds and the length is 0.
2023-07-10 20:05:13 +02:00
r00ster91
0b1e8690da AstGen: make sure for range start and end are usizes
Fixes #16311

The actual cause of #16311 is the `start_is_zero` special case:
```zig
                const range_len = if (end_val == .none or start_is_zero)
                    end_val
                else
                    try parent_gz.addPlNode(.sub, input, Zir.Inst.Bin{
                        .lhs = end_val,
                        .rhs = start_val,
                    });
```
It only happens if the range start is 0. In that case we would not perform any type checking.
Only in the other cases coincidentally `.sub` performs type checking in Sema, but the errors are still rather poor:
```
$ zig test x.zig
x.zig:9:15: error: invalid operands to binary expression: 'Pointer' and 'Pointer'
    for ("abc".."def") |val| {
         ~~~~~^~~~~~~
```
Note how it's the same as if I use `-`:
```
x.zig:9:11: error: invalid operands to binary expression: 'Pointer' and 'Pointer'
    "abc" - "def";
    ~~~~~~^~~~~~~
```
Now after this PR, the errors are much clearer for both range start and end:
```
x.zig:9:10: error: expected type 'usize', found '*const [3:0]u8'
    for ("abc".."def") |val| {
         ^~~~~
```
This is why I decided to use `.ty` instead of `.coerced_ty` for both range start and end rather than
just perform type checking in that `end_val == .none or start_is_zero` case.
2023-07-10 10:51:55 -07:00
Andrew Kelley
2b8c1f0d46
Merge pull request #16339 from r00ster91/ueficc
std.os.uefi: use std.os.uefi.cc instead of .C as calling convention
2023-07-10 10:41:19 -07:00
Ian Johnson
3a30f0fa50 Sema: resolve field type layout for anon struct type info
Closes #16148
2023-07-10 19:17:50 +03:00
kcbanner
82a9d5d78d type: update optionalReprIsPayload to handle inferred error sets 2023-07-10 04:52:23 -04:00
r00ster91
026c63d8fe Sema: infrastructure for supporting more than .C callconv for variadic functions
Now you can add new calling conventions that you confirmed to work with
variadic functions simply in a single place and the rest will work
automatically.
2023-07-08 18:05:03 -04:00
Luuk de Gram
d54ebf4356
llvm: add safety-check for Wasm memset
When lowering the `memset` instruction, LLVM will lower it to WebAssembly's
`memory.fill` instruction when the bulk-memory feature is enabled. This
instruction will trap when the destination address is out-of-bounds.
By Zig's semantics, it is valid to have an invalid pointer when the length is 0.
To prevent runtimes from trapping, we add a safety-check for slices to only
lower to a memset instruction when the length is larger than 0.
2023-07-08 17:45:05 +02:00
Luuk de Gram
836f9fceab
llvm: add safety-check for Wasm memcpy
When lowering the `memcpy` instruction, LLVM will lower it to WebAssembly's
`memory.copy` instruction when the bulk-memory feature is enabled. This
instruction will trap when the destination or source pointer is out-of-bounds.
By Zig's semantics, it is valid to have an invalid pointer when the length is 0.
To prevent runtimes from trapping, we add a safety-check for slices to only
lower to a memcpy instruction when the length is larger than 0.
2023-07-08 17:45:04 +02:00
Ian Johnson
91daf1c8d8 Autodoc: implement boolean operations 2023-07-06 17:28:11 +02:00
Jacob Young
78eb3c5617 bootstrap: support aarch64 in 32-bit mode
* `CMakeLists.txt`: support the weird `uname -m` output.
 * `CMakeLists.txt`: detect and use the C compiler's default arm mode.
 * cbe: support gcc with both `f128` and `u128` emulated.
 * std.os.linux.thumb: fix incorrectly passed asm inputs.
2023-07-04 15:47:07 -07:00
Andrew Kelley
17890f6b8a
Merge pull request #15879 from r00ster91/more_stage1_test_coverage
More stage1 test coverage
2023-07-03 15:59:54 -07:00
r00ster91
2b8687ba2d std.math.big.int: better name for equal function
All of the std except these few functions call it "eql" instead of "eq".
This has previously tripped me up when I expected the equality check function to be called "eql"
(just like all the rest of the std) instead of "eq".

The motivation is consistency.

If search "eq" on Autodoc, these functions stick out and it looks inconsistent.

I just noticed there are also a few functions spelling it out as "equal" (such as std.mem.allEqual).
Maybe those functions should also spell it "eql" but that can be done in a future PR.
2023-07-03 11:00:13 -07:00
Loris Cro
28ad74e8a6 autodoc: wire in js tokenizer to frontend 2023-07-03 19:18:44 +02:00
Andrew Kelley
afc5edabe0
Merge pull request #16287 from Snektron/amdgpu-panic-fix
Some amdgcn fixes
2023-07-01 22:04:06 -07:00
Andrew Kelley
309aacfc89
Merge pull request #16284 from Snektron/spirv-internpool-fixes
SPIR-V InternPool aftermath damage control
2023-07-01 14:21:04 -07:00
Robin Voetter
13c0624f23
llvm: cast optional null ptr representation to generic address space
The panic handler expects that this value is represented with the
generic address space, so cast the global to the generic address-
space before caching and returning the value.
2023-07-01 20:28:17 +02:00
Loris Cro
97a1b046ea autodoc: fix scoring bug when matching full decl name 2023-07-01 17:38:18 +02:00
Emile Badenhorst
35a8e8a06c
Fixed Autodoc rendering of @truncate builtin (#16263)
* fixed autodoc rendering of @trucate builtin

* Changed to LHS for typeRef

* autodoc: fix typeref for `truncate`

---------

Co-authored-by: Loris Cro <kappaloris@gmail.com>
2023-07-01 16:43:17 +02:00
Robin Voetter
8eee392862
spirv: fix up todos & errors from intern pool changes
This replaces the implementation of constant() which one that
is directly based on the intern pool rather than the Zig type tag
too.
2023-07-01 14:27:12 +02:00
Jacob Young
f571438fc0 Unrevert "Sema: preserve extern struct field alignment"
This unreverts commit 1a2468abfcd8b539193d943c1eefb71319cc7b88.
2023-06-30 23:24:52 -04:00
Jacob Young
2282c27885 Remerge pull request #15995 from mlugg/fix/union-field-ptr-align
Sema: copy pointer alignment to union field pointers

This is an unrevert of 43c98dc11567eeb38be041c7dad179c53156f3df.
2023-06-30 23:23:26 -04:00
mlugg
730f2e0407 Sema: copy pointer alignment to struct field pointers 2023-06-30 23:23:03 -04:00
mlugg
5b594139d9 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-30 23:23:01 -04:00
Evan Haas
0a6cd257b9 translate-c: Use @constCast and @volatileCast to remove CV-qualifiers
Instead of converting a pointer to an int and then back to a pointer.
2023-06-29 23:36:56 +03:00
Jacob Young
43c98dc115 Revert "Merge pull request #15995 from mlugg/fix/union-field-ptr-align"
This reverts commit 40cf3f7ae5fbfb84b7af6b27e6296ee858b209ef, reversing
changes made to d98147414d084bc41b00ba9c0be8c7b82ad4e76c.
2023-06-29 00:23:19 -04:00
Jacob Young
1a2468abfc Revert "Sema: preserve extern struct field alignment"
This reverts commit 4620972d086ebb3b7686a79914876488c6dfd171.
2023-06-29 00:23:19 -04:00