11072 Commits

Author SHA1 Message Date
Andrew Kelley
22965e6fcb Sema: improve error message for mismatched for loop lengths 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
f2a6a1756b Sema: fix for loops with comptime-known int ranges 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
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
Matt Knight
07630eb696
Value: implement writeToMemory for packed unions 2023-02-18 21:10:27 +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
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
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
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
AdamGoertz
c8dc00086e
Add -ferror-tracing and -fno-error-tracing compile options 2023-02-13 16:23:13 +02:00
Andrew Kelley
9cb52ca6ce move the cache system from compiler to std lib 2023-02-13 06:42:25 -07:00
Ali Chraghi
a8edd67d3d zig fmt: additionally format .zon files 2023-02-13 02:20:02 -05:00
Andrew Kelley
d4bd1b1a60
Merge pull request #14618 from Vexu/fixes
small misc fixes
2023-02-13 01:58:01 -05:00
Veikka Tuominen
ba680aa987
Merge pull request #14588 from dweiller/test-runner-imports
fix custom test runner file import path resolution
2023-02-11 14:40:14 +02:00
Veikka Tuominen
28413ffcba Sema: fix typo in zirCUndef
Closes #14617
2023-02-11 14:36:54 +02:00
Veikka Tuominen
0328c9cbeb llvm: fix lowerDeclRefValue for extern function aliases
Same as 0577069af5f5deb859762725736537d60c324453 for extern functions.

Closes  #14610
2023-02-11 14:36:54 +02:00
Veikka Tuominen
8127a27eb1 zig fmt: do not consider tuples blocks
Closes #14056
2023-02-11 14:36:54 +02:00
Veikka Tuominen
31ed8d293d Sema: add missing peer type resolution for error unions
Closes #14077
2023-02-11 14:36:54 +02:00
Veikka Tuominen
b9c2837c1c Sema: validate inferred error set payload type
This was missed in b0a55e1b3be3a274546f9c18016e9609d546bdb0
2023-02-11 14:36:54 +02:00
John Schmidt
a5d25fabda
translate_c: fix typedeffed pointer subtraction
Closes #14560.
2023-02-10 15:46:29 +02:00
Dominic
948754c5d4
clone package table into custom test runner
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2023-02-08 22:39:38 +11:00
dweiller
edc0e84270 allow custom test runners to import modules 2023-02-08 16:35:32 +11:00
Jakub Konka
94c68c1f9e macho: fix incorrect representation of encodings count per page
There can be a maximum of 256 compact encodings per page in compact
unwind info, and we were using `u8` to represent the count which is insufficient.
This commit bumps it to `u9`.
2023-02-08 05:03:14 +01:00
dweiller
1f7390f399 fix custom test runner package path resolution
Fixes #13970.

This fix makes test runners resolve package paths relative to the
directory the test runner is in. This means it is not possible to import
a file from outside the file tree root at the directory containing the
test runner.
2023-02-08 14:30:37 +11:00
Jakub Konka
4b1a883d35 macho: ensure local syms buffer is nlist_64 aligned when re-reading from file 2023-02-07 03:14:26 +01:00
Jakub Konka
f63eda3f6a macho: parse and sort data-in-code entries ahead of time 2023-02-06 16:08:42 +01:00
Jakub Konka
b32f5ee932 macho: downgrade alignment requirements for symtab in object files
Parse and sort relocations by address descending.
2023-02-06 13:23:08 +01:00
Andrew Kelley
11cc1c16fa make @embedFile support module-mapped names the same way as @import
closes #14553
2023-02-05 03:25:43 -05:00
Luuk de Gram
c9b957c937 link: remove FnData and make it self-owned
This finishes the work started in #14502 where atoms are owned by the
linker themselves. This now makes debug atoms fully owned by dwarf,
and no information is left stored on the decl.
2023-02-03 22:55:46 +01:00
Andrew Kelley
60935decd3
Merge pull request #14523 from ziglang/zon
introduce Zig Object Notation and use it for the build manifest file (build.zig.zon)
2023-02-03 14:20:49 -05:00
Loris Cro
e59ef95a40
Merge pull request #14515 from der-teufel-programming/autodoc-quickfixes
autodoc: Added `@qualCast` builtin function handling
2023-02-03 17:55:31 +01:00
Loris Cro
93c56a70c4
Merge pull request #14489 from der-teufel-programming/autodoc-initempty
autodoc: Implemented struct_init_empty for walkInstruction
2023-02-03 17:52:23 +01:00
Andrew Kelley
81c27c74bc use build.zig.zon instead of build.zig.ini for the manifest file
* improve error message when build manifest file is missing
 * update std.zig.Ast to support ZON
 * Compilation.AllErrors.Message: make the notes field a const slice
 * move build manifest parsing logic into src/Manifest.zig and add more
   checks, and make the checks integrate into the standard error
   reporting code so that reported errors look sexy

closes #14290
2023-02-03 00:06:11 -07:00
Andrew Kelley
873bb29c98 introduce ZON: Zig Object Notation
* std.zig.parse is moved to std.zig.Ast.parse
 * the new function has an additional parameter that requires passing
   Mode.zig or Mode.zon
 * moved parser.zig code to Parse.zig
 * added parseZon function next to parseRoot function
2023-02-03 00:06:11 -07:00
Andrew Kelley
7505d19e93
Merge pull request #14511 from ziglang/zig-build-hashes
two package hash breaking enhancements
2023-02-02 14:03:41 -05:00
Krzysztof Wolicki Der Teufel
c3abb63fe9 autodoc: Added @qualCast builtin function handling 2023-02-02 14:47:16 +01:00
Andrew Kelley
6b7ad22981
Merge pull request #14477 from Vexu/fixes
Improve `@ptrCast` errors, fix some bugs
2023-02-01 23:31:52 -05:00
Andrew Kelley
24ff8a1a5f zig build: use multihash for the hash field
https://multiformats.io/multihash/

Still, only SHA2-256 is supported. This is only intended to future-proof
the hash field of the manifest.

closes #14284
2023-02-01 20:02:35 -07:00