Commit graph

5835 commits

Author SHA1 Message Date
mlugg
1e7dcaa3ae Sema: resolve peer vector types before comparison
Resolves: #15732
2023-06-10 21:41:49 +03:00
mlugg
34d44e0c1c Sema: emit error on @intToPtr with slice dest type
Resolves: #15967
2023-06-10 11:12:35 +03:00
mlugg
bf4b43a2f7 AstGen: handle ref_table for params
This is kind of similar to 1a4b0d9. In this case, we need to handle
ref_table when appending the body of param instructions.

Resolves: #15952
2023-06-10 07:18:05 +03:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
mlugg
1a4b0d9790 AstGen: handle ref_table for errdefer captures
Resolves: #15861
2023-06-03 13:36:44 -07:00
Andrew Kelley
77b40d6ecb
Merge pull request #15927 from truemedian/http-bugs
std.http: fix infinite read loop, deduplicate connection code, add TlsAlert errors
2023-06-03 13:36:07 -07:00
Nameless
23ccff9cce
std.http.Server: collapse BufferedConnection into Connection 2023-06-01 13:44:00 -05:00
Luuk de Gram
3faf376b08
Merge pull request #15919 from Luukdegram/wasm-behavior-tests 2023-06-01 19:42:04 +02:00
Evin Yulo
3085e2af41 add missing note "operation is runtime due to this operand" 2023-05-31 19:18:36 +03:00
Luuk de Gram
1042deb86f
enable passing behavior tests 2023-05-31 18:04:33 +02:00
yujiri8
cd1417dbdf
don't crash when can't evaluate comptime expression with inferred type
Closes #15911.
2023-05-31 11:15:52 +00:00
Bogdan Romanyuk
32e719e070
sema: add compile error for incorrect extern type 2023-05-31 04:38:32 +00:00
Jakub Konka
76aa1fffb7
Merge pull request #15905 from jacobly0/x86_64-hotfix
x86_64: hotfix for crash during in-memory coercion of large type
2023-05-30 13:22:13 +02:00
Jacob Young
0c438ab616 x86_64: hotfix for crash during in-memory coercion of large type
Unblocks #15768
Closes #15904
2023-05-29 22:03:27 -04:00
mlugg
0f58d34ef7
tests: disable incremental cases for now
These were failing on the prior commit. Unfortunately, the fix would
have been relatively complicated, and ties into underlying issues with
the current incremental compilation logic. After discussing this with
Andrew, we agreed that the best course of action is to completely
disable incremental compilation tests for now until it's more mature, at
which point we can re-enable them.
2023-05-29 23:06:11 +01:00
mlugg
4976b58ab1
Prevent analysis of functions only referenced at comptime
The idea here is that there are two ways we can reference a function at runtime:

* Through a direct call, i.e. where the function is comptime-known
* Through a function pointer

This means we can easily perform a form of rudimentary escape analysis
on functions. If we ever see a `decl_ref` or `ref` of a function, we
have a function pointer, which could "leak" into runtime code, so we
emit the function; but for a plain `decl_val`, there's no need to.

This change means that `comptime { _ = f; }` no longer forces a function
to be emitted, which was used for some things (mainly tests). These use
sites have been replaced with `_ = &f;`, which still triggers analysis
of the function body, since you're taking a pointer to the function.

