4238 Commits

Author SHA1 Message Date
Andrew Kelley
d17f492017 stage2: miscellaneous fixes for the branch
* Breaking language change: inline assembly must use string literal
   syntax. This is in preparation for inline assembly improvements that
   involve more integration with the Zig language. This means we cannot
   rely on text substitution.
 * Liveness: properly handle inline assembly and function calls with
   more than 3 operands.
   - More than 35 operands is not yet supported. This is a low priority
     to implement.
   - This required implementation in codegen.zig as well.
 * Liveness: fix bug causing incorrect tomb bits.
 * Sema: enable switch expressions that are evaluated at compile-time.
   - Runtime switch instructions still need to be reworked in this
     branch. There was a TODO left here (by me) with a suggestion to do
     some bigger changes as part of the AIR memory reworking. Now that
     time has come and I plan to honor the suggestion in a future commit
     before merging this branch.
 * AIR printing: fix missing ')' on alive instructions.

We're back to "hello world" working for the x86_64 backend.
2021-07-20 12:19:16 -07:00
charlieman
bfe2005167
std: remove dead code in std.os.read 2021-07-20 10:22:06 +02:00
Evan Haas
3e67ef5c9f translate-c: Handle underscore when used as an identifier
Use `@` syntax to escape `_` when used as an identifier.

Remove the stage1 astgen prohibition against assigning from `_`

