14583 Commits

Author SHA1 Message Date
Jacob G-W
166dffb088 plan9 linker: correct runtime vs file offset converting code 2021-07-08 14:10:50 -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 G-W
3e59c15025 plan9 linker: do relocations 2021-07-08 14:10:49 -07:00
Jacob G-W
c114474190 plan9 linker: write symbol table
Also switch to iovecs because gotta go fast.
2021-07-08 14:10:49 -07:00
Jacob G-W
798162e509 plan9 linker: make runnable binaries
We can now run binaries! (they segfault, but still run!)
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
g-w1
1f0b77b3b8
stage2 type.zig: implement eql of error unions (#9334) 2021-07-08 14:35:43 -04:00
Mr. Paul
a201d80253 Introduce Zig Test earlier in Language Reference
The "Zig Test" section of the language reference has been moved between the
current "Hello World" section and the "Comments" section. This was done to
introduce the Zig test syntax before it is used in later sections.

The description of the Zig test feature has NOT been updated in this commit.

Closes #5837
2021-07-08 14:33:53 -04:00
Jacob G-W
ec36ac8b21 stage2 astgen: provide 3 more errors for invalid inline assembly 2021-07-08 14:33:01 -04:00
Martin Wickham
e2b954c273 Add support for NO_COLOR 2021-07-08 14:30:45 -04:00
Andrew Kelley
7bdeda82ae
Merge pull request #8494 from mattnite/cbe-wrapping-addition
Wrapping add/sub for the C backend
2021-07-08 14:26:20 -04:00
Andrew Kelley
9dbe684854 C backend: cleanups to wrapping int operations
* less branching by passing parameters in the main op code switch.
 * properly pass the target when asking the type system for int info.
 * handle u8, i16, etc when it is represented using
   int_unsigned/int_signed tag.
 * compile error instead of assertion failure for unimplemented cases
   (greater than 64 bits integer).
 * control flow cleanups
 * zig.h: expand macros into inline functions
 * reduce the complexity of the test case by making it one test case
   that calls multiple functions. Also fix the problem of c_int max
   value mismatch between host and target.
2021-07-08 11:21:06 -07:00
Matt Knight
fb16633ecb C backend: add/sub/mul wrapping for the C backend 2021-07-08 09:56:40 -07: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
yetanothercheer
7935e83b1d Fix indentation in langref.html.in 2021-07-08 00:05:29 -04:00
Andrew Kelley
c2e66d9bab stage2: basic inferred error set support
* Inferred error sets are stored in the return Type of the function,
   owned by the Module.Fn. So it cleans up that memory in deinit().
 * Sema: update the inferred error set in zirRetErrValue
   - Update relevant code in wrapErrorUnion
 * C backend: improve some some instructions to take advantage of
   liveness analysis to avoid being emitted when unused.
 * C backend: when an error union has a payload type with no runtime
   bits, emit the error union as the same type as the error set.
2021-07-07 20:47:21 -07:00
Andrew Kelley
5c8bd443d9 stage2: fix if expressions on error unions
AstGen had the then-else logic backwards for if expressions
on error unions. This commit fixes it.

Turns out AstGen only really needs `is_non_null` and `is_non_err`,
and does not need the `is_null` or `is_err` variants. So I removed the
`is_null{,_ptr}` and `is_err{,_ptr}` ZIR instructions (-4) and
added `is_non_err`, `is_non_err_ptr` ZIR instructions (+2) for
a total of (-2) ZIR instructions, giving us a tiny bit more headroom
within the 256 tag limit. This required swapping the order of
then/else blocks in a handful of cases, but ultimately means the
ZIR will be in the same as source order, which is convenient
when debugging.

AIR code on the other hand, gains the `is_non_err` and `is_non_err_ptr`
instructions.

Sema: fix logic in zirErrUnionCode and zirErrUnionCodePtr returning the
wrong result type.
2021-07-07 19:50:56 -07: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
Andrew Kelley
5816997ae7 stage2: get tests passing
* implement enough of ret_err_value to pass wasm tests
 * only do the proper `@panic` implementation for the backends which
   support it, which is currently only the C backend. The other backends
   will see `@breakpoint(); unreachable;` same as before.
   - I plan to do AIR memory layout reworking as a prerequisite to
     fixing other backends, because that will help me put all the
     constants up front, which will allow the codegen to lower to memory
     without jumps.
 * `@panic` is implemented using anon decls for the message. Makes it
   easier on the backends. Might want to look into re-using decls for
   this in the future.
 * implement DWARF .debug_info for pointer-like optionals.
2021-07-07 14:17: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
13f04e3012 stage2: implement @panic and beginnigs of inferred error sets
* ZIR: add two instructions:
   - ret_err_value_code
   - ret_err_value
 * AstGen: add countDefers and utilize it to emit more efficient ZIR for
   return expressions in the presence of defers.
 * AstGen: implement |err| payloads for `errdefer` syntax.
   - There is not an "unused capture" error for it yet.
 * AstGen: `return error.Foo` syntax gets a hot path in return
   expressions, using the new ZIR instructions. This also is part of
   implementing inferred error sets, since we need to tell Sema to add
   an error value to the inferred error set before it gets coerced.
 * Sema: implement `@setCold`.
   - Implement `@setCold` support for C backend.
 * `@panic` and regular safety panics such as `unreachable` now properly
   invoke `std.builtin.panic`.
 * C backend: improve pointer and function value rendering.
 * C linker: fix redundant typedefs.
 * Add Type.error_set_inferred.
 * Fix Value.format for enum_literal, enum_field_index, bytes.
 * Remove the C backend test that checks for identical text

I measured a 14% reduction in Total ZIR Bytes from master branch
for std/os.zig.
2021-07-07 00:39:23 -07: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
Jacob G-W
23f414b927 stage1 parser: update comments to match impl 2021-07-07 07:38:26 +03:00
Andrew Kelley
6ba843ee0f
Merge pull request #9310 from ziglang/stage1-better-hashing
Speed up stage 1 by improving hash functions
2021-07-06 13:20:15 -04:00
leesongun
cff7ecee07
Fix unexpected truncation behavior with comptime_int larger than u64 range (#9303)
Closes #9299
2021-07-06 12:42:18 +03:00
Martin Wickham
f02ee7a9f5 Avoid some large copies for another second of time saved 2021-07-06 00:57:46 -05:00
Jacob G-W
6c11e9bb07 stage2: add error note for comparing booleans with '||' 2021-07-06 07:51:30 +03:00
Jacob G-W
d089b3df7a remove really weird debugging statement from stage1 2021-07-05 21:13:10 -04:00
Martin Wickham
149ecdfe1b Remove debug checks, audit field accesses 2021-07-05 19:41:48 -05:00
Andrew Kelley
b3225a755a stage1: avoid incorrectly reading ZigValue data
Hashing, equality checking, and expanding lazy values were not
inspecting the is_comptime field of structs, causing incorrect behavior
for tuples. When looking at a comptime value of a struct, if the
is_comptime field is true, the value must be learned from the type
rather than the value.
2021-07-05 16:22:40 -07:00
Evan Haas
b5659e0233 translate-c: Don't discard variables unless necessary
Closes #9205
2021-07-05 17:51:53 -04:00
Andrew Kelley
0ff9a4d21c stage1: resolve lazy values before comptime fn call 2021-07-05 14:07:36 -07:00
Martin Wickham
0e5fa87ac9 Better hashing, new asserts failing 2021-07-05 15:28:13 -05:00
Andrew Kelley
9b08687766 stage1: recursively resolve lazy values before hashing
When putting ZigValues into a hash map. The hash of a lazy value
and a fully resolved value must equal, and so we must resolve
the lazy values prior. The hash function asserts that none of
the values are lazy.
2021-07-05 13:05:03 -07:00
Andrew Kelley
b7da1b2d45
Merge pull request #9175 from kprotty/thread
std.Thread enhancements
2021-07-04 22:31:02 -04:00
Nulo
5d0dad9acd Link to the GPA now that it's on upstream 2021-07-04 15:44:29 -04:00
leesongun
da2ca447c8
implement xoshiro256++ (#9298)
Implement xoshiro256++
2021-07-04 16:15:23 +02:00
Nulo
8a863381d1 CODE_OF_CONDUCT: change Freenode to Libera.chat 2021-07-03 20:28:17 -04:00
Andrew Kelley
254a35fd88 stage2: add the zig version to AstGen cache hash
This solves the problem of different versions of Zig having different
binary representations of ZIR code.

closes #9290
2021-07-03 11:47:58 -07:00
kprotty
c8f90a7e7e zig fmt 2021-07-03 11:49:07 -05:00
Takeshi Yoneda
5c34c01179 WASI: include exec-model in cache state.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-03 11:57:44 +03:00
Andrew Kelley
af20fdbce7 stage1: eliminate the IrInst base struct
This commit intentions to have no functional changes. The only purpose
is to delete the struct IrInst, which is the common base struct that
both IrInstSrc (ZIR) and IrInstGen (AIR) instructions embed.

This untangles stage1 ZIR and AIR memory layout, paving the way for a
following commit to reduce memory usage.
2021-07-03 03:14:54 -04:00
Andrew Kelley
bb98620c10
Merge pull request #9219 from ziglang/unreachable-code
move "unreachable code" error from stage1 to stage2
2021-07-02 21:11:45 -04:00
Andrew Kelley
a6bf68ccf9 langref: fix test cases now that AST Lowering has priority 2021-07-02 16:22:09 -07: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