4508 Commits

Author SHA1 Message Date
Isaac Freund
f7b090d707 std.log: simplify to 4 distinct log levels
Over the last year of using std.log in practice, it has become clear to
me that having the current 8 distinct log levels does more harm than
good. It is too subjective which level a given message should have which
makes filtering based on log level weaker as not all messages will have
been assigned the log level one might expect.

Instead, more granular filtering should be achieved by leveraging the
logging scope feature. Filtering based on a combination of scope and log
level should be sufficiently powerful for all use-cases.

Note that the self hosted compiler has already limited itself to 4
distinct log levels for many months and implemented granular filtering
based on both log scope and level. This has worked very well in practice
while working on the self hosted compiler.
2021-10-24 15:04:29 -04:00
LemonBoy
2a733051bb libc: Export truncl
With the usual caveat of it being wrong for targets where c_longdouble
is not f128.
2021-10-24 19:17:55 +02:00
Andrew Kelley
94879506ea
Merge pull request #10017 from Snektron/big-int-div
Big ints: division fixes
2021-10-23 22:49:33 -04:00
LemonBoy
1690b35770 std: Fix edge case in TLS tp calculation
The TLS area may be located in the upper part of the address space and,
if the platform expects a constant offset to be applied, may make the tp
register calculation overflow.

Use +% instead of +, the overflow is harmless.
2021-10-23 22:48:25 -04:00
Robin Voetter
c563521d44 big ints: tighten some more division memory requirements 2021-10-24 02:56:48 +02:00
Robin Voetter
83bdbb2abb big ints: Make calcLimbLen always work at comptime, even if parameter is runtime 2021-10-24 02:56:48 +02:00
Robin Voetter
c905ceb23c big ints: fix divFloor 2021-10-24 02:56:48 +02:00
Robin Voetter
87b7b31557 big ints: improve division 2021-10-24 01:21:33 +02:00
Andrew Kelley
069c83d58c stage2: change @bitCast to always be by-value
After a discussion about language specs, this seems like the best way to
go, because it's simpler to reason about both for humans and compilers.

The `bitcast_result_ptr` ZIR instruction is no longer needed.

This commit also implements writing enums, arrays, and vectors to
virtual memory at compile-time.

This unlocked some more of compiler-rt being able to build, which
in turn unlocks saturating arithmetic behavior tests.

There was also a memory leak in the comptime closure system which is now
fixed.
2021-10-22 15:35:35 -07:00
Andrew Kelley
86b9280963 zig libc: export floorl and ceill
needed since self-hosted now contains calls to `@divFloor` and
`@divTrunc` for 128-bit floats.
2021-10-22 10:48:45 -07:00
Andrew Kelley
7f70c27e9d stage2: more division support
AIR:
 * div is renamed to div_trunc.
 * Add div_float, div_floor, div_exact.
   - Implemented in Sema and LLVM codegen. C backend has a stub.

Improvements to std.math.big.Int:
 * Add `eqZero` function to `Mutable`.
 * Fix incorrect results for `divFloor`.

Compiler-rt:
 * Add muloti4 to the stage2 section.
2021-10-21 19:05:26 -07:00
Robin Voetter
a3c9bfef30 stage2: truncation
* Also fixes a related case where big int truncate would assume that the
input fits in the output limbs buffer
2021-10-21 20:10:27 -04:00
Jonathan Marler
e2a2e6c14f InstallRawStep: handle empty segments
This fixes InstallRawStep to handle the cases when there are empty segments (segments with no sections).  Before this change, if there was an empty segment with no sections, then the fixup of binaryOffsets is skipped.  This fixes that by looping through each segment until a non-empty one is found and then fixing up the sections. This fixed an issue I was having with InstallRawStep for a bootloader I'm writing.
2021-10-21 17:03:44 -04:00
Jonathan Marler
da2b615efb distinguish between unexpected child process exit code and unclean exit
This modifies the error for an unexpected exit code from the ChildProcess of RunStep to be UnexpectedExitCode rather than UncleanExit.  This allows the handler of the error to distinguish between an error reported by the ChildProcess, and an error executing the ChildProcess, which is an important dinstinction when it comes to know what information to report to the user.  For example, if you have a ChildProcess that you know reports its own errors, an unexpected exit code would mean the error is already reported, but an unclean exit would mean that child process was not able to report any error.
2021-10-21 17:03:00 -04:00
Andrew Kelley
361217bda2 stage2: fix inline assembly with expression output
Thanks @g-w1 for the print_air.zig implementation for inline assembly. I
copied it and slightly modified it from your open pull request.
2021-10-20 15:34:10 -07:00
Andrew Kelley
ad17108bdd
Merge pull request #9960 from Snektron/bit-not
Some not and vector stuff
2021-10-17 21:59:10 -04:00
Max Hollmann
53b87fa78a Move compareFn from init to type constructor in PriorityQueue and PriorityDequeue.
This change significantly improves performance for simple compare functions and modifies
the API to be more consistent with e.g. `HashMap`.
2021-10-17 17:47:43 -04:00
Jonathan Marler
22beaf5afc actually fix child process deadlock on windows
Looks like I forgot to remove windows from this workaround condition when I finished implementing the child process output collection on windows.
2021-10-17 16:07:51 -04:00
LemonBoy
51be575745 std: Fix endless loop in fmt impl
Apparently there's a stage1 bug that may sometimes lead to an endless
loop being generated when unrolling the fmt impl.

