22608 Commits

Author SHA1 Message Date
Andrew Kelley
ec4cd87ed7 add test coverage for fixed bug. closes #5518 2023-02-19 21:18:27 -07:00
Andrew Kelley
e778e47140 add test coverage for fixed bug. closes #5516 2023-02-19 21:18:27 -07:00
Andrew Kelley
680d79ebf9 add test coverage for fixed bug. closes #5508 2023-02-19 21:18:27 -07:00
Andrew Kelley
ffdce5f98c add test coverage for fixed bug. closes #5497 2023-02-19 21:18:27 -07:00
Andrew Kelley
53104b9165 add test coverage for fixed bug. closes #5410 2023-02-19 21:18:27 -07:00
Jan Philipp Hafer
476bdc8b0b compiler_rt: restructure compiler_rt.zig according to README.md
Justifications
- compiler_rt base routines are almost finished, so make 1:1
mapping of code and documentation.
- Make adjustments to code + documentation simpler to prevent technical or
  documentation debt.
2023-02-19 14:00:55 -05:00
Andrew Kelley
adfc019d60
Merge pull request #11982 from marler8997/ignoreSigpipe
ignore SIGPIPE by default
2023-02-19 13:55:12 -05:00
Veikka Tuominen
f10950526e implement writeToMemory/readFromMemory for pointers 2023-02-19 13:54:52 -05:00
Andrew Kelley
02f5d2673f Revert "Merge pull request #14661 from evacchi/zig-wasi-preopens"
This reverts commit 772a0eb68ac95b7e24508580499b49872fdb541f, reversing
changes made to 0bb178bbb2451238a326c6e916ecf38fbc34cab1.

