4812 Commits

Author SHA1 Message Date
Andrew Kelley
db55f469c1 std.mem.Allocator: upgrade to new function pointer semantics 2022-01-26 20:02:01 -07:00
Andrew Kelley
50accb757f stage2: fix crash on file-level struct field source locations 2022-01-26 20:02:01 -07:00
Josh Hannaford
178cd60a5e Update the documentation for std.mem.sliceTo for readability 2022-01-26 00:49:17 -05:00
John Schmidt
9ee67b967b stage2: avoid inferred struct in os_version_check.zig
Before this commit, compiling an empty main with Stage 2 on macOS x86_64 results in

```
../stage2/bin/zig build-exe -ODebug -fLLVM empty_main.zig
error: sub-compilation of compiler_rt failed
    [...]/zig/stage2/lib/zig/std/special/compiler_rt/os_version_check.zig:26:10: error: TODO: Sema.zirStructInit for runtime-known struct values
```

By assigning the value to a variable we can sidestep the issue for now.
2022-01-26 00:48:05 -05:00
Andrew Kelley
0c1df96b17
Merge pull request #10552 from hdorio/deflate
compress: add a deflate compressor
2022-01-26 00:43:13 -05:00
Meghan
f1b79c9a44 std.crypto.random: Randoms are no longer passed by reference 2022-01-25 13:00:39 -05:00
Andrew Kelley
b34f994c0b stage2: type system treats fn ptr and body separately
This commit updates stage2 to enforce the property that the syntax
`fn()void` is a function *body* not a *pointer*. To get a pointer, the
syntax `*const fn()void` is required.

ZIR puts function alignment into the func instruction rather than the
decl because this way it makes it into function types. LLVM backend
respects function alignments.

Struct and Union have methods `fieldSrcLoc` to help look up source
locations of their fields. These trigger full loading, tokenization, and
parsing of source files, so should only be called once it is confirmed
that an error message needs to be printed.

There are some nice new error hints for explaining why a type is
required to be comptime, particularly for structs that contain function
body types.

`Type.requiresComptime` is now moved into Sema because it can fail and
might need to trigger field type resolution. Comptime pointer loading
takes into account types that do not have a well-defined memory layout
and does not try to compute a byte offset for them.

`fn()void` syntax no longer secretly makes a pointer. You get a function
body type, which requires comptime. However a pointer to a function body
can be runtime known (obviously).

Compile errors that report "expected pointer, found ..." are factored
out into convenience functions `checkPtrOperand` and `checkPtrType` and
have a note about function pointers.

Implemented `Value.hash` for functions, enum literals, and undefined values.

stage1 is not updated to this (yet?), so some workarounds and disabled
tests are needed to keep everything working. Should we update stage1 to
these new type semantics? Yes probably because I don't want to add too
much conditional compilation logic in the std lib for the different
backends.
2022-01-24 21:47:53 -07:00
Andrew Kelley
913d61ebb9 Revert "MultiArrayList: Fix error when struct is 0 sized"
This reverts commit 1f10cf4edf2b645e63dedc42f5d7475914bf2311.

Re-opens #10618

I want to solve this a different way. `align(S)` where S is a 0-byte
type should work in this context.

This also caused issues such as
https://github.com/Vexu/arocc/issues/221
2022-01-24 21:29:04 -07:00
Frank Denis
4e5495e443 std.crypto.25519.scalar: implement edwards25519 scalar field inversion
This operation is extremely useful for multiplicative blinding.
2022-01-24 23:09:45 +01:00
John Schmidt
40b3c9a592 Handle FormatOptions in fmtDuration/fmtDurationSigned 2022-01-24 20:30:36 +02:00
riverbl
a0732117d0 HashMap: add removeByPtr 2022-01-24 20:29:05 +02:00
Sizhe Zhao
15ef251a15 Avoid duplicate TLS startup symbols 2022-01-24 20:26:29 +02:00
Jonathan Marler
3f341bdc26
Normalize some build function names
An attempt to normalize some of the function names in build.zig.  Normalize add*Dir to add*Path.  Also use "Library" instead of the "Lib" abbreviation.