Resolves: #6256
Resolves: #15353
2023-05-29 23:06:08 +01:00
mlugg
e2837fd224 Sema: return comptime_int if all args to @min/@max are comptime_int
Resolves: #15776
2023-05-29 11:32:13 -07:00
Evin Yulo
235b776d61 fix #15778: Binary operations on empty vectors crash 2023-05-29 13:01:11 +03:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +01:00
Veikka Tuominen
230ea411f7 disable test on C backend
This test was previously incorrect and was not testing the intended instruction.
2023-05-25 18:49:18 +03:00
Veikka Tuominen
4a3539e449 llvm: fix vector type in vector_store_elem
Closes #15848
2023-05-25 15:57:30 +03:00
Mason Remaley
5744ceedb8
Fixes WriteFile.getFileSource failure on Windows (#15730) 2023-05-24 14:26:07 -07:00
Veikka Tuominen
7cb2e653a2
Merge pull request #15806 from linusg/std-io-tty
std: Move TTY from std.debug to std.io and add missing colors
2023-05-24 16:03:44 +03:00
Veikka Tuominen
b2a514b3d2 Sema: @memcpy convert src slice to many ptr
Closes #15838
2023-05-24 14:29:15 +03:00
Linus Groh
0f6fa3f20b std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.tty
Also get rid of the TTY wrapper struct, which was exlusively used as a
namespace - this is done by the tty.zig root struct now.

detectTTYConfig has been renamed to just detectConfig, which is enough
given the new namespace. Additionally, a doc comment had been added.
2023-05-24 10:15:02 +01:00
Ali Chraghi
3db3cf7790 std.sort: add pdqsort and heapsort 2023-05-23 17:55:59 -07:00
tison
bfe02ff61a
make @boolToInt always return a u1
Signed-off-by: tison <wander4096@gmail.com>
2023-05-24 00:01:48 +00:00
Veikka Tuominen
4ce1ae71a5
Merge pull request #15235 from Vexu/safety
add runtime safety for noreturn function returning
2023-05-23 13:34:52 +03:00
Veikka Tuominen
eef92753c7 Sema: improve error message when calling optional function
Co-authored-by: wrongnull <wrongnull@gmail.com>
2023-05-22 19:11:38 +03:00
Andrew Kelley
7621e56938
Merge pull request #15753 from Snektron/spirv-more-tests
spirv: make more tests pass
2023-05-20 13:54:01 -07:00
Veikka Tuominen
413ef3aa38
Merge pull request #15748 from alichraghi/ali-spirv
spirv: lower get_union_tag
2023-05-20 23:26:04 +03:00
Luuk de Gram
56d8a1c89c
Merge pull request #15663 from Luukdegram/wasm-test-runner
wasm: enable standard test runner
2023-05-20 21:33:48 +02:00
mlugg
38b83d9d93 Zir: eliminate field_call_bind and field_call_bind_named
This commit removes the `field_call_bind` and `field_call_bind_named` ZIR
instructions, replacing them with a `field_call` instruction which does the bind
and call in one.

`field_call_bind` is an unfortunate instruction. It's tied into one very
specific usage pattern - its result can only be used as a callee. This means
that it creates a value of a "pseudo-type" of sorts, `bound_fn` - this type used
to exist in Zig, but now we just hide it from the user and have AstGen ensure
it's only used in one way. This is quite silly - `Type` and `Value` should, as
much as possible, reflect real Zig types and values.

It makes sense to instead encode the `a.b()` syntax as its own ZIR instruction,
so that's what we do here. This commit introduces a new instruction,
`field_call`. It's like `call`, but rather than a callee ref, it contains a ref
to the object pointer (`&a` in `a.b()`) and the string field name (`b`). This
eliminates `bound_fn` from the language, and slightly decreases the size of
generated ZIR - stats below.

This commit does remove a few usages which used to be allowed:
- `@field(a, "b")()`
- `@call(.auto, a.b, .{})`
- `@call(.auto, @field(a, "b"), .{})`

These forms used to work just like `a.b()`, but are no longer allowed. I believe
this is the correct choice for a few reasons:
- `a.b()` is a purely *syntactic* form; for instance, `(a.b)()` is not valid.
  This means it is *not* inconsistent to not allow it in these cases; the
  special case here isn't "a field access as a callee", but rather this exact
  syntactic form.
- The second argument to `@call` looks much more visually distinct from the
  callee in standard call syntax. To me, this makes it seem strange for that
  argument to not work like a normal expression in this context.
- A more practical argument: it's confusing! `@field` and `@call` are used in
  very different contexts to standard function calls: the former normally hints
  at some comptime machinery, and the latter that you want more precise control
  over parts of a function call. In these contexts, you don't want implicit
  arguments adding extra confusion: you want to be very explicit about what
  you're doing.

Lastly, some stats. I mentioned before that this change slightly reduces the
size of ZIR - this is due to two instructions (`field_call_bind` then `call`)
being replaced with one (`field_call`). Here are some numbers:

+--------------+----------+----------+--------+
| File         | Before   | After    | Change |
+--------------+----------+----------+--------+
| Sema.zig     | 4.72M    | 4.53M    | -4%    |
| AstGen.zig   | 1.52M    | 1.48M    | -3%    |
| hash_map.zig | 283.9K   | 276.2K   | -3%    |
| math.zig     | 312.6K   | 305.3K   | -2%    |
+--------------+----------+----------+--------+
2023-05-20 12:27:48 -07:00
Robin Voetter
65157d30ab
spirv: ptr_elem_val
Implements the ptr_elem_val air tag. Implementation is unified
with ptr_elem_ptr.
2023-05-20 17:30:23 +02:00
Robin Voetter
77b8bf2b82
spirv: ptr_sub
Implments the ptr_sub air tag. The code is unified with that of ptr_add.
2023-05-20 17:30:22 +02:00
Robin Voetter
091595ac37
spirv: customize module-scope asm test
This test passes just fine, but the provided assembly is not valid
for spir-v. This adds a custom assembly test and enables the test
for spir-v
2023-05-20 17:30:22 +02:00
Robin Voetter
37aa343079
spirv: more passing tests 2023-05-20 17:30:22 +02:00
Robin Voetter
2f28713bd7
spirv: pointer bitcasting 2023-05-20 17:30:22 +02:00
Robin Voetter
64f99f36a6
spirv: ptr_add
Implements the ptr_add air tag for spirv.

The implementation for slices is probably wrong, but there seems to be no test for this...
2023-05-20 17:30:22 +02:00
Robin Voetter
0ba0d8fecb
spirv: dont use OpIAddCarry
This instruction is not really working well in the LLVM SPIRV translator,
as it is not implemented.

This commit also intruces the constructStruct helper function to initialize
structs at runtime. This is ALSO buggy in the translator, and we must work
around OpCompositeConstruct not working when some of the constituents are
runtime-known only.

Some other improvements are made:
- improved variable() so that it is more useful and no longer requires the
  address space. It always puts values in the Function address space,
  and returns a pointer to the Generic address space
- adds a boolToInt utility function
2023-05-20 17:30:21 +02:00
Robin Voetter
7d519b3383
spirv: use intInfo instead of arithmeticTypeInfo in airIntCast
This ensures that we can also cast enums and error sets here. In the future
this function will need to be changed to support composite and strange
integers, but that is fine.
2023-05-20 17:30:21 +02:00
Robin Voetter
6e3770e970
spirv: implement pointer comparison in for air cmp
It turns out that the Khronos LLVM SPIRV translator does not support OpPtrEqual.
Therefore, this instruction is emitted using a series of conversions.

This commit breaks intToEnum, because enum was removed from the arithmetic type
info. The enum should be converted to an int before this function is called.
2023-05-20 17:30:21 +02:00
Ali Chraghi
fedc9a19e7 spirv: lower get_union_tag 2023-05-20 18:43:26 +03:30
Luuk de Gram
ca870aa005
wasm: fix div_trunc for floats
For floats we would previously only do the division, but not
the truncation for floats. This would result in incorrect values
being returned.
2023-05-19 20:22:47 +02:00
Luuk de Gram
4a33aa922e
wasm: support memset for elem abi size > 1
Previously we incorrectly assumed all memset's to have its element
abi-size be 1 byte. This would set the region of memory incorrectly.
We now have a more efficient loop, as well as support any element
type by re-using the `store` function for each element and moving
the pointer by 1 element.
2023-05-19 20:22:45 +02:00
Luuk de Gram
55a260c968
wasm: implement shl for big integers 2023-05-19 20:20:29 +02:00
Luuk de Gram
061d99285d
wasm: correctly use elem type when lowering
Previously when lowering a value of `elem_ptr` we would multiply the
abisize of the parent type by the index, rather than the element type.
This would result in an invalid pointer way beyond the correct pointer.

We now also pass the current offset to each recursive call to ensure
we do not miss inner offsets.
2023-05-19 20:20:26 +02:00
Andrew Kelley
b873ce1e0e
Merge pull request #15727 from jacobly0/x86_64-behavior
x86_64: behavior
2023-05-19 00:56:59 -07:00
Andrew Kelley
503302ceef Sema: simplify "duplicate test name" error message
* Avoid redundant words ("found")
   - All compile errors are found by the compiler
 * Avoid unnecessary prepositions ("with")
   - There is a grammatically correct alternate word order without the
     preposition.
2023-05-18 19:17:04 -07:00
Jacob Young
79bdd2bd63 x86_64: implement saturating add/sub for weird types 2023-05-18 20:42:38 -04:00