Note: there a few stage1 bugs preventing `_` from being used as an identifier
for a local variable or function parameter; these will be fixed by stage2.
They are unlikely to arise in real C code since identifiers starting with
underscore are reserved for the implementation.
2021-07-19 12:56:23 +03:00
Tizoner
c905056562 fix style warning in json.zig 2021-07-19 12:55:05 +03:00
Adam C
95e5fac412
FIX typo in doc comment for std.math.hypot (#9413) 2021-07-18 23:53:06 +02:00
Jonathan Marler
08e5daa7d5 Add std.unicode.fmtUtf16le 2021-07-15 20:37:16 +03:00
g-w1
ee173d5127
parser: require block in suspend expression 2021-07-15 10:55:22 +03:00
Ryan Liptak
4ea7470417 Add inotify_rm_watch definition to c/linux.zig
Also make inotify_add_watch's pathname marked as nul-terminated
2021-07-15 10:54:05 +03:00
Ryan Liptak
a84402d796 Add NotDir as possible error for os.inotify_add_watch
Possible when "mask contains IN_ONLYDIR and pathname is not a directory."
2021-07-15 10:51:25 +03:00
Isaac Freund
03156e5899 std/hash_map: fix ensureUnusedCapacity() over-allocating
Currently this function adds the desired unused capactiy to the current
total capacity instead of the current used capactiy.
2021-07-12 11:31:36 -07:00
Kenta Iwasaki
aa2a31612f io_uring: add sqe prep methods for epoll_ctl, poll_add, and poll_remove
Implement io_uring submission queue entry preparation methods for
epoll_ctl, poll_add and poll_remove.

Poll masks are designated as 32-bit little-endian integers as
specified in liburing's definitions.

Updated io_uring_prep_rw to take in an unsigned 64-bit address instead
of an anytype. io_uring_sqe by default assumes that the address
specified in a submission queue entry is an unsigned 64-bit integer.
2021-07-11 09:15:54 +00:00
Jacob G-W
968d1ecf17 stage2 plan9: add aarch64 support 2021-07-11 01:58:26 -04:00
Malcolm Still
a3703745eb
Add waitid syscall on linux (#9335) 2021-07-10 16:56:41 -04:00
Andrew Kelley
7b8a968f14
Merge pull request #9105 from g-w1/plan9
stage2: bringup plan9 target and linker
2021-07-08 17:30:28 -04:00
Andrew Kelley
476faef97a plan9 cleanups
* rename files to adhere to conventions
 * remove unnecessary function / optionality
 * fix merge conflict
 * better panic message
 * remove unnecessary TODO comment
 * proper namespacing of declarations
 * clean up documentation comments
 * no copyright header needed for a brand new zig file that is not
   copied from anywhere
2021-07-08 14:24:16 -07:00
Frank Denis
b4b90af4e0
Switch rand.DefaultPrng to Xoshiro256++ (#9301)
Xoroshiro128+ is the current default non-cryptographic random
number generator.

This algorithm was designed to generate floating-point numbers, by
only using the top 53 bits. Lower bits have a significant bias, that
contradicts the documented properties for `rand.DefaultPrng`. This
also has implications on everything using `Random.fill()`, including
the way we generate random floating-point numbers.

In addition, Xoroshiro128+ has known issues. See for example:
- https://lemire.me/blog/2017/08/22/cracking-random-number-generators-xoroshiro128/
- https://www.pcg-random.org/posts/xoroshiro-fails-truncated.html

Xoshiro256++ addresses these issues, while remaining very fast.
2021-07-08 23:19:49 +02:00
Jacob G-W
1c2facaf6b stage2: include enough inline asm support for more plan9 syscalls
Also make the exit more correct by exiting 0 rather than random
stuff on the stack.
2021-07-08 14:12:08 -07:00
Jacob G-W
f1aadfa77b plan9 linker: remove panics and improve 64 bit support
Don't @intCast when we do not need to, and change
some panics to unreachable when they can never happen.
2021-07-08 14:12:08 -07:00
Jacob G-W
72bb6bb143 plan9 linker: produce an object file that can actually work!!! 2021-07-08 14:10:49 -07:00
jacob gw
34c21affa2 initial plan9 boilerplate
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-08 14:10:49 -07:00
Martin Wickham
e2b954c273 Add support for NO_COLOR 2021-07-08 14:30:45 -04:00
Andrew Kelley
62d27fcfb6
Merge pull request #9325 from ziglang/stage2-inferred-error-sets
Stage2 inferred error sets and `@panic`
2021-07-08 02:04:53 -04:00
Andrew Kelley
ec63411905 Revert "Skip over CRs at the end of multiline literals"
This reverts commit 9de452f9a69d5590743a194bc2d0817d26d66a0b.

No CRs allowed in multiline string literals - this is intentional.
2021-07-07 18:00:04 -07:00
Daniele Cocca
9de452f9a6 Skip over CRs at the end of multiline literals
Fixes #9257.
This is needed when tokenizing input containing DOS line endings, i.e.
the CRLF sequence.
2021-07-07 20:03:19 +03:00
Andrew Kelley
d481acc7db std.builtin.panic: simpler default panic for stage2
until it catches up to stage1 in terms of supported language features
2021-07-07 00:38:46 -07:00
Andrew Kelley
298a65ff4b std.HashMap: add ensureUnusedCapacity and ensureTotalCapacity
and deprecated ensureCapacity. This matches the pattern set by ArrayList
and ArrayHashMap already.
2021-07-07 00:38:10 -07:00
Carlos Zúñiga
b936bbd2f1 Fixed builtin.Target -> std.Target 2021-07-07 07:54:38 +03:00
Andrew Kelley
b7da1b2d45
Merge pull request #9175 from kprotty/thread
std.Thread enhancements
2021-07-04 22:31:02 -04:00
leesongun
da2ca447c8
implement xoshiro256++ (#9298)
Implement xoshiro256++
2021-07-04 16:15:23 +02:00
kprotty
c8f90a7e7e zig fmt 2021-07-03 11:49:07 -05:00
Andrew Kelley
d979dd9b58 stage2: improve AstGen FileNotFound error message
Partially addresses #9203. It fixes the first case, but not the second
one mentioned in the issue.
2021-07-02 15:27:00 -07:00
Andrew Kelley
5103053977 compile errors test harness: support unknown file/line/column
This gets us 2 more passing compile error test cases.
2021-07-02 13:28:31 -07:00
Andrew Kelley
c5c23db627 tokenizer: clean up invalid token error
It now displays the byte with proper printability handling. This makes
the relevant compile error test case no longer a regression in quality
from stage1 to stage2.
2021-07-02 13:28:31 -07:00
Andrew Kelley
7a2e0d9810 AstGen: cleanups to pass more compile error test cases 2021-07-02 13:28:29 -07:00
Andrew Kelley
41336acb0b AstGen: detect redeclaration of function parameters
Also improve redeclaration error message to include the category of
variable.
2021-07-02 13:27:35 -07:00
Andrew Kelley
24c432608f stage2: improve compile errors from tokenizer
In order to not regress the quality of compile errors, some improvements
had to be made.

 * std.zig.parseCharLiteral is improved to return more detailed parse
   failure information.
 * tokenizer is improved to handle null bytes in the middle of strings,
   character literals, and line comments.
 * validating how many unicode escape digits in string literals is moved
   to std.zig.parseStringLiteral rather than handled in the tokenizer.
 * when a tokenizer error occurs, if the reported token is the 'invalid'
   tag, an error note is added to point to the invalid byte location.
   Further improvements would be:
   - Mention the expected set of allowed bytes at this location.
   - Display the invalid byte (if printable, print it, otherwise
     escape-print it).
2021-07-02 13:27:35 -07:00
Andrew Kelley
3f680abbe2 stage2: tokenizer: require null terminated source
By requiring the source file to be null-terminated, we avoid extra
branching while simplifying the logic at the same time.

Running ast-check on a large zig source file (udivmodti4_test.zig),
master branch compared to this commit:
 * 4% faster wall clock
 * 7% fewer cache misses
 * 1% fewer branches
2021-07-02 13:27:35 -07:00
Andrew Kelley
8ce880ca75 avoid calling into stage1 backend when AstGen fails
The motivation for this commit is that there exists source files which
produce ast-check errors, but crash stage1 or otherwise trigger stage1
bugs. Previously to this commit, Zig would run AstGen, collect the
compile errors, run stage1, report stage1 compile errors and exit if
any, and then report AstGen compile errors.

The main change in this commit is to report AstGen errors prior to
invoking stage1, and in fact if any AstGen errors occur, do not invoke
stage1 at all.

This caused most of the compile error tests to fail due to things such
as unused local variables and mismatched stage1/stage2 error messages.
It was taking a long time to update the test cases one-by-one, so I
took this opportunity to unify the stage1 and stage2 testing harness,
specifically with regards to compile errors. In this way we can start
keeping track of which tests pass for 1, 2, or both.
`zig build test-compile-errors` no longer works; it is now integrated
into `zig build test-stage2`.

This is one step closer to executing compile error tests in parallel; in
fact the ThreadPool object is already in scope.

There are some cases where the stage1 compile errors were actually
better; those are left failing in this commit, to be addressed in a
follow-up commit.

Other changes in this commit:

 * build.zig: improve support for -Dstage1 used with the test step.
 * AstGen: minor cosmetic changes to error messages.
 * stage2: add -fstage1 and -fno-stage1 flags. This now allows one to
   download a binary of the zig compiler and use the llvm backend of
   self-hosted. This was also needed for hooking up the test harness.
   However, I realized that stage1 calls exit() and also has memory
   leaks, so had to complicate the test harness by not using this flag
   after all and instead invoking as a child process.
   - These CLI flags will disappear once we start shipping the
     self-hosted compiler as the main compiler. Until then, they can be
     used to try out the work-in-progress stage2.
 * stage2: select the LLVM backend by default for release modes, as long
   as the target architecture is supported by LLVM.
 * test harness: support setting the optimize mode
2021-07-02 13:27:28 -07:00
Andrew Kelley
125b85d737 move "unreachable code" error from stage1 to stage2
* AstGen: implement "unreachable code" error for blocks. This works at
   the statement level.
 * stage1: remove the "unreachable code" error implementation, which
   means removing the `is_gen` field from IrInstSrc. This is one small
   step towards a smaller memory footprint for stage1. The benefits
   won't be realized until a future commit because this flag took
   advantage of padding.

There may be a regression here with "union has no associated enum"
error, and there is a regression with the following code:

```zig
const a = noreturn;
```

A future commit will address these regressions.
2021-07-02 13:26:50 -07:00
kprotty
483eb8e057 std.Thread: move linux detach code to inline asm 2021-07-01 17:34:23 -05:00
LemonBoy
1fc877fd94 std: Catch and handle overflow in json parser
When a floating-point value with no fractional part is shoved into an
integer type we must check whether it fits or not before calling
`@floatToInt` as the builtin panics in case of overflow.

Catch the error and bubble it up to the caller.
2021-07-01 22:35:19 +03:00
kprotty
98106b09d5 zig fmt 2021-06-30 21:49:38 -05:00
kprotty
2309c81a78 std.Thread: non-zero child_tid to avoid racy join() 2021-06-30 21:49:00 -05:00
kprotty
2a6ba41020 std.Thread: add CLONE_CHILD_SETTID to fix join() 2021-06-30 21:49:00 -05:00
kprotty
6dd6604638 std.Thread: fix tls 9386 linux typo 2021-06-30 21:49:00 -05:00
kprotty
f0fa129e9b std.Thread: more cleanup & testing 2021-06-30 21:49:00 -05:00
kprotty
7b323f84ca std.Thread: more fixes 2021-06-30 21:49:00 -05:00
kprotty
c6fb968a3d std.Thread: fix posix 2021-06-30 21:49:00 -05:00
kprotty
fd4a607bb2 std.Thread: fix futex test + thread errors 2021-06-30 21:49:00 -05:00
kprotty
18bcb2e990 std.Thread: fix futex thread spawning 2021-06-30 21:49:00 -05:00