This needs a rebase against master branch - it has build-breaking merge
conflicts. I also added a "changes requested" review on the original
pull request.
2023-02-19 09:40:55 -07:00
Luuk de Gram
772a0eb68a
Merge pull request #14661 from evacchi/zig-wasi-preopens 2023-02-19 17:09:58 +01:00
Andrew Kelley
0bb178bbb2
Merge pull request #14671 from ziglang/multi-object-for
implement multi-object for loops
2023-02-19 10:10:59 -05:00
Tom Read Cutting
346ec15c50
Correctly handle carriage return characters according to the spec (#12661)
* Scan from line start when finding tag in tokenizer

This resolves a crash that can occur for invalid bytes like carriage
returns that are valid characters when not parsed from within literals.

There are potentially other edge cases this could resolve as well, as
the calling code for this function didn't account for any potential
'pending_invalid_tokens' that could be queued up by the tokenizer from
within another state.

* Fix carriage return crash in multiline string

Follow the guidance of #38:

> However CR directly before NL is interpreted as only a newline and not part of the multiline string. zig fmt will delete the CR.

Zig fmt already had code for deleting carriage returns, but would still
crash - now it no longer does so. Carriage returns encountered before
line-feeds are now appropriately removed on program compilation as well.

* Only accept carriage returns before line feeds

Previous commit was much less strict about this, this more closely
matches the desired spec of only allow CR characters in a CRLF pair, but
not otherwise.

* Fix CR being rejected when used as whitespace

Missed this comment from ziglang/zig-spec#83:

> CR used as whitespace, whether directly preceding NL or stray, is still unambiguously whitespace. It is accepted by the grammar and replaced by the canonical whitespace by zig fmt.

* Add tests for carriage return handling
2023-02-19 14:14:03 +02:00
The Potato Chronicler
281d4c0ff6
Fix grammatical error in doc comment 2023-02-19 14:12:09 +02:00
Andrew Kelley
5fc6bbe71e update zig1.wasm 2023-02-18 19:20:19 -07:00
Andrew Kelley
15d767c621 add safety test cases for multi-object for loops 2023-02-18 19:20:19 -07:00
Andrew Kelley
40c4c25e2b Sema: add missing coercion when checking for loop len 2023-02-18 19:20:19 -07:00
Andrew Kelley
12a7a0d76f omit safety check when incrementing for loop counter
Since for loops are statically analyzed to have an upper bound, and the
loop counter is a usize, it is impossible for it to overflow.
2023-02-18 19:20:19 -07:00
Andrew Kelley
8b05205bb7 implement error for unbounded for loops 2023-02-18 19:20:19 -07:00
Andrew Kelley
e89bfedd8d update compare-output test case to new for loop syntax 2023-02-18 19:20:19 -07:00
Andrew Kelley
74db8c2e83 omit safety checks for element access in for loops
One of the main points of for loops is that you can safety check the
length once, before entering the loop, and then safely assume that every
element inside the loop is in bounds.

In master branch, the safety checks are incorrectly intact even inside
for loops. This commit fixes it. It's especially nice with multi-object
loops because the number of elided checks is N * M where N is how many
iterations and M is how many objects.
2023-02-18 19:20:19 -07:00
Andrew Kelley
7abeb52abc langref: update to new for loop syntax 2023-02-18 19:20:19 -07:00
Andrew Kelley
4dd958d585 improve error message for byref capture of byval array 2023-02-18 19:20:19 -07:00
Andrew Kelley
601db3981c fix source location for not-indexable for loop errors 2023-02-18 19:20:19 -07:00
Andrew Kelley
bcb72401d3 AstGen: add error for discard of unbounded counter 2023-02-18 19:17:21 -07:00
Andrew Kelley
22965e6fcb Sema: improve error message for mismatched for loop lengths 2023-02-18 19:17:21 -07:00
Andrew Kelley
b13745ac03 disable failing x86_64 backend tests 2023-02-18 19:17:21 -07:00
Andrew Kelley
209e83f395 AstGen: fix ZIR for for loops accessing instruction out of block 2023-02-18 19:17:21 -07:00
Andrew Kelley
8c96d0dddd update test-cases for new for loop syntax 2023-02-18 19:17:21 -07:00
Andrew Kelley
b6a5e52dec add passing for loop test: two counters 2023-02-18 19:17:21 -07:00
Andrew Kelley
f2a6a1756b Sema: fix for loops with comptime-known int ranges 2023-02-18 19:17:21 -07:00
Andrew Kelley
552e8095ae update docgen to new for loop syntax 2023-02-18 19:17:21 -07:00
Andrew Kelley
a005b5f198 add zig fmt test for upgrading for loop syntax 2023-02-18 19:17:21 -07:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Andrew Kelley
f0530385b5 update existing behavior tests and std lib to new for loop semantics 2023-02-18 19:17:21 -07:00
Andrew Kelley
321ccbdc52 Sema: implement for_len
This also makes another breaking change to for loops: in order to
capture a pointer of an element, one must take the address of array
values. This simplifies a lot of things, and makes more sense than how
it was before semantically.

It is still legal to use a for loop on an array value if the
corresponding element capture is byval instead of byref.
2023-02-18 19:17:21 -07:00
Andrew Kelley
5029e5364c make zig fmt perform upgrade to new for loop syntax
The intent here is to revert this commit after Zig 0.10.0 is released.
2023-02-18 19:17:21 -07:00
Andrew Kelley
293d6bdc73 AstGen: back to index-based for loops 2023-02-18 19:17:20 -07:00
Andrew Kelley
841add6890 AstGen: finish multi-object for loops
This strategy uses pointer arithmetic to iterate through the loop. This
has a problem, however, which is tuples. AstGen does not know whether a
given indexable is a tuple or can be iterated based on contiguous
memory. Tuples unlike other indexables cannot be represented as a
many-item pointer that is incremented as the loop counter.

So, after this commit, I will modify AstGen back closer to how @vexu had
it before, using a counter and array element access.
2023-02-18 19:17:20 -07:00
Andrew Kelley
faa44e2e58 AstGen: rework multi-object for loop
* Allow unbounded looping.
* Lower by incrementing raw pointers for each iterable rather than
  incrementing a single index variable. This elides safety checks
  without any analysis required thanks to the length assertion and
  lowers to decent machine code even in debug builds.
  - An "end" value is selected, prioritizing a counter if possible,
    falling back to a runtime calculation of ptr+len on a slice input.
* Specialize on the pattern `0..`, avoiding an unnecessary subtraction
  instruction being emitted.
* Add the `for_check_lens` ZIR instruction.
2023-02-18 19:17:20 -07:00
Veikka Tuominen
6733e43d87 AstGen: work-in-progress multi-object for loops 2023-02-18 19:17:20 -07:00
Veikka Tuominen
1b7055b514 parse and render new for loop syntax 2023-02-18 19:17:20 -07:00
Andrew Kelley
5e7b09ce9f std.Build.RunStep: fix default caching logic
RunStep is supposed to auto-detect whether the intend is for
side-effects or for producing an output file. The auto-detection logic
was incorrect, and this commit fixes it.

I tested this manually locally. Automated testing will require a more
significant investment in the test harness, which I will work on in a
future enhancement.

closes #14666
2023-02-18 19:33:47 -05:00
Edoardo Vacchi
4940afc434 skip when builtin.link_libc 2023-02-18 22:29:11 +01:00
Edoardo Vacchi
a250af5a51 wasi: add Preopens.findDir, update tests to preopen `/tmp'
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-02-18 21:41:26 +01:00
Matt Knight
07630eb696
Value: implement writeToMemory for packed unions 2023-02-18 21:10:27 +02:00
Jonathan Marler
dafefe9c9d use std_options for keep_sigpipe and existence of SIG.PIPE to check for support 2023-02-18 11:49:15 -07:00
flexicoding
c993af6234
compiler_rt: remove unexported functions 2023-02-18 17:07:35 +00:00
Jonathan Marler
0a8fe34b11 add test to ignore sigpipe 2023-02-17 15:25:36 -07:00
Ali Chraghi
c32171991b Ast: fix expected_block error message
Fixes #14579
2023-02-17 20:54:50 +02:00
Jonathan Marler
c02ced4d34 ignore SIGPIPE by default 2023-02-17 09:08:41 -07:00