Commit Graph

4234 Commits

Author SHA1 Message Date
aiz
5414bd48ed
std.math.Complex: Change new() to init() 2021-05-17 21:57:51 +02:00
Aiz672
8467373bb8 Remove isIntegerNumber and isFloatingNumber 2021-05-17 08:41:44 +03:00
Jonathan Marler
5042a47682 add missing EBADF error code for openat 2021-05-16 22:36:50 +02:00
Andrew Kelley
597082adf4 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
2021-05-15 21:44:38 -07:00
LemonBoy
7a4b53fdee std: Avoid using white color when printing stacktraces
Use .bold instead of .white, the effect is the same for light-on-dark
terminals but greatly improves the readability for dark-on-light ones.

Closes #8761
2021-05-15 13:44:52 -04:00
viri
a994966870 remove range constants 2021-05-15 10:08:07 -06:00
Andrew Kelley
607abb5b14 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-14 23:16:46 -07:00
ZapAnton
e94bbc2237 std.testing: Added newline to the error messages
Added newline to every `std.debug.print` message.
Closes https://github.com/ziglang/zig/issues/8777
2021-05-15 01:27:39 -04:00
viri
ca575f887c std: re-add weird undocumented Win32 constants
Got deleted. Not documented but sure.
2021-05-14 15:15:20 -06:00
viri
150a3ad6ff std: fix & add os.windows.user32 WM constants 2021-05-14 15:06:47 -06:00
Andrew Kelley
2dcec42b74
Merge pull request #8757 from Snektron/spirv-stuff
SPIR-V: Features + some other stuff
2021-05-14 17:02:51 -04:00
viri
612ad779bb
std: rework math.scalbn (#8733)
* std: fix overflow in math.scalbn32

* std: rewrite math.scalbn to be generic

* std: support f128 in math.isNormal

* std: enable f128 tests in math.scalbn
2021-05-14 16:15:53 -04:00
Andrew Kelley
114c6612cb
Merge pull request #8764 from mattbork/json-usefirst
Fix duplicate_field_behavior UseFirst for parse in json.zig
2021-05-14 15:32:32 -04:00
Andrew Kelley
826d833416
Merge pull request #8746 from koachan/sparc64-fixes
Various Linux/SPARCv9 fixes
2021-05-14 15:21:17 -04:00
Sahnvour
2d4d4baa42 std.hash_map: use 7 bits of metadata instead of 6
we only effectively need 1 control bit to represent 2 special states for
the metadata (free and tombstone)
this should reduce the number of actual element equality tests, but since
it's very low already, the impact is negligible
2021-05-14 15:15:55 -04:00
LemonBoy
5185b5619a compiler-rt: Fix signedness mismatch in f128 mul impl
The `1 - shift` expression was computed using small unsigned types and
then casted to i32, producing either an underflow error or an incorrect
result.

Reported by `@notviri` in #8733
2021-05-14 15:11:54 -04:00
Robin Voetter
98dc8eb7d9 SPIR-V: Add generated SPIR-V features 2021-05-14 19:49:32 +02:00
Robin Voetter
fa3afede58 SPIR-V: Set default ofmt to spirv 2021-05-14 19:49:32 +02:00
Andrew Kelley
93896ef860 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-13 23:50:39 -07:00
Matthew Borkowski
11fd2aa767 fix logic for duplicate comptime fields and avoid freeing comptime fields in parseFree and parseInternal 2021-05-14 01:51:39 -04:00
Andrew Kelley
173142cc36
Merge pull request #8611 from shachaf/precedence
parser: Use an operator precedence table
2021-05-13 17:40:03 -04:00
Jakub Konka
1b222cb1ff start.zig: export main with strong linkage
Unmarks `_main` as weak symbol making it global (the entire linked
program) in scope.
2021-05-13 17:24:32 -04:00
Jakub Konka
402264ab0e Add experimental Darling support for cross testing macOS
* for cross testing stage2 tests, we use `darling shell` command
  since the path to the tested binary is relative to cwd
* for the `zig test` command, we simply use `darling` since the
  path to the binary is absolute
2021-05-13 20:31:33 +02:00
Matthew Borkowski
cadb84b3ac fix duplicate_field_behavior UseFirst in json.zig 2021-05-13 09:43:55 -04:00
Matthew Borkowski
e902c19c0e
std/json: Fix premature closing brace being considered valid JSON
return error from StreamingParser when reading closing brace when expecting value for an object key
2021-05-13 11:11:28 +02:00
Andrew Kelley
417b5b1daa std: fix redundant comptime keywords
caught by stage2 astgen
2021-05-12 20:44:05 -07:00
Andrew Kelley
1ab3dff846 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Need the latest commit which fixes std and behavior tests for cross
compiled glibcs.
2021-05-12 20:37:40 -07:00
Andrew Kelley
799d1f0d36 build system: fix wrong glibc dir passed to qemu for i386
Without this, and with `-Denable-qemu -Denable-foreign-glibc`,
i386-linux-gnu tests failed because the `-L` path passed to qemu
was "i386-linux-gnu" (nonexistent) rather than "i686-linux-gnu".

Fixes std lib and behavior tests when using these options to enable
test coverage with cross compiled glibcs.
2021-05-12 20:34:54 -07:00
Andrew Kelley
c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
Koakuma
90a54f06e5 Add a comment to explain the alignment directive 2021-05-13 06:18:51 +07:00
Matthew Borkowski
40a47eae65 fix shrinkAndFree and remove shrinkRetainingCapacity in PriorityQueue and PriorityDequeue 2021-05-12 18:33:25 -04:00
Andrew Kelley
43da102920
Merge pull request #8698 from ifreund/scanZ
std/mem: add sliceTo(), deprecate spanZ(), lenZ()
2021-05-12 18:15:36 -04:00
LemonBoy
893a428656 stage2: Drop LLVM's host CPU detection method as fallback
The CPU detection code is nearly at feature parity, we do support
detecting the native CPU on Sparc systems and macos, our ARM/AArch64
model list is quite comprehensive and so is our PPC one.

The only missing pieces are:
- ARM32 detection on Darwin hosts (I don't think anybody is planning on
  running the compiler on a old-ass iPhone)
- s390x detection on Linux hosts, this can be easily added at a later
  stage.
2021-05-12 14:03:59 -04:00
Koakuma
9e67c062c4 Add missing f128 compiler-rt shim 2021-05-12 20:13:29 +07:00
Isaac Freund
cd7b5a3718
std/mem: add sliceTo(), deprecate spanZ(), lenZ()
The current spanZ() function will not scan for a 0 terminator if the
type is not 0 terminated. This encourages using 0 terminated array
types to bind C arrays which hold 0 terminated strings. However, this is
a big footgun as nothing in the C type system guarantees there to be a
0 terminator at the end of the array and if there is none this becomes
Illegal Behavior in Zig.

To solve this, deprecate spanZ() and lenZ(), adding a new sliceTo()
function that always scans for the given terminator even if the type is
not sentinel terminated.
2021-05-12 11:24:49 +02:00
Koakuma
f24d0fbb07 Remove SPARC pthreadtypes-arch.h to match upstream glibc
This is only a temporary measure, we need to properly update the bundled glibc.
2021-05-12 14:54:13 +07:00
Koakuma
5dd6f9616e Fix linux dirent64 buffer align directive 2021-05-12 14:52:53 +07:00
LemonBoy
e260cfae85 stage2: Add CPU feature detection for macos
This is mostly meant to detect the current and future AArch64 core types
as the x86 part is already taken care of with OS-independent machinery.
2021-05-12 09:43:49 +02:00
Koakuma
6e5330ee38 Define ENOTSUP for SPARC 2021-05-12 14:23:08 +07:00
Michael Dusan
30ace64fc4 bsd: detect os version
- netbsd, dragonly: use sysctlbyname
- openbsd: use sysctl
- updated default semver ranges
2021-05-11 22:05:08 -04:00
Isaac Freund
e6881d4373
std/json: fix previous commit for std.testing changes 2021-05-11 23:09:25 +02:00
Matthew Borkowski
1b87d45494 fix a double free in parse when duplicate_field_behavior is UseLast and a leak in parse when allocating a single item 2021-05-11 22:54:02 +02:00
Isaac Freund
c036957521
std.meta.Elem: support all optional types 2021-05-11 22:22:21 +02:00
Andrew Kelley
ace5714551
Merge pull request #8705 from LemonBoy/libc-fix
32bit glibc fixes
2021-05-11 15:15:00 -04:00
Andrew Kelley
c3d4733a00 test runner: avoid an "out of memory" error return trace entry
The long term solution to this will be #1923
2021-05-11 11:47:22 -07:00
Andrew Kelley
65d279bc05 test runner: print error return trace after failed test 2021-05-11 10:50:17 -07:00
LemonBoy
8bb58fb428 std: Fix offset param splitting for preadv/pwritev
The kernel interface expects the offset as a low+high pair even on BE
systems.
2021-05-11 15:49:53 +02:00
Matthew Borkowski
75ed835d08 fix AutoArrayHashMap's store_hash logic 2021-05-11 16:14:23 +03:00
LemonBoy
780f510ac0 std: Fix fallocate offset type 2021-05-11 12:33:48 +02:00
LemonBoy
c065e12dbe std: Add more tests, fix broken code
It turns out that nothing in the test suite was exercising
preadv/pwritev and so the previous commits silently broke them.

Adding tests revealed readvAll and preadvAll were also broken and not
covered by any test.
2021-05-11 12:33:48 +02:00
LemonBoy
31f1cc9a0d std: Harmonize use of off_t between libc and Zig impls
Let's follow the libc/kernel convention and use an i64 for offsets, we
bitcast as needed and avoid the useless conditional casts.
2021-05-11 12:33:48 +02:00
LemonBoy
f4a05286d3 std: Fix cast that's sometimes invalid 2021-05-11 12:33:48 +02:00
LemonBoy
679876ba72 c: Fix prototypes for bcmp and memcmp
They return c_int and not isize.
2021-05-11 12:33:47 +02:00
LemonBoy
a909db6aea std: Prefer 64bit libc functions where possible
While musl decided to hard-wire off_t to a 64bit quantity, glibc is much
older and defaults to 32bit offsets and offers some -64 suffixed
versions of I/O functions.

There's a weird mix-up of types: sometimes off_t is used, sometimes not,
sometimes it's defined as a signed quantity and sometimes as an unsigned
one, but we'll sort this problem later.
2021-05-11 12:33:47 +02:00
LemonBoy
28a9e4c4aa libc: Add workaround for #4926
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
2021-05-11 12:33:47 +02:00
Andrew Kelley
b9a099e83c stage2: type declarations ZIR encode AnonNameStrategy
which can be either parent, func, or anon. Here's the enum reproduced in
the commit message for convenience:

```zig
pub const NameStrategy = enum(u2) {
    /// Use the same name as the parent declaration name.
    /// e.g. `const Foo = struct {...};`.
    parent,
    /// Use the name of the currently executing comptime function call,
    /// with the current parameters. e.g. `ArrayList(i32)`.
    func,
    /// Create an anonymous name for this declaration.
    /// Like this: "ParentDeclName_struct_69"
    anon,
};
```

With this information in the ZIR, a future commit can improve the
names of structs, unions, enums, and opaques.

In order to accomplish this, the following ZIR instruction forms were
removed and replaced with Extended op codes:

 * struct_decl
 * struct_decl_packed
 * struct_decl_extern
 * union_decl
 * union_decl_packed
 * union_decl_extern
 * enum_decl
 * enum_decl_nonexhaustive

By being extended opcodes, one more u32 is needed, however we more than
make up for it by repurposing the 16 "small" bits to provide shorter
encodings for when decls_len == 0, fields_len == 0, a source node is not
provided, etc. There tends to be no downside, and in fact sometimes
upsides, to using an extended op code when there is a need for flag
bits, which is the case for all three of these. Likewise, the container
layout can be encoded in these bits rather than into the opcode.

The following 4 ZIR instructions were added, netting a total of 4 freed
up ZIR enum tags for future use:

 * opaque_decl_anon
 * opaque_decl_func
 * error_set_decl_anon
 * error_set_decl_func

This is so that opaques and error sets can have the same name hint as
structs, enums, and unions.

`std.builtin.ContainerLayout` gets an explicit integer tag type so that
it can be used inside packed structs.

This commit also makes `Module.Namespace` use a separate set for
anonymous decls, thus allowing anonymous decls to share the same
`Decl.name` as their owner `Decl` objects.
2021-05-10 21:34:43 -07:00
Andrew Kelley
55d235dc38
Merge pull request #8711 from lithdew/master
std/os, x/os/socket: windows support, socket helpers, getpeername()
2021-05-10 19:00:53 -04:00
jacob gw
24dfa61236 stage1: remove outdated error message regarding #447 2021-05-10 21:00:10 +02:00
lithdew
0d0edd23a8 std/os: add missing sockaddr_storage defs 2021-05-10 19:22:31 +09:00
lithdew
e652595f2a std/os: fix sockaddr_storage padding size 2021-05-10 19:22:31 +09:00
lithdew
6d41e08664 x/os, os: fix setsockopt on windows, simplify Socket.setOption error set 2021-05-10 19:22:31 +09:00
lithdew
6cb6edb6f6 std/os/windows/ws2_32: add missing FIONBIO constant 2021-05-10 19:22:31 +09:00
lithdew
77f8a9ae22 x/os/socket, std/os/windows: implement loading winsock extensions
Implement loading Winsock extensions.

Add missing Winsock extension GUID's.

Implement readVectorized() for POSIX sockets and
readVectorized() / writeVectorized() for Windows
sockets.

Inverse how mixins are used to implement platform-independent syscalls
for the std.x.os.Socket abstraction. This cleans up the API as suggested
by @komuw.
2021-05-10 19:22:31 +09:00
lithdew
3d946ef5eb x/os, x/net, os:, fix typos/errors, add missing constants/docs
Add missing constants to ws2_32 such as SIO_BASE_HANDLE.

Made all declared constants in ws2_32 comptime_int, and fixed a few
broken constants (i.e. GUID's).

Fixed a few syscalls not having callconv(WINAPI) in ws2_32.

Fixed a typo in std.x.net.tcp.Client.

Removed unnecessary @alignCast's for socket addresses in
std.x.net.Socket.

Added a warning on using timeout methods for std.x.net.Socket.

Fixed compilation error spotted by CI in std.os that references
std.os.windows.ws2_32.SD_RECEIVE.

Renamed std.x.os.Socket.setOption()'s parameter `name: u32` to `code:
u32`.
2021-05-10 19:22:31 +09:00
Kenta Iwasaki
a24101be5b x/os/socket_posix.zig: make linger struct extern
Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
2021-05-10 19:22:31 +09:00
lithdew
e739b2b7d6 x/os/socket: use sockaddr_storage for accept() 2021-05-10 19:22:31 +09:00
lithdew
d3871af724 x/net/tcp, x/os/socket: tcp.Client.{Reader, Writer}
Only allow SOCK_STREAM (std.x.net.tcp.Client) sockets to have wrappers
for std.io.Reader and std.io.Writer provided, instead of Socket's in
general.
2021-05-10 19:22:31 +09:00
lithdew
d7b601b35e std/os, x/os/socket: windows support, socket helpers, getpeername()
Socket I/O methods such as read, readv, write, writev, send, recv,
sendmsg, recvmsg have been generalized to read(buf, flags), write(buf,
flags), readVectorized(vectors, flags), and writeVectorized(vectors,
flags). There is still some work left to be done abstracting both
readVectorized and writeVectorized properly across platforms, which is
work to be done in a future PR.

Support for setting the linger timeout of a socket, querying the remote
address of a socket, setting whether or not keep-alive messages are to
be sent through a connection-oriented socket periodically depending on
host operating system settings has been added.

`std.io.Reader` and `std.io.Writer` wrappers around `Socket` has been
implemented, which wrap around Socket.read(buf, flags) and
Socket.write(buf, flags). Both wrappers may be provided flags which are
passed to Socket.read / Socket.write accordingly.

Cross-platform support for `getpeername()` has been implemented.

Windows support for the new `std.x.os.Socket` has been implemented. To
accomplish this, a full refactor of `std.os.windows.ws2_32` has been
done to supply any missing definitions and constants based on
auto-generated Windows syscall bindings by @marler8997.

`std.x.net.TCP.Listener.setQuickACK` has been moved to
`std.x.net.TCP.Client.setQuickACK`.

Windows support for resolving the scope ID of an interface name
specified in an IPv6 address has been provided.

`sockaddr_storage` definitions have been provided for Windows, Linux,
and Darwin. `sockaddr_storage` is used to allocate space before any
socket addresses are queried via. calls such as accept(), getsockname(),
and getpeername().

Zig-friendly wrappers for GetQueuedCompletionStatusEx(), getpeername(),
SetConsoleCtrlHandler(), SetFileCompletionNotificationModes() syscalls
on Windows have been provided.

Socket.setOption() was provided to set the value of a socket option in
place of os.setsockopt. Socket.getOption() will be provided in a future
PR.

There is still further work to be done regarding querying socket option
values on Windows, which is to be done in a subsequent PR.
2021-05-10 19:22:31 +09:00
Jakub Konka
9c03b39d1e
Merge pull request #8723 from jedisct1/init-stat
Initialize the Stat structure
2021-05-10 09:42:37 +02:00
Frank Denis
2d11967734
p256: properly handle neutral element & add AffineCoordinates struct (#8718)
Instead of multiple references to an anonymous structure to represent affine coordinates, add an actual `AffineCoordinates` structure.

Also properly handle the neutral element during coordinate conversion and fix mixed addition.

And comptime the small precomputation table for basepoint multiplication.
2021-05-09 18:20:43 +02:00
Frank Denis
c3675d9351 Shorten 2021-05-09 18:17:09 +02:00
Frank Denis
4e399ef62c Initialize the Stat structure
The system `stat` structure includes padding, and, on some
operating systems such as all BSDs, "spare" bytes at the end.

We can't reliably compare two `Stat` values if these are
uninitialized, while being later compared.

This is what was causing the `fstatat` test to fail on FreeBSD
since the update to LLVM 12. It was previously only passing by
accident.
2021-05-09 18:15:42 +02:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Andrew Kelley
67154d233e
Merge pull request #8686 from Vexu/try
Allow tests to fail
2021-05-08 17:29:44 -04:00
Andrew Kelley
b6bb0ee1ac Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux/tls.zig
 * test/behavior/align.zig
 * test/behavior/atomics.zig
 * test/behavior/vector.zig
2021-05-08 10:53:22 -07:00
Veikka Tuominen
7fe39c4e96 update usage of std.testing in compiler_rt 2021-05-08 15:15:30 +03:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Veikka Tuominen
59f9253d94 allow tests to fail 2021-05-08 15:15:23 +03:00
Andrew Kelley
6ec24a6502 std: start code on linux when -lc also expands stack size
See #8708
2021-05-07 21:34:53 -07:00
Andrew Kelley
f69cf93064 std: start code increases stack size as appropriate on linux
closes #8708
2021-05-07 21:23:51 -07:00
Andrew Kelley
a7221ef4e9 Sema: implement @typeInfo for functions
The goal is to get start code to be able to inspect the calling
convention of `main` in order to determine whether to export a main for
libc to call, or to allow the root source file to do it.
2021-05-06 22:30:44 -07:00
Michael Dusan
84d5cc31c5 fix test to restore cwd after chdir
- `../zig-cache/tmp` is no longer created by subsequent test(s)
2021-05-07 01:04:38 -04:00
Andrew Kelley
7dd33d4316 stage2: fix compile errors in test harness 2021-05-06 17:48:38 -07:00
Andrew Kelley
426e4c784c std.ArrayHashMap: ensureUnusedCapacity and ensureTotalCapacity
Same as 22015c1b3b, but for ArrayHashMap.
2021-05-06 12:50:53 -07:00
Andrew Kelley
530e67cb86
Merge pull request #8683 from LemonBoy/thumblinux
Initial bringup for Linux/Thumb2
2021-05-06 12:50:34 -04:00
Andrew Kelley
c714a3250f std.ArrayList: add clearRetainingCapacity and clearAndFree 2021-05-05 16:55:49 -07:00
Andrew Kelley
6b5d0b3711 std: fix compile errors found by stage2
* redundant `comptime`
 * `try` outside function
 * `extern enum`
2021-05-05 11:03:54 -07:00
Andrew Kelley
fc40d23723 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * lib/std/array_list.zig
 * lib/std/c/ast.zig
 * lib/std/c/parse.zig
 * lib/std/os/bits/linux.zig
2021-05-05 10:48:22 -07:00
LemonBoy
9d409233b2 std: Implement hex float printing
The results have been cross-checked with LLVM's APFloat implementation
by randomly sampling the f32/f64 space, while the f16 one was completely
checked given the small size.
2021-05-05 12:37:40 -04:00
Michael Dusan
622a3ac876
Merge pull request #8691 from lithdew/master
x/net: fix tcp tests for openbsd and add missing `fmt` import
2021-05-05 05:54:47 -04:00
Andrew Kelley
368e13a9a1
Merge pull request #8671 from LemonBoy/arm-host-det
ARM/AArch64 CPU host detection
2021-05-05 03:17:32 -04:00
LemonBoy
e863204c47 zig fmt: Fix edge case in inline asm parsing
The presence of a trailing comma in the single and only input/output
declaration confused the parser and made zig fmt discard any element
placed after the comma.
2021-05-05 03:16:07 -04:00
lithdew
c75ae8b66d x/net: fix tcp tests for openbsd and add missing fmt import
On OpenBSD, connecting to a newly-allocated port on an unspecified IPv4
host address causes EINVAL. This was found by @mikdusan when running TCP
tests on OpenBSD.

This commit fixes TCP tests on OpenBSD by having all tests that allocate
a new host-port pair to have the host IPv4/IPv6 address point to the
host's loopback adapter (on localhost).
2021-05-05 16:09:08 +09:00
Sage Hane
975cb9e9a9
std.zig: make the unrecognized C flag case non-fatal 2021-05-05 04:19:08 +09:00
Andrew Kelley
785a6c1aa9 std: remove dead and rotting C parsing code 2021-05-04 10:26:44 -07:00
LemonBoy
afbcb6209d std: Initial bringup for Linux on Thumb2
There are some small problems here and there, mostly due to the pointers
having the lsb set and disrupting the fn alignment tests and the
`@FrameSize` implementation.
2021-05-04 18:52:53 +02:00
LemonBoy
4bf093f1a0 compiler-rt: Better selection of __clzsi implementation
To be honest all this detection logic is starting to become a real PITA,
the ARM32 version can be possibly removed as the generic version
optimizes pretty well...
2021-05-04 18:45:52 +02:00
LemonBoy
b6be28ddcc std: Accept unaligned slice in several ArrayListAligned ops
Do not impose the internal alignment requirements to the user-supplied
parameters.

Closes #8647
2021-05-04 14:08:19 +03:00
Andrew Kelley
2ae72c6f09 Sema: implement ExportOptions support in @export
Also fix switch blocks not emitting their AIR code.
2021-05-03 20:05:29 -07:00
Andrew Kelley
0e3930bb5a
Merge pull request #8649 from lithdew/master
x/os, x/net: layout tcp, ipv4/ipv6, and socket abstractions
2021-05-03 17:38:10 -04:00
LemonBoy
3eed613407 std: Add two more ARM CPUs to the known CPU list
Modeled after GCC's description.
2021-05-03 12:32:13 +02:00
LemonBoy
e2d2295382 std: Add many more vendors and cpus to the ARM detection list
Hand-picked from GCC and LLVM lists.
2021-05-03 12:32:13 +02:00
LemonBoy
a7f3e12d23 std: Add fallback on pre-v6 ARM targets
Thanks xackus for noticing the missing else branch.
2021-05-03 12:32:13 +02:00
LemonBoy
792cf925ec std: Fix missing CPU feature check
We need both the v6k and the v6m checks.
2021-05-03 12:32:13 +02:00
LemonBoy
b10d40b89b stage2: Implement CPU host detection for ARM/AArch64 targets 2021-05-03 12:32:13 +02:00
Frank Denis
97779442d0
Prepare std/crypto/pcurves for ecdsa and other curves (#8670)
Functions generated by Fiat-crypto are not prefixed by their description any more. This matches an upstream change.

We can now use a single type for different curves and implementations.

The field type is now generic, so we can properly handle the base field and scalars without code duplication.
2021-05-03 09:57:45 +02:00
lithdew
96fe49ef62 std/os/bits/windows: add timeval extern struct 2021-05-03 14:49:10 +09:00
lithdew
16fc1b904c std/os/linux/bits: correct socket option codes for ppc/ppc64 2021-05-03 14:49:10 +09:00
lithdew
af057c888b x/net/ip: add copyright header 2021-05-03 14:49:10 +09:00
lithdew
5c4fbc4014 x/net: generalize tcp.Address into ip.Address
Generalize `tcp.Address` into `ip.Address` given that multiple transport
protocols apart from TCP (i.e. UDP) operate solely over IP.
2021-05-03 14:49:10 +09:00
lithdew
cc6714a929 std/os/bits: add timeval struct for riscv64 linux 2021-05-03 14:49:10 +09:00
lithdew
a799ad05b3 x/net/tcp: make tcp tests blocking to avoid unit test races 2021-05-03 14:49:10 +09:00
lithdew
aa15699269 x/os/net: skip ipv6 scope id parse test on unsupported platforms 2021-05-03 14:49:10 +09:00
lithdew
9a7c57144d x/net: disable tcp tests on wasi 2021-05-03 14:49:10 +09:00
lithdew
8ef9d98e6d x/os: fix compile errors on mac and linux
Use i32 instead of isize for os.timeval's for socket read/write
timeouts.

Add a comptime check to resolveScopeID to see if `IFNAMESIZE` is
available on the host. If it is not available, return an error
indicating that resolving the scope ID of a IPv6 address is not yet
supported on the host platform.
2021-05-03 14:49:10 +09:00
lithdew
76304a36af std/builtin: add missing comma to CallingConvention 2021-05-03 14:49:10 +09:00
lithdew
13068da43e x/os, x/net: re-approach Address, rename namespace TCP -> tcp
Address comments from @ifreund and @MasterQ32 to address unsafeness and
ergonomics of the `Address` API.

Rename the `TCP` namespace to `tcp` as it does not contain any
top-level fields.

Fix missing reference to `sockaddr` which was identified by @kprotty in
os/bits/linux/arm64.zig.
2021-05-03 14:49:10 +09:00
lithdew
2ab588049e x/os, x/net: layout tcp, ipv4/ipv6, and socket abstractions
The `Socket` abstraction was refactored to only comprise of methods that
can be generically used/applied to all socket domains and protocols.

A more comprehensive IPv4/IPv6 module derived from @LemonBoy's earlier
work was implemented under `std.x.os.IPv4` and `std.x.os.IPv6`. Using
this module, one can then combine them together into a union for example
in order to optimize memory usage when dealing with socket addresses.

A `TCP.Client` and `TCP.Listener` abstraction is introduced that is one
layer over the `Socket` abstraction, which isolates methods that can
only be applied to a "client socket" and a "listening socket". All prior
tests from the `Socket` abstraction, which all previously operated
assuming the socket is operating via. TCP/IP, were moved. All TCP socket
options were also moved into the `TCP.Client` and `TCP.Listener`
abstractions respectively away from the `Socket` abstraction.

Some additional socket options from @LemonBoy's prior PR for Darwin were
also moved in (i.e. SIGNOPIPE).
2021-05-03 14:49:10 +09:00
Andrew Kelley
807a8b6f75 stage2: make struct field analysis lazy
This commit breaks struct field analysis; will be fixed in a future
commit.
2021-05-02 18:50:01 -07:00
Andrew Kelley
6248e2a560 std.GeneralPurposeAllocator: print leaked memory addresses
This helps when using it with other tools, such as memory watchpoints.
2021-05-01 21:25:01 -07:00
Andrew Kelley
4f9c928e56
Merge pull request #8665 from LemonBoy/misc
Miscellaneous patches
2021-05-01 18:07:58 -04:00
Andrew Kelley
d788181a3b
fix typo
Co-authored-by: Maciej Walczak <14938807+xackus@users.noreply.github.com>
2021-05-01 18:07:26 -04:00
Sage Hane
6490e57136
std.zig: handle -frandom-seed in NIX_CFLAGS_COMPILE 2021-05-02 02:44:55 +09:00
LemonBoy
06b2fee05e std: Implement isFinite for f128 2021-05-01 16:28:13 +02:00
LemonBoy
236dba8ba9 std: Implement copysign for f128 2021-05-01 16:28:08 +02:00
LemonBoy
9f6edfd201 std: Implement signbit for f128 2021-05-01 16:28:03 +02:00
LemonBoy
718b43504e std: Fix pwrite/pread syscalls on SPARC targets 2021-05-01 15:46:28 +02:00
LemonBoy
69a9c1488d std: Add signal numbers for SPARC 2021-05-01 12:25:40 +02:00
LemonBoy
527053a4e4 std: Import correct errno defs for SPARC
Taken from Linux arch/sparc/include/uapi/asm/errno.h
2021-05-01 11:03:59 +02:00
LemonBoy
51f80deaf6 std: Fix stack overflow in SPARC clone() impl
Leave the minimum amount of stack space required by the ABI (16 * 8
bytes for the window contents plus 6 * 8 bytes for the input arguments)
on the new thread stack.
2021-05-01 11:02:04 +02:00
g-w1
e9e91b4ed0
std.build: if using a RunStep, show the command run on verbose (#8571) 2021-05-01 08:17:17 +02:00
Frank Denis
fe8781357a
std.crypto: add support for the NIST P-256 curve (#8627)
Uses verified code generated by fiat-crypto for field arithmetic, and complete formulas to avoid side channels.

There's still plenty of room for optimizations, especially with a fixed base. But this gives us a framework to easily add other similar curves.
2021-05-01 08:14:32 +02:00
Andrew Kelley
dc28f5c3ec Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
	lib/std/crypto/25519/field.zig
	lib/std/crypto/poly1305.zig

I had resolved those by removing `comptime` but master branch decided to
make the parameters `comptime`.

This also pulls in the updated default `zig build` install directory.
2021-04-30 23:13:17 -07:00
Devin Bayer
d3f55782b0
rename doc refs to deprecated functions like openC (#8467) 2021-04-30 21:31:01 +02:00
Andrew Kelley
fb95fd8443 start.zig: unconditionally import the root source file
stage1 did this by accident by unconditionally semantically analyzing
std.builtin.panic, which imports the root source file to look for a
panic handler override. But stage2 is smarter; it will only semantically
analyze std.builtin.panic if any panic calls are emitted. So for very
simple compilations, the root source file was being ignored, even if it
contained `export` functions in it.
2021-04-30 11:24:15 -07:00
LemonBoy
807bb7c03f std: Improve spinloop hint
* Add a yield pattern for PowerPC64
* Fix compile error on pre-v6 ARM targets
* Use isb instead of yield on AArch64 to give the CPU a chance to enter
  low-power states.
* Make the hint an inline function, the call overhead can be avoided.
2021-04-30 17:11:03 +02:00
Yorhel
f79b487337 Handle EPERM and ELOOP in os.fstatat() 2021-04-30 15:08:07 +02:00
Andrew Kelley
4e07755ce7
Merge pull request #8638 from ifreund/build-default-prefix
std/build: change default install prefix to zig-out
2021-04-30 00:10:44 -04:00
Andrew Kelley
474ade88b5 std: fix compile errors found by stage2 AstGen 2021-04-29 20:33:29 -07:00
Andrew Kelley
fb4cb430e0 std.enums: remove stuff for enums with field aliases
This will probably conflict with the real patch to rework this code, and
in such case this commit should be discarded in favor of the other
commit.
2021-04-29 16:05:30 -07:00
Andrew Kelley
4307436b99 move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
2021-04-29 15:54:04 -07:00
Isaac Freund
5079d11b21
std/build: change default install prefix to zig-out
Currently the default install prefix is $BUILD_ROOT/zig-cache,
but mixing cache and artifacts makes little sense. Instead make
$BUILD_ROOT/zig-out the default.
2021-04-29 23:58:45 +02:00
Matthew Borkowski
585479500e check for overflow when reading code lengths for a block with dynamic Huffman codes 2021-04-29 17:48:08 -04:00
Frank Denis
687ef42f98
x: comptime bool -> comptime x: bool (#8639) 2021-04-29 16:27:50 +02:00
Isaac Freund
2ed368fb92
std/build: add -p alias for --prefix 2021-04-29 14:25:58 +02:00
Andrew Kelley
c60d8f017e std: remove redundant comptime keyword
@g-w1's fancy new compile error in action
2021-04-28 22:58:12 -07:00
Andrew Kelley
c90e52b74c std: remove redundant comptime const 2021-04-28 15:15:44 -07:00
Andrew Kelley
d3ffacb55c AstGen: hook up hex float parsing to float literals
Thanks @LemonBoy!
2021-04-28 15:13:43 -07:00
Andrew Kelley
df24ce52b1 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted to take advantage of the new hex float parsing
code.
2021-04-28 14:57:38 -07:00
LemonBoy
55c58f226d std: Add a parser for hexadecimal floating point numbers
Should be good enough to unblock progress on the stage2 compiler.

Unifying this parser and the regular one (and perhaps rewrite it, #2207)
is left as an exercise for the reader.
2021-04-28 17:36:12 -04:00
Andrew Kelley
86e129eff6 std.Target: bump freebsd known maximum version 2021-04-28 10:26:47 -07:00
Andrew Kelley
2c9ed6daee
Merge pull request #8472 from sreehax/master
callconv: add SysV
2021-04-28 13:11:40 -04:00
LemonBoy
da9da76e3f stage1: Implement CPU host detection for PowerPC targets
Untested but should work well on both 32 and 64 bit systems.
2021-04-27 13:11:39 -04:00
Andrew Kelley
bfded492f0 stage2: rewire the frontend driver to whole-file-zir
* Remove some unused imports in AstGen.zig. I think it would make sense
   to start decoupling AstGen from the rest of the compiler code,
   similar to how the tokenizer and parser are decoupled.
 * AstGen: For decls, move the block_inline instructions to the top of
   the function so that they get lower ZIR instruction indexes. With
   this, the block_inline instruction index combined with its corresponding
   break_inline instruction index can be used to form a ZIR instruction
   range. This is useful for allocating an array to map ZIR instructions
   to semantically analyzed instructions.

 * Module: extract emit-h functionality into a struct, and only allocate
   it when emit-h is activated.
 * Module: remove the `decl_table` field. This previously was a table of
   all Decls in the entire Module. A "name hash" strategy was used to
   find decls within a given namespace, using this global table. Now,
   each Namespace has its own map of name to children Decls.
   - Additionally, there were 3 places that relied on iterating over
     decl_table in order to function:
     - C backend and SPIR-V backend. These now have their own decl_table
       that they keep populated when `updateDecl` and `removeDecl` are
       called.
     - emit-h. A `decl_table` field has been added to the new GlobalEmitH
       struct which is only allocated when emit-h is activated.
 * Module: fix ZIR serialization/deserialization bug in debug mode having
   to do with the secret safety tag for untagged unions. There is still an
   open TODO to investigate a friendlier solution to this problem with
   the language.
 * Module: improve deserialization of ZIR to allocate only exactly as
   much capacity as length in the instructions array so as to not waste
   space.
 * Module: move `srcHashEql` to `std.zig` to live next to the definition
   of `SrcHash` itself.
 * Module: re-introduce the logic for scanning top level declarations
   within a namespace.

 * Compilation: add an `analyze_pkg` Job which is used to kick off the
   start of semantic analysis by doing the equivalent of
   `_ = @import("std");`. The `analyze_pkg` job is unconditionally added
   to the work queue on every update(), with pkg set to the std lib pkg.

 * Rename TZIR to AIR in a few places. A more comprehensive rename will
   come later.
2021-04-26 20:41:07 -07:00
Andrew Kelley
1c0259f11e
Merge pull request #8609 from jedisct1/timingSafeCompare
Add std.crypto.utils.timingSafeCompare
2021-04-26 23:03:46 -04:00
Frank Denis
d3361c41db Change timingSafeCompare() to accept slices 2021-04-26 22:32:22 +02:00
Frank Denis
030fa5e7eb
25519: remove unused const, safeguard against unreduced scalars (#8624)
* 25519: remove unused const, safeguard against unreduced scalars

No behavior change, but it makes the existing code better match
the forthcoming code for other curves.

Rename nonAdjacentForm() to slide(), remove an unneeded and
confusing constant, and do a reduction in slide() if 257 bits would
be required.

Note that in all the high-level functions, the top bit is always
cleared, so the reduction is never necessary. But since the low-level
functions are public, the check is a safe thing to have.

* 25519: make identityElement public, deprecate neutralElement

Also fix a few comments by the way.
2021-04-26 22:25:48 +02:00
Andrew Kelley
95b42f9e6b
Merge pull request #8604 from hoanga/haiku-support-sysdefs
further haiku support system definitions
2021-04-26 16:12:23 -04:00
Andrew Kelley
0de962fdd9
Merge pull request #8622 from LemonBoy/cpuinfo
stage2: Add framework for host CPU detection on Linux
2021-04-26 16:02:07 -04:00
Andrew Kelley
528a83dd6b
Merge pull request #8618 from LemonBoy/mini-stuff
Two small patches
2021-04-26 14:32:45 -04:00
Andrew Kelley
ddf9ff79bd Revert "thread: simplify and remove useless return in spawn (#8621)"
This reverts commit 77cb45f59f.

Zig's error return traces will point to the return token if they
happen to occur, so having multiple return statements makes those
stack traces really helpful. This destroys debuggability.
2021-04-26 10:44:40 -07:00
LemonBoy
7e6cc4c505 stage2: Ensure the features set is populated 2021-04-26 18:28:17 +02:00
LemonBoy
896d93e1e6 stage2: Add framework for host CPU detection on Linux
Add a generic framework to parse /proc/cpuinfo and implement the model
detection for 64bit SPARC targets as proof of concept.
2021-04-26 18:11:28 +02:00
Vincent Rischmann
77cb45f59f
thread: simplify and remove useless return in spawn (#8621) 2021-04-26 18:03:32 +02:00
jumpnbrownweasel
bf67a3fdc9
#8454 Fix for std.mem.replacementSize adjacent matches bug. (#8455)
* #8454 Fix for std.mem.replacementSize adjacent matches bug.

When two 'needle' values are adjacent in the 'input' slice, the size is not
counted correctly. The 2nd 'needle' value is not matched because the index is
incremented by one after changing the index to account for the first value.

The impact is the the size returned is incorrect, and could cause UB when this
amount is used to size of the buffer passed to std.mem.replace.

* Apply changes from PR review:

- Add assert checking that the needle is non-empty and doc for this.
- Add minimal test that an empty input works.
- Use testing.expectEqualStrings.
2021-04-25 19:16:24 -04:00
Andrew Kelley
c420eb60ad
Merge pull request #8590 from lithdew/master
x,  x/os/Socket: initial work on new Socket abstraction
2021-04-25 19:15:15 -04:00
Andrew Kelley
2fc6b347ec
Merge pull request #8616 from LemonBoy/fn-align
Function pointer alignment
2021-04-25 19:12:06 -04:00
Andrew Kelley
6f61594692
Merge pull request #8496 from xackus/isError
std.meta: add isError
2021-04-25 13:27:44 -04:00
LemonBoy
5a94794b73 std: Fix thread creation with field-less context type
Closes #8524
2021-04-25 13:21:15 -04:00
LemonBoy
dc29d86649 std: Fix wrong alignOf expression
Mostly harmless but conceptually wrong, luckily it hasn't tripped any
safety check.
2021-04-25 19:12:49 +02:00
LemonBoy
54db36cd88 std: Fix backtraces on sparcv9
Flush all the register windows to stack before starting the stack walk,
we may otherwise try to read garbage and crash and burn.

Add a few comptime annotations to debloat some functions.
2021-04-25 19:10:11 +02:00
Frank Denis
0747591c3d Add std.crypto.utils.timingSafeCompare
A little function to complement the existing crypto.utils.timingSafeEql
function with a way to compare large numbers serialized as arrays.

This is useful to compare nonces and to check that group elements are
in canonical form.

Absence of side channels remains a best effort, reusing the common
pattern we use elsewhere.
2021-04-25 17:07:11 +02:00
LemonBoy
19cec0db1e std: Make met.alignment work on more types
Make it return the correct value for function types and optional
pointers.
2021-04-25 16:49:21 +02:00
lithdew
98706c9686 x: fmt source code 2021-04-25 21:15:02 +09:00
lithdew
b435d7fa60 x, x/os/Socket: initial work on new Socket abstraction
Kick-start initial work on new cross-platform abstraction for
sockets. Adds a test for read timeouts and a test for creating
a non-blocking socket pair on Linux.

The new Socket abstraction is barebones and is made to support both
blocking and non-blocking abstractions, alongside different socket
protocols and domains.

Support for platform-dependant socket options that handles unsupported
platforms gracefully via. comptime checks is provided for the new Socket
abstraction.

This also marks the first out of many commits for introducing breaking
changes to the standard library in a separate `x` folder, which was
pre-approved by @andrewrk.

The intent for the new `x` package is to introduce new async, event loop,
networking, and operating system abstractions that would require breaking
the standard library significantly. By having the `x` package, code in the
standard library and compiler may then slowly be refactored to use the `x`
package. Once modules in the `x` package are stabilized, they can be moved
out of the `x` package, and a global 'grep' can be done to update import
paths that resolve to the stabilized module in the `x` package.
2021-04-25 21:15:02 +09:00
Andrew Kelley
015cd79f89 stage2: implement caching for ZIR code
Notably this exposed an issue with the language having to do with the
secret safety tag on untagged unions. How can we have our cake and eat
it too? Not solved in this commit. I will file a language proposal to
tackle this issue soon.

Fixes a compile error in `std.fs.File.readvAll`.
2021-04-25 00:02:58 -07:00
Shachaf Ben-Kiki
33da465079 Use a directEnumArray lookup table instead of a switch 2021-04-24 23:03:48 -07:00
Shachaf Ben-Kiki
01aa74a93f parser: Use an operator precedence table
Instead of having one function per precedence level, mirroring the BNF grammar,
this uses the "precedence climbing" algorithm with a table of operator
precedences (and a few special cases that don't fit into the table as it is).

This is a first pass -- it's probably possible to put more of the parser
into this form, e.g. to support prefix/suffix operators with precedence, if
necessary, or just to simplify the code more.

It may also be possible to speed this up by putting more useful information
into the tokens during tokenization, to avoid the extra branch on the token in
operInfo.
2021-04-24 22:40:41 -07:00
Andrew Kelley
e86cee258c Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted the change that makes `suspend;` illegal in the
parser.
2021-04-24 10:44:41 -07:00
Matt Knight
8530b6b724 fix import path 2021-04-24 13:35:55 -04:00
Frank Denis
7a793a9b9d ed25519: use double-base multiplication for signature verification
This makes single signature verification about 60% faster.

Also check that R is not the identity point.
2021-04-24 13:35:36 -04:00
LemonBoy
eabf378a56 zig fmt: Automagically fix block-less suspend exprs 2021-04-24 15:37:55 +02:00
LemonBoy
0aede1a8fc stage1: Require a block after suspend
Closes #8603
2021-04-24 10:25:43 +02:00
Al Hoang
762d4a959c update haiku system constants 2021-04-23 23:40:42 -05:00
Al Hoang
914d57a1a6 support output collection for haiku 2021-04-23 23:39:13 -05:00
Andrew Kelley
a279f18bce
Merge pull request #8599 from LemonBoy/unsigned-neg
stage1: Allow wrapping negation on unsigned ints at comptime
2021-04-23 16:59:01 -04:00
Hadron67
e86a1df9f2 std.atomic: load should take const pointer to Self 2021-04-23 22:39:49 +02:00
LemonBoy
9ac5f98200 std: Remove unneeded workaround
Now that -% works on unsigned integers at comptime this (clever) hack is
not not needed anymore.
2021-04-23 19:19:44 +02:00
Andrew Kelley
0262dda9b8 std: remove comptime const 2021-04-22 23:52:52 -07:00
jacob gw
ce41ddcd23 std: fix potential bug in parseInt 2021-04-22 22:42:46 -04:00
Andrew Kelley
93d1c2d6d4 std: fix compile errors caught by stage2 AstGen
Follow-up from 507a8096d2
2021-04-22 19:32:57 -07:00
Andrew Kelley
8dd7378013 delete packed enums from the language
No need for any such thing. Instead, provide an integer tag type for the
enum.
2021-04-22 19:21:50 -07:00
Andrew Kelley
507a8096d2 std: fix compile errors caught by stage2 AstGen
* `comptime const` is redundant
 * don't use `extern enum`; specify a tag type.
   `extern enum` is only when you need tags to alias. But aliasing tags
   is a smell. I will be making a proposal shortly to remove `extern enum`
   from the language.
 * there is no such thing as `packed enum`.
 * instead of `catch |_|`, omit the capture entirely.
 * unused function definition with missing parameter name
 * using `try` outside of a function or test
2021-04-22 18:07:46 -07:00
LemonBoy
c5cc6b7082 compiler-rt: Export __extendhftf2 and __trunctfhf2
Even though LLVM12 doesn't make use of those intrinsics at the moment
let's export them anyway.
2021-04-21 19:02:13 +02:00
LemonBoy
e0d7cfce5f compiler-rt: Don't re-define PPC builtins in test mode
Prevent linking errors when `zig test`-ing the compiler_rt module for
powerpc-linux triples.
2021-04-21 19:00:57 +02:00
LemonBoy
e4f9a3041a std: Use stat definition with 32bit *time fields
We're not ready for Y38K yet.
2021-04-21 16:31:30 +02:00
LemonBoy
d82eb8dd40 std: Split syscall parameters for PowerPC targets 2021-04-21 16:31:29 +02:00
Jakub Konka
c8753aceef macho: fix typos in consts defs 2021-04-21 06:49:34 +02:00
Andrew Kelley
a008fb0a71 std.fs: delete unused label
stage2 starting to catch problems with the standard library :)
2021-04-20 17:57:35 -07:00
Andrew Kelley
30c9808391 AstGen: implement anytype parameters 2021-04-20 17:38:06 -07:00