Closes #9961
2021-10-17 16:06:40 -04:00
Robin Voetter
6a3659c4e0 big.int: 2s-complement binary wrapping not 2021-10-17 20:33:04 +02:00
Stephen Gregoratto
98a37dfb23 Linux: Update syscall numbers for 5.14 2021-10-17 14:22:47 -04:00
Robin Voetter
1e09157b53 big ints: Fix set(signed int minimum) panic 2021-10-16 11:32:05 +02:00
Robin Voetter
efa4f76c8b big ints: Saturating left shift + tests 2021-10-16 11:32:05 +02:00
Andrew Kelley
0536c25578 std.os: another workaround for stage1 @minimum behavior
This is a companion commit to 0915d24e6b34b67d358c1309e9bc8516416f1008.
2021-10-15 14:43:57 -07:00
Andrew Kelley
0915d24e6b std.os: add workarounds for stage1 @minimum implementation 2021-10-15 11:46:47 -07:00
Miles Alan
411e9ca4ad
Fix bug where std.math.asinh64 doesn't respect signedness for negative values (#9940)
* std: Correct math.asinh64 to return correct signedness for negative values

* std: Add tests for negative values for math.asinh32 and math.asinh64
2021-10-15 13:55:40 -04:00
Sizhe Zhao
f3ab092f67
std.os.windows: Fix typo (#9951) 2021-10-15 14:44:05 +02:00
Andrew Kelley
55eea3b045 stage2: implement @minimum and @maximum, including vectors
* std.os: take advantage of `@minimum`. It's probably time to
   deprecate `std.min` and `std.max`.
 * New AIR instructions: min and max
 * Introduce SIMD vector support to stage2
 * Add `@Type` support for vectors
 * Sema: add `checkSimdBinOp` which can be re-used for other arithmatic
   operators that want to support vectors.
 * Implement coercion from vectors to arrays.
   - In backends this is handled with bitcast for vector to array,
     however maybe we want to reduce the amount of branching by
     introducing an explicit AIR instruction for it in the future.
 * LLVM backend: implement lowering vector types
 * Sema: Implement `slice.ptr` at comptime
 * Value: improve `numberMin` and `numberMax` to support floats in
   addition to integers, and make them behave properly in the presence
   of NaN.
2021-10-14 21:17:30 -07:00
Andrew Kelley
b0f80ef0d5 stage2: remove use of builtin.stage2_arch workaround
The LLVM backend no longer needs this hack! However, the other backends
still do. So there are still some traces of this workaround in use for now.
2021-10-13 18:43:43 -07:00
Sizhe Zhao
a5ecffa461 rand: remove workaround for issue #1770 2021-10-10 16:25:12 +00:00
Lee Cannon
8e1aa72c69
add test step to build.zig generated by init-exe (#9919)
* added simple test

* Update lib/std/special/init-exe/build.zig

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-10-09 00:17:49 -07:00
tgschultz
526191bfaf Better documentation, use of len field instead of function, @bitSizeOf instead of meta.bitCout 2021-10-09 03:15:34 -04:00
Andrew Kelley
9ed599b4e3 stage2: LLVM backend: miscompilation fixes
* work around a stage1 miscompilation leading to the wrong integer
   comparison predicate being emitted.
 * fix the bug of not annotating callsites with the calling convention
   of the callee, leading to undefined behavior.
 * add the `nobuiltin` attribute when building freestanding libc or
   compiler_rt libraries to prevent e.g. memcpy from being "optimized"
   into a call to itself.
 * compiler-rt: change a call to be comptime to make the generated LLVM
   IR simpler and easier to study.

I still can't enable the widening tests due to the compiler-rt compare
function being miscompiled in some not-yet-diagnosed way.
2021-10-05 20:36:04 -07:00
Andrew Kelley
01ad6c0b02 freestanding libc: don't rely on compiler_rt symbols we don't have yet
Previous commit made fmal depend on __extendxftf2 and __trunctfxf2 but
we don't have implementations of those yet.
2021-10-05 18:19:31 -07:00
Andrew Kelley
5518a0aff2 freestanding libc: export fmal
libc requires this to use `long double` which is sometimes the same as
f128, sometimes not.

Also for an unknown reason, aarch64 is getting an invalid result for the
`@mulAdd` behavior test for f128. See #9900.
2021-10-05 16:56:46 -07:00
Andrew Kelley
4ee91bb8a8 stage1: work around LLVM's buggy fma lowering
* move fmaq from freestanding libc to compiler_rt, unconditionally
   exported weak_odr.
 * stage1: add fmaf, fmal, fmaq as symbols that compiler-rt might
   generate calls to.
 * stage1: lower `@mulAdd` directly to a call to `fmaq` instead of to
   the LLVM intrinsic because LLVM will lower it to `fmal` even when the
   target's `long double` is not equivalent to `f128`.

This commit is intended to fix the test suite which is failing on the
previous commit.
2021-10-05 14:22:38 -07:00
Andrew Kelley
2fe7b06f3d add support for f128 @mulAdd
std: add f128 implementations of fma, frexp, and ilogb. Expose `fmal` in
zig's freestanding libc. This makes `@mulAdd` work correctly for f128.

Fixes a CI regression from yesterday, where I added a usage of f128
`@mulAdd` into the self-hosted compiler.
2021-10-05 12:32:26 -07:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
78902db68b stage2: fix comptime @bitCast
Before, Sema for comptime `@bitCast` would return the same Value but
change the Type. This gave invalid results because, for example, an
integer Value when the Type is a float would be interpreted numerically,
but `@bitCast` needs it to reinterpret how they would be stored in
memory.

This requires a mechanism to serialize a Value to a byte buffer and
deserialize a Value from a byte buffer.

Not done yet, but needs to happen: comptime dereferencing a pointer
to a Decl needs to perform a comptime bitcast on the loaded value.
Currently the value is silently wrong in the same way that `@bitCast`
was silently wrong before this commit.

The logic in Value for handling readFromMemory for large integers is
only correct for small integers. It needs to be fleshed out for proper
big integers.

As part of this change:
 * std.math.big.Int: initial implementations of readTwosComplement and
   writeTwosComplement. They only support bit_count <= 128 so far and
   panic otherwise.
 * compiler-rt: move the compareXf2 exports over to the stage2 section.
   Even with the improvements in this commit, I'm still seeing test
   failures in the widening behavior tests; more investigation is
   needed.
2021-10-04 23:30:04 -07:00
Sreehari Sreedev
598db831f3 FileProtocol: add Reader, Writer, SeekableStream 2021-10-04 22:29:53 -04:00
Andrew Kelley
d4ebfa8763
Merge pull request #9880 from squeek502/deflate-construct-errors
deflate: Better Huffman.construct errors and error handling
2021-10-04 15:31:08 -04:00
Matthew Borkowski
66204b7806 deflate.zig: check for distances past beginning of output stream 2021-10-04 15:30:37 -04:00
alichraghi
5125788e33 add phi constant 2021-10-04 15:27:25 -04:00
Robin Voetter
95fe86e3db big ints: Fix tests for 32-bit architectures 2021-10-04 11:25:29 +02:00
Robin Voetter
a1e02f33ad fmt 2021-10-04 11:25:29 +02:00
Robin Voetter
3dc47b8161 Apply new big int wrap/saturate to Value.zig 2021-10-04 11:25:29 +02:00
Robin Voetter
a62ce87f1f big ints: mulWrap tests 2021-10-04 11:25:29 +02:00
Robin Voetter
b352564b36 big ints: Some extra comments 2021-10-04 11:25:29 +02:00
Robin Voetter
ebcdfebaa6 big ints: saturate() tests 2021-10-04 11:25:29 +02:00
Robin Voetter
bbd50248f2 big ints: saturate() function 2021-10-04 11:25:29 +02:00