22588 Commits

Author SHA1 Message Date
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
Matt Knight
07630eb696
Value: implement writeToMemory for packed unions 2023-02-18 21:10:27 +02:00
flexicoding
c993af6234
compiler_rt: remove unexported functions 2023-02-18 17:07:35 +00:00
Ali Chraghi
c32171991b Ast: fix expected_block error message
Fixes #14579
2023-02-17 20:54:50 +02:00
Motiejus Jakštys
3f7e9ff597 [all linkers] fail hard on unsupported flags
Currently `zig cc`, when confronted with a linker argument it does
not understand, skips the flag and emits a warning.

This has been causing headaches for people that build third-party
software (including me). Zig seemingly builds and links the final
executable, only to segfault when running it.

If there are linker warnings when compiling software, the first thing we
have to do is add support for ones linker is complaining, and only then
go file issues. If zig "successfully" (i.e. status code = 0) compiles a
binary, there is instead a tendency to blaim "zig doing something
weird". (I am guilty of this.) In my experience, adding the unsupported
arguments has been quite easy; see #11679, #11875, #11874 for recent
examples.

With the current ones (+ prerequisites below) I was able to build all of
the CGo programs that I am encountering at $dayjob. CGo is a reasonable
example, because it is exercising the unusual linker args quite a bit.

Prerequisites: #11614 and #11863.
2023-02-16 19:20:53 -05:00
Andrew Kelley
d2650eb570 CLI: detect linker color diagnostics flags 2023-02-16 17:19:26 -07:00
Motiejus Jakštys
705e9cb3ca [linker] ignore --sort-common
From ld.lld(1):

     --sort-common
             This option is ignored for GNU compatibility.

Refs https://github.com/zigchroot/zig-chroot/issues/1
2023-02-16 18:46:06 -05:00
Motiejus Jakštys
b1b944a683 [elf linker] add --sort-section
Tested by: created a "hello world" C file and compiled with:

    zig cc -v main.c -Wl,--sort-section=name -o main

... and verified the `--sort-section=name` is passed to ld.lld.

Refs https://github.com/zigchroot/zig-chroot/issues/1
2023-02-16 18:44:56 -05:00
Andrew Kelley
f911c933b2
Merge pull request #11912 from motiejus/wl-no-undefined
[linker] add --no-undefined, -z undefs
2023-02-16 18:36:57 -05:00
Andrew Kelley
61da9a25b9 CLI: remove option from usage text since it doesn't work 2023-02-16 16:35:06 -07:00
Motiejus Jakštys
4c7ca20da5 [linker] add --no-undefined, -z undefs
Refs https://github.com/zigchroot/zig-chroot/issues/1
2023-02-16 16:33:05 -07:00
Chris Boesch
438b71155a
crypto: add AES-CMAC (RFC 4493) (#14545)
* crypto: add AES-CMAC

Co-authored-by: Frank Denis <124872+jedisct1@users.noreply.github.com>
2023-02-16 21:18:20 +01:00
Veikka Tuominen
7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Jakub Konka
4e6f21e2cb comp: reinstate -fcompiler-rt when used with build-obj as output
When the following is specified

```
$ zig build-obj -fcompiler-rt example.zig
```

the resulting relocatable object file will have the compiler-rt
unconditionally embedded inside.

```
$ nm example.o
...
0000000012345678 W __truncsfhf2
...
```
2023-02-14 12:12:22 -05:00
Tom Read Cutting
47e14b7ffb Zld: Report archive file with cpu arch mismatch
This is just a simple/hacky feature to report the source of a linking
error. I found this helpful in fixing-up some of my libs when recently
switching from an x86_64 to aarch64 device, so thought it might be
useful to others a well before zld has a fully featured error reporting
system.
2023-02-14 12:05:30 +01:00
Philippe Pittoli
d09e39aefd Add std.c.umask. 2023-02-14 02:17:33 +02:00
Andrew Kelley
a9e1cf3049
Merge pull request #14571 from ziglang/more-build-zig
std.Build.ConfigHeaderStep: support sentinel-terminated strings
2023-02-13 17:23:19 -05:00
Andrew Kelley
35bb823131 build.zig: builder.zig_exe is not relative 2023-02-13 09:13:36 -07:00
Veikka Tuominen
fc48467a97
Merge pull request #14548 from schmee/std-json-fixes
Some std.json fixes
2023-02-13 16:24:29 +02:00
AdamGoertz
c8dc00086e
Add -ferror-tracing and -fno-error-tracing compile options 2023-02-13 16:23:13 +02:00
Manlio Perillo
5894be94c8 langref: make more examples testable
Some examples using {#syntax_block|zig|...#} either have a valid syntax
or it is easy to make the syntax valid.  Update these example to use
{#code_begin|syntax|...#}.

Remove extra whitespace in the error_union_parsing_u64.zig example.

Replace size_t with usize in the call_malloc_from_zig.zig example.
2023-02-13 16:21:54 +02:00
Leo Constantinides
25d6b8c1f1
std: support deserialising JSON strings containing escape seqences into sentinel slice 2023-02-13 15:44:34 +02:00
Andrew Kelley
e9c7e539e4 std.Build.OptionsStep: update test case 2023-02-13 06:42:26 -07:00
Andrew Kelley
5c1f7288d9 std.Build: delete test that doesn't test anything 2023-02-13 06:42:26 -07:00