The PR does not remove the old names, only adds the new normalized ones to faciliate a transition period.
2022-01-24 20:15:32 +02:00
Pablo Santiago Blum de Aguiar
5ba4385971 readUntilDelimiter*: read only if buffer not full
Ref.: #9594
2022-01-24 17:44:26 +02:00
Jonathan Marler
2fc2d88fc6 use explicit integer bit widths for windows GUID
The size of a GUID is not platform-dependent, it's always a fixed number of bits.  So I've updated guid to use fixed bit integer types rather than platform-dependent C integer types.
2022-01-24 17:35:15 +02:00
fifty-six
da8d4d9225 std/fs: Support XDG_DATA_HOME
This is generally used for user-specific data on linux, with the
default being ~/.local/share
2022-01-24 17:33:38 +02:00
riverbl
1f10cf4edf
MultiArrayList: Fix error when struct is 0 sized
Also fixes error with ArrayHashMap when both key and value are 0 sized
2022-01-24 17:31:27 +02:00
Lee Cannon
c54a7ca4b2 allow expected_exit_code to be null 2022-01-24 17:29:19 +02:00
Andrew Kelley
12c2de6ee2
Merge pull request #10662 from ziglang/doc-comments-zir
Doc comments zir
2022-01-23 18:31:55 -05:00
Andrew Kelley
8a69726209 AstGen: doc comment fixups
* AstGen: use Ast.zig helper methods to avoid copy pasting token counting logic
   - take advantage of the `first_doc_comment` field we already have for
     param AST nodes
 * Add missing ZIR docs
2022-01-23 16:24:46 -07:00
Jimmi Holst Christensen
7287c7482a Stop using LinearFifo in BufferedWriter
Looking at the BufferedWriter assembly generated, one can see that is
has to do a lot of work, just to copy over some bytes and increase an
offset. This is because the LinearFifo is a much more general construct
than what BufferedWriter needs and the optimizer cannot prove that we
don't need to do this extra work.
2022-01-23 14:41:15 -05:00
Hadrien Dorio
490f067de8
compress: add a deflate compressor
Replaces the inflate API from `inflateStream(reader: anytype, window_slice: []u8)` to
`decompressor(allocator: mem.Allocator, reader: anytype, dictionary: ?[]const u8)` and
`compressor(allocator: mem.Allocator, writer: anytype, options: CompressorOptions)`
2022-01-23 19:30:06 +01:00
Hadrien Dorio
dba04a272a
compress: remove sha256 checks from tests
Read bytes to check expected values instead of reading and hashing them.
Hashing is a waste of time when we can just read and compare.
This also removes a dependency on std.crypto.hash.sha2.Sha256 for tests.
2022-01-23 19:29:57 +01:00
joachimschmidt557
fa84625aeb std: Add some missing termios types to c/linux.zig and os.zig 2022-01-23 17:12:07 +01:00
Andrew Kelley
d819663543 disable some broken stuff for stage2 llvm backend on aarch64 2022-01-21 14:42:58 -07:00
Jonathan Marler
0e682e71b0 remove unnecessary self argument 2022-01-20 10:55:10 +02:00
Meghan Denny
b7ba728929 std: add meta.DeclEnum 2022-01-20 10:54:45 +02:00
Andrew Kelley
fd6d1fe015 stage2: improvements to entry point handling
* rename `entry` to `entry_symbol_name` for the zig build API
 * integrate with `zig cc` command line options
 * integrate with COFF linking with LLD
 * integrate with self-hosted ELF linker
 * don't put it in the hash for MachO since it is ignored
2022-01-19 11:41:08 -07:00
Kenta Iwasaki
5ae3e4e9bd lld: allow for entrypoint symbol name to be set
This commit enables for the entrypoint symbol to be set when linking ELF
or WebAssembly modules with lld using the Zig compiler.
2022-01-19 11:22:10 -07:00
Andrew Kelley
beb7495e19
Merge pull request #10624 from ziglang/prefetch
stage2: implement `@prefetch`
2022-01-18 23:25:44 -05:00
John Schmidt
305a7def13 Implement segfault handler for macOS x86_64 2022-01-18 15:10:49 -05:00
Andrew Kelley
30efcf22d7 stage2: implement @prefetch
This reverts commit f423b5949b8722d4b290f57c3d06d015e39217b0,
re-instating commit d48e4245b68bf25c7f41804a5012ac157a5ee546.
2022-01-18 11:59:09 -07:00
Andrew Kelley
f423b5949b Revert "stage2: implement @prefetch"
This reverts commit d48e4245b68bf25c7f41804a5012ac157a5ee546.

I have no idea why this is failing Drone CI, but in a branch, reverting
this commit solved the problem.
2022-01-18 10:47:02 -07:00
Andrew Kelley
4938fb8f5c test runner: stage2 llvm backend prints stats 2022-01-17 22:17:02 -07:00
Andrew Kelley
4d05f2ae5f remove zig_is_stage2 from @import("builtin")
Instead use the standarized option for communicating the
zig compiler backend at comptime, which is `zig_backend`. This was
introduced in commit 1c24ef0d0b09a12a1fe98056f2fc04de78a82df3.
2022-01-17 21:55:49 -07:00
Meghan
4a92f42ed7 std.c: add shm_open and shm_unlink
https://man7.org/linux/man-pages/man3/shm_open.3.html
2022-01-17 16:56:50 +02:00
johnLate
4addb26bba Fix os.rusage when linking with c library on Linux
Fixes ziglang#10543 on Linux.
2022-01-17 16:52:36 +02:00
Meghan Denny
0d0f277954 std: add json.stringifyAlloc 2022-01-17 12:32:02 +01:00
Jakub Konka
90343d1868 libstd: add smoke test for insert methods in MultiArrayList 2022-01-17 12:26:48 +01:00
Jarred Sumner
144e36770e
Fix missing !void in std.MultiArrayList
Calling `insert` on a `std.MultiArrayList` currently fails with a compiler error due to using a `try` without the `!` annotation on the return type

```zig
this.list.insert(allocator, 0, listener);
```

```zig
/Users/jarred/Build/zig/lib/std/multi_array_list.zig:192:13: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(std.multi_array_list.MultiArrayList(src.javascript.jsc.node.types.Listener).ensureUnusedCapacity)).Fn.return_type.?).ErrorUnion.error_set'
            try self.ensureUnusedCapacity(gpa, 1);
```
2022-01-16 17:26:49 -08:00
Jimmi Holst Christensen
f19b5ecf4b Slice function of BoundedArray now returns slice based on self pointer
If self pointer is const, the slice is const. Otherwise the slice is
mutable.
2022-01-16 01:37:37 -05:00
Andrew Kelley
d48e4245b6 stage2: implement @prefetch 2022-01-15 15:18:25 -07:00
Jakub Konka
ba0f72363a
Merge pull request #10576 from schmee/macos-resolve-ip
Use libc if_nametoindex for macOS when parsing IPs
2022-01-15 00:47:12 +01:00
John Schmidt
c992164dc7 Check for isDarwin() instead of linked libc 2022-01-14 13:44:38 +01:00
bryfry
0d45c72d3e Use allocPrintZ to avoid needing assumeSentinel 2022-01-14 00:17:38 -05:00
Andrew Kelley
9bf2bda683 compiler_rt: one less exception for stage2 2022-01-13 00:32:48 -07:00
Andrew Kelley
93b854eb74 stage2: implement @ctz and @clz including SIMD
AIR:
 * `array_elem_val` is now allowed to be used with a vector as the array
   type.
 * New instructions: splat, vector_init

AstGen:
 * The splat ZIR instruction uses coerced_ty for the ResultLoc, avoiding
   an unnecessary `as` instruction, since the coercion will be performed
   in Sema.
 * Builtins that accept vectors now ignore the type parameter. Comment
   from this commit reproduced here:

   The accepted proposal #6835 tells us to remove the type parameter from
   these builtins. To stay source-compatible with stage1, we still observe
   the parameter here, but we do not encode it into the ZIR. To implement
   this proposal in stage2, only AstGen code will need to be changed.

Sema:
 * `clz` and `ctz` ZIR instructions are now handled by the same function
   which accept AIR tag and comptime eval function pointer to
   differentiate.
 * `@typeInfo` for vectors is implemented.
 * `@splat` is implemented. It takes advantage of `Value.Tag.repeated` 😎
 * `elemValue` is implemented for vectors, when the index is a scalar.
   Handling a vector index is still TODO.
 * Element-wise coercion is implemented for vectors. It could probably
   be optimized a bit, but it is at least complete & correct.
 * `Type.intInfo` supports vectors, returning int info for the element.
 * `Value.ctz` initial implementation. Needs work.
 * `Value.eql` is implemented for arrays and vectors.

LLVM backend:
 * Implement vector support when lowering `array_elem_val`.
 * Implement vector support when lowering `ctz` and `clz`.
 * Implement `splat` and `vector_init`.
2022-01-12 23:53:26 -07:00
John Schmidt
66fe5bb0d8 Use libc if_nametoindex if available when parsing IPs
Fixes https://github.com/ziglang/zig/issues/10521 and makes a couple of
additional tests pass when linking libc.
2022-01-12 19:32:46 +01:00
Jimmi Holst Christensen
a5ac138ae2 Allow BoundArray to be default initialized 2022-01-12 13:17:01 -05:00
Jimmi Holst Christensen
349a7cc272 Make prominent_compile_errors also work for test steps 2022-01-12 00:13:30 -05:00