Commit Graph

3895 Commits

Author SHA1 Message Date
Andrew Kelley
a0e89c9b46 Merge remote-tracking branch 'origin/master' into llvm12 2021-04-02 12:09:38 -07:00
Loris Cro
354c14d6a2 make visited links readable in the stdlib docs warning bar 2021-04-02 20:22:02 +02:00
Loris Cro
4fef1d2982 added warning banner to stdlib docs 2021-04-02 20:13:55 +02:00
Andrew Kelley
d780848ae4
Merge pull request #7792 from zanderxyz/zanderxyz/priority-dequeue
std: Add Priority Dequeue
2021-04-02 10:52:23 -07:00
Michael Dusan
cc435dab2f test: fix io_uring timing test to skip on failure 2021-04-02 07:12:09 -04:00
lithdew
59035ae3e9 os: handle ECONNRESET for connect() syscall 2021-04-01 14:18:49 +02:00
Andrew Kelley
070a28e493
Merge pull request #8266 from ziglang/zir-memory-layout
rework ZIR memory layout; overhaul source locations
2021-03-31 23:11:15 -07:00
Andrew Kelley
b27d052676 stage2: finish source location reworkings in the branch
* remove the LazySrcLoc.todo tag
 * finish updating Sema and AstGen, remove the last of the
   `@panic("TODO")`.
2021-03-31 21:36:32 -07:00
Matthew Borkowski
501b4aff99 Add tests for the fill functions of the Isaac64, Pcg, Sfc64, and Xoroshiro128 PRNGs 2021-03-29 09:22:06 +02:00
Matthew Borkowski
a5cc5f7854 Fix typo in Pcg.zig's fill function
When filling the last (len % 4) bytes of a buffer, the random number n was only being shifted right by 4 bits for each byte instead of 8. A random u16, for example, would always have its middle two nybbles be equal when generated this way. For comparison, Isaac64.zig, Sfc64.zig, and Xoroshiro128.zig all correctly shift right by 8 bits for each of the last bytes in their nearly identical fill functions.
2021-03-29 09:22:06 +02:00
Andrew Kelley
b85ef2300f Merge remote-tracking branch 'origin/master' into llvm12 2021-03-28 21:42:56 -07:00
Andrew Kelley
281a7baaea Merge remote-tracking branch 'origin/master' into zir-memory-layout
Wanted to make sure those new test cases still pass.

Also grab that CI fix so we can get those green check marks.
2021-03-28 19:42:43 -07:00
Andrew Kelley
bb5cfbcb72
Merge pull request #8305 from jedisct1/base64
std/base64: cleanups & support url-safe and other non-padded variants
2021-03-28 17:11:07 -07:00
Jonathan Knezek
bbe6a0dddd Add a test & fix for std.fmt.fmtDuration 2021-03-28 15:44:15 +02:00
Frank Denis
6993087edc Remove the base64 unsafe decoder 2021-03-28 14:32:34 +02:00
Frank Denis
99bed37fc7 Add more variants 2021-03-28 14:32:34 +02:00
Frank Denis
b8c019ef49 std/base64: cleanups & support url-safe and other non-padded variants
This makes a few changes to the base64 codecs.

* The padding character is optional. The common "URL-safe" variant, in
particular, is generally not used with padding. This is also the case for
password hashes, so having this will avoid code duplication with bcrypt,
scrypt and other functions.
* The URL-safe variant is added. Instead of having individual constants
for each parameter of each variant, we are now grouping these in a
struct. So, `standard_pad_char` just becomes `standard.pad_char`.
* Types are not `snake_case`'d any more. So, `standard_encoder` becomes
`standard.Encoder`, as it is a type.
* Creating a decoder with ignored characters required the alphabet and
padding. Now, `standard.decoderWithIgnore(<ignored chars>)` returns a
decoder with the standard parameters and the set of ignored chars.
* Whatever applies to `standard.*` obviously also works with `url_safe.*`
* the `calcSize()` interface was inconsistent, taking a length in the
encoder, and a slice in the encoder. Rename the variant that takes a
slice to `calcSizeForSlice()`.
* In the decoder with ignored characters, add `calcSizeUpperBound()`,
which is more useful than the one that takes a slice in order to size
a fixed buffer before we have the data.
* Return `error.InvalidCharacter` when the input actually contains
characters that are neither padding nor part of the alphabet. If we
hit a padding issue (which includes extra bits at the end),
consistently return `error.InvalidPadding`.
* Don't keep the `char_in_alphabet` array permanently in a decoder;
it is only required for sanity checks during initialization.
* Tests are unchanged, but now cover both the standard (padded) and
the url-safe (non-padded) variants.
* Add an error set, rename `OutputTooSmallError` to `NoSpaceLeft`
to match the `hex2bin` equivalent.
2021-03-28 14:32:34 +02:00
lithdew
c8d721aa42 array_hash_map: decrement entries slice len after popping from entries in pop() to prevent oob 2021-03-28 11:02:37 +02:00
LemonBoy
75080e351a std: Detect AMD Zen3 CPU family
Easy peasy lemon squeezy.
2021-03-27 12:23:40 -07:00
lithdew
4ce212739b os/linux: handle ECONNRESET for recv 2021-03-25 12:41:51 -07:00
Sreehari S
5c28b8cd11 boot_services: implement locateDevicePath 2021-03-25 16:45:43 +02:00
Andrew Kelley
31023de6c4 stage2: implement inline while
Introduce "inline" variants of ZIR tags:
 * block => block_inline
 * repeat => repeat_inline
 * break => break_inline
 * condbr => condbr_inline

The inline variants perform control flow at compile-time, and they
utilize the return value of `Sema.analyzeBody`.

`analyzeBody` now returns an Index, not a Ref, which is the ZIR index of
a break instruction. This effectively communicates both the intended
break target block as well as the operand, allowing parent blocks to
find out whether they, in turn, should return the break instruction up the
call stack, or accept the operand as the block's result and continue
analyzing instructions in the block.

Additionally:
 * removed the deprecated ZIR tag `block_comptime`.
 * removed `break_void_node` so that all break instructions use the same Data.
 * zir.Code: remove the `root_start` and `root_len` fields. There is now
   implied to be a block at index 0 for the root body. This is so that
   `break_inline` has something to point at and we no longer need the
   special instruction `break_flat`.
 * implement source location byteOffset() for .node_offset_if_cond
   .node_offset_for_cond is probably redundant and can be deleted.

We don't have `comptime var` supported yet, so this commit adds a test
that at least makes sure the condition is required to be comptime known
for `inline while`.
2021-03-25 00:55:36 -07:00
Isaac Freund
0c601965ab
stage2: make zir.Inst.Ref a non-exhaustive enum
This provides us greatly increased type safety and prevents the common
mistake of using a zir.Inst.Ref where a zir.Inst.Index was expected or
vice-versa. It also increases the ergonomics of using the typed values
which can be directly referenced with a Ref over the previous zir.Const
approach.

The main pain point is casting between a []Ref and []u32, which could be
alleviated in the future with a new std.mem function.
2021-03-24 19:11:44 +01:00
Isaac Freund
3bf72f2b3a std.build: make Builder.install_prefix non optional
This is useful for build.zig files to check in some cases, for example
to adhere to the convention of installing config to /etc instead of
/usr/etc on linux when using the /usr prefix. Perhaps std.build will
handle such common cases eventually, but that is not yet the case.
2021-03-24 12:29:50 +01:00
Isaac Freund
8111453cc1
astgen: implement array types 2021-03-22 14:54:13 +01:00
Carlos Zúñiga
187af14599 Fixed typo in user32
Use CreateWindowExW instead of RegisterClassExW as the type of pfnCreateWindowExW.
2021-03-22 10:43:04 +02:00
Joris Hartog
5e40560367 Specify type in autoHash error message
This commit simply specifies the type which `autoHash` can't hash in the
compile error.

Closes #7970.
2021-03-21 23:07:02 +02:00
Nuno Leiria
0d96a284e8 std: Add reset to TokenIterator 2021-03-20 22:01:09 -07:00
Andrew Kelley
56677f2f2d astgen: support blocks
We are now passing this test:

```zig
export fn _start() noreturn {}
```

```
test.zig:1:30: error: expected noreturn, found void
```

I ran into an issue where we get an integer overflow trying to compute
node index offsets from the containing Decl. The problem is that the
parser adds the Decl node after adding the child nodes. For some things,
it is easy to reserve the node index and then set it later, however, for
this case, it is not a trivial code change, because depending on tokens
after parsing the decl determines whether we want to add a new node or
not.

Possible strategies here:

1. Rework the parser code to make sure that Decl nodes are before
   children nodes in the AST node array.

2. Use signed integers for Decl node offsets.

3. Just flip the order of subtraction and addition. Expect Decl Node
   index to be greater than children Node indexes.

I opted for (3) because it seems like the simplest thing to do. We'll
want to unify the logic for computing the offsets though because if the
logic gets repeated, it will probably get repeated wrong.
2021-03-19 23:15:18 -07:00
LemonBoy
867ae506e3 std: Add syscall7 stub for Linux/MIPS
Some syscalls such as fadvise require an extra argument to comply with
the register pair alignment imposed by the ABI.

Wacky, isn't it?
2021-03-19 13:03:55 -07:00
Andrew Kelley
f5aca4a6a1 Merge remote-tracking branch 'origin/master' into zir-memory-layout
I need the enum arrays that were just merged into master.
2021-03-18 15:52:12 -07:00
Martin Wickham
96ae451bbe Add some enum utilities 2021-03-18 14:05:01 -07:00
Jakub Konka
17c066e925
Merge pull request #8282 from kubkon/zld
macho: upstream zld linker
2021-03-18 19:14:17 +01:00
root
75a7abb0c4 std: Fix std.fs.path.joinZ 2021-03-18 14:33:38 +02:00
Andrew Kelley
66245ac834 stage2: Module and Sema are compiling again
Next up is reworking the seam between the LazySrcLoc emitted by Sema
and the byte offsets currently expected by codegen.

And then the big one: updating astgen.zig to use the new memory layout.
2021-03-17 22:54:56 -07:00
Jakub Konka
7516dfff83 zld: use zld when linking aarch64 by default and cross-comp 2021-03-18 00:37:13 +01:00
Jakub Konka
1ec620be62 zld: fix GOT loads and indirection on x86_64 2021-03-17 19:59:57 +01:00
Jakub Konka
a1b0ec5277 zld: start bringing x64 up to speed 2021-03-17 19:59:13 +01:00
Jakub Konka
b0ee480177 zld: merge and sort sections 2021-03-17 19:59:13 +01:00
Jakub Konka
0f7b036eb7
Merge pull request #8281 from kubkon/macho-got-refactor
stage2+macho: refactor global offset table for incremental linker
2021-03-17 19:44:32 +01:00
Frank Denis
119fc318a7 std/crypto/chacha20: add round-reduced versions & cleanup internals
See https://eprint.iacr.org/2019/1492.pdf for justification.

8 rounds ChaCha20 provides a 2.5x speedup, and is still believed
to be safe.

Round-reduced versions are actually deployed (ex: Android filesystem
encryption), and thanks to the magic of comptime, it doesn't take much
to support them.

This also makes the ChaCha20 code more consistent with the Salsa20 code,
removing internal functions that were not part of the public API any more.

No breaking changes; the public API remains backwards compatible.
2021-03-17 11:25:51 -07:00
Andrew Kelley
587243c7a5
Merge pull request #8273 from jedisct1/pbkdf2-check
crypto/pbkdf2: simplify the check for the max number of iterations
2021-03-17 11:25:19 -07:00
Jakub Konka
e5234c0e9e macho: offset table part of GOT 2021-03-17 12:16:36 +01:00
Frank Denis
6d9b3e7b19 pbkdf2: use std.math.divCeil() 2021-03-17 10:11:47 +01:00
Evan Haas
f76bd56588 translate-c: fix __builtin_object_size
Previous code assumed `c_long` and `usize` were the same size.
Use `isize` instead.
2021-03-17 09:06:47 +02:00
Evan Haas
715370a10a translate-c: demote usage of un-implemented builtins 2021-03-17 09:06:47 +02:00
xackus
9a94415680 translate-c: improve std.meta.cast 2021-03-17 00:05:42 +02:00
jacob gw
83d0c2ed67 std: make all errors in os.zig public 2021-03-16 14:48:31 -07:00
Frank Denis
f609c4ddb3 crypto/pbkdf2: use snake_case for variables like everywhere else 2021-03-16 19:08:38 +01:00
Frank Denis
d1b1e542a0 crypto/pbkdf2: simplify the check for the max number of iterations 2021-03-16 18:55:58 +01:00
Lewis Gaul
6787f163eb
zig fmt: don't add trailing whitespace on switch case 2021-03-16 09:26:28 +01:00
LemonBoy
5ecf8bddae
zig fmt: Respect line breaks in struct default value decls
Bring this in line with how variable declarations are handled.

Open a new indentation level for the initialization expression to handle
nested expressions like blocks.

Closes #7618
2021-03-16 09:22:16 +01:00
Andrew Kelley
aef3e534f5 stage2: *WIP*: rework ZIR memory layout; overhaul source locations
The memory layout for ZIR instructions is completely reworked. See
zir.zig for those changes. Some new types:

 * `zir.Code`: a "finished" set of ZIR instructions. Instead of allocating
   each instruction independently, there is now a Tag and 8 bytes of
   data available for all ZIR instructions. Small instructions fit
   within these 8 bytes; larger ones use 4 bytes for an index into
   `extra`. There is also `string_bytes` so that we can have 4 byte
   references to strings. `zir.Inst.Tag` describes how to interpret
   those 8 bytes of data.
   - This is shared by all `Block` scopes.

 * `Module.WipZirCode`: represents an in-progress `zir.Code`. In this
   structure, the arrays are mutable, and get resized as we add/delete
   things. There is extra state to keep track of things. This struct is
   stored on the stack. Once it is finished, it produces an immutable
   `zir.Code`, which will remain on the heap for the duration of a
   function's existence.
   - This is shared by all `GenZir` scopes.

 * `Sema`: represents in-progress semantic analysis of a `zir.Code`.
   This data is stored on the stack and is shared among all `Block`
   scopes. It is now the main "self" argument to everything in the file
   that was previously named `zir_sema.zig`.
   Additionally, I moved some logic that was in `Module` into here.

`Module.Fn` now stores its parameter names inside the `zir.Code`,
instead of inside ZIR instructions. When the TZIR memory layout
reworking time comes, codegen will be able to reference this data
directly instead of duplicating it.

astgen.zig is (so far) almost entirely untouched, but nearly all of it
will need to be reworked to adhere to this new memory layout structure.

I have no benchmarks to report yet, as I am still working through
compile errors and fixing various things that I broke in this branch.

Overhaul of Source Locations:

Previously we used `usize` everywhere to mean byte offset, but sometimes
also mean other stuff. This was error prone and also made us do
unnecessary work, and store unnecessary bytes in memory.

Now there are more types involved into source locations, and more ways
to describe a source location.

 * AllErrors.Message: embrace the assumption that files always have less
   than 2 << 32 bytes.
 * SrcLoc gets more complicated, to model more complicated source
   locations.
 * Introduce LazySrcLoc, which can model interesting source locations
   with very little stored state. Useful for avoiding doing unnecessary
   work when no compile errors occur.

Also, previously, we had `src: usize` on every ZIR instruction. This is
no longer the case. Each instruction now determines whether it even cares
about source location, and if so, how that source location is stored.
This requires more careful work inside `Sema`, but it results in fewer
bytes stored on the heap, without compromising accuracy and power of
compile error messages.

Miscellaneous:

 * std.zig: string literals have more helpful result values for
   reporting errors. There is now a lower level API and a higher level
   API.
   - side note: I noticed that the string literal logic needs some love.
     There is some unnecessarily hacky code there.
 * cut & pasted some TZIR logic that was in zir.zig to ir.zig. This
   probably broke stuff and needs to get fixed.
 * Removed type/Enum.zig, type/Union.zig, and type/Struct.zig. I don't
   think this quite how this code will be organized. Need some more
   careful planning about how to implement structs, unions, enums. They
   need to be independent Decls, just like a top level function.
2021-03-16 00:03:22 -07:00
Anders Conbere
f16f25047c
std: support optional getaddrinfo arguments 2021-03-16 01:10:32 +01:00
Lewis Gaul
aa1c780560 Add test for multi-line while cont expr with same-line then expr 2021-03-15 20:44:45 +01:00
Isaac Freund
48efa3bcb6 zig fmt: simplify and improve consistency of if/for/while handling
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes https://github.com/ziglang/zig/issues/6114
Fixes https://github.com/ziglang/zig/issues/8022
2021-03-15 14:55:34 +01:00
Lewis Gaul
b4db03d8bb zig fmt: fix extra newline before if nested in for
Add failing testcase to reproduce issue 8088

Tidy up renderWhile(), factoring out renderWhilePayload()

Ensure correct newline is used before 'then' token in while/for/if

Handle indents for 'if' inside 'for' or 'while'

Stop special-casing 'if' compared to 'for' and 'while'
2021-03-15 14:55:34 +01:00
LemonBoy
27d07c6c4d std: Replace testing fns for floating-point values
Beside handling NaNs and other non-numeric values better we finally
offer the same pair of testing predicates in math and testing.
2021-03-14 17:23:47 -04:00
Frank Denis
b98d7747fa Use a unified error set for std/crypto/*
This ensures that errors are used consistently across all operations.
2021-03-14 20:51:31 +01:00
Andrew Kelley
1f34c03ac1 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-12 18:05:27 -07:00
LemonBoy
8ebb18d9da std: Use more common escape sequences in Progress
This should fix the badly-rendered progress message when run in
Terminal.app.
2021-03-12 19:31:59 -05:00
Isaac Freund
b83ef595a5 std/linux: sync io_uring library with liburing
liburing commit: 1bafb3ce5f

As stated in the liburing commit message, this fixes a regression,
reverting code that was added specutively to avoid a syscall in some
cases.
2021-03-12 22:22:06 +01:00
Andrew Kelley
f950489ed9
Merge pull request #8174 from LemonBoy/progress-line-wrap
std: Better handling of line-wrapping in Progress
2021-03-12 15:45:11 -05:00
Jakub Konka
a745e704f6 macos: add missing x86_64 libc headers 2021-03-12 18:05:50 +01:00
LemonBoy
b0724a350f Handle some weird edge cases of Win32 API
Sometimes the viewport srWindow may report an invalid rectangle where
the top row is below the bottom one.
2021-03-12 17:14:50 +01:00
LemonBoy
b5a50a26eb Fix many thinkos
Somehow I forgot to save after copy-pasting some code and changing it.
2021-03-12 15:08:48 +01:00
Sébastien Marie
89e522b935 make std.c.getErrno() return same type as _errno() aka c_int
adjust std.os.unexpectedErrno() to be correct for all std.os.system.errno (c_int, u12, usize, ...)
2021-03-12 15:04:36 +01:00
LemonBoy
3010bfb08a Fix Progress printing on Windows systems
The cursor must be restored after the line is printed, not before.
Take into account the visible viewport to correctly compute the terminal
size.
2021-03-12 10:15:38 +01:00
Andrew Kelley
e9a038c33b
Merge pull request #7934 from Vexu/stage2-cbe
Stage2 cbe: optionals and errors
2021-03-11 22:02:35 -05:00
Isaac Freund
a5cb4ab95e parser: disallow ptr modifiers on array types 2021-03-12 00:18:30 +01:00
LemonBoy
482424e2b1 std: Handle empty MultiArrayList in items()
Closes #8211
2021-03-12 00:17:35 +01:00
Andrew Kelley
4fc6f631e0
Merge pull request #8126 from xackus/translate_c_int_literal_promotion
translate-c: promote int literals to bigger types
2021-03-11 14:32:37 -05:00
Asherah Connor
24e5959840 elf: make EM non-exhaustive 2021-03-11 10:09:51 +11:00
Asherah Connor
c5eb15526d expose machine field in ELF header 2021-03-10 16:26:41 +11:00
Loris Cro
a033735c8d update to latest fetch-them-macos-headers 2021-03-09 22:43:16 +01:00
Loris Cro
767eb2d469 update to latest fetch-them-macos-headers 2021-03-09 22:15:01 +01:00
Isaac Freund
b988815bf0 parser: fix parsing/rendering of a[b.. :c] slicing
The modification to the grammar in the comment is in line with the
grammar in the zig-spec repo.

Note: checking if the previous token is a colon is insufficent to tell
if a block has a label, the identifier must be checked for as well. This
can be seen in sentinel terminated slicing: `foo[0..1:{}]`
2021-03-08 01:37:28 +01:00
Veikka Tuominen
0a7be71bc2
stage2 cbe: non pointer optionals 2021-03-08 00:33:56 +02:00
jacob gw
5d215cc76b stage2 Elf linker: fill in bswapAllFields
I moved it to std.elf since it could be used there and added test
2021-03-07 23:18:26 +02:00
LemonBoy
4fc2e92876 std: Better handling of line-wrapping in Progress
In order to update the printed progress string the code tried to move
the cursor N cells to the left, where N is the number of written bytes,
and then clear the remaining part of the line.
This strategy has two main issues:
 - Is only valid if the number of characters is equal to the number of
   written bytes,
 - Is only valid if the line doesn't get too long.

The second point is the main motivation for this change, when the line
becomes too long the terminal wraps it to a new physical line. This
means that moving the cursor to the left won't be enough anymore as once
the left border is reached it cannot move anymore.

The wrapped line is still stored by the terminal as a single line,
despite now taking more than a single one when displayed. If you try to
resize the terminal you'll notice how the contents are reflowed and are
essentially illegible.

Querying the cursor position on non-Windows systems (plot twist,
Microsoft suggests using VT escape sequences on newer systems) is
extremely cumbersome so let's do something different.

Before printing anything let's save the cursor position and clear the
screen below the cursor, this way we ensure there's absolutely no trace
of stale data on screen, and after the message is printed we simply
restore it.
2021-03-07 15:23:20 +01:00
Jonathan Knezek
0447a2c041
Implement fmtDuration using Formatter (#8137)
* Implement fmtDuration using Formatter

Deprecate Duration, duration

* fmtDuration: Fixed ns remainder

* fmtDuration: Fixed visibility; removed [Dd]uration
2021-03-07 15:00:15 +02:00
LemonBoy
72664df491 std: Deprecate the B and Bi format specifiers
Following #8007 and #8137 let's get rid of the last weird format.
2021-03-07 14:58:45 +02:00
LemonBoy
e47b754b28 std: Prevent null pointer deref in mem.len{,Z}
Closes #8140
2021-03-07 14:58:45 +02:00
Vincent Rischmann
272ae0ca0d fix parsing of assignment with 'inline for' and 'inline while' 2021-03-06 17:39:54 -08:00
Meghan
9f722f43ac
std/special: init-exe,lib make import(std) its own decl (#8160)
std/special: init-exe,lib make import(std) its own decl
2021-03-05 19:13:05 -08:00
Isaac Freund
ef3adbdb36 zig fmt: fix lastToken() for container_decl_arg 2021-03-05 21:33:27 +01:00
xackus
eee43a65ae add tests 2021-03-05 21:21:23 +01:00
Maciej Walczak
5f53b77c2b remove redundant cast
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-03-05 21:04:27 +01:00
xackus
679910ecec translate-c: promote int literals to bigger types 2021-03-05 21:04:27 +01:00
Veikka Tuominen
9cd038d73a std: fix memory leak in MultiArrayList 2021-03-05 10:52:40 -08:00
cryptocode
02737d535a Reject bare +/- input when parsing floats 2021-03-05 13:11:20 +01:00
Andrew Kelley
434fce2146 zig fmt: recovery: missing while rbrace
Previously, this test case resulted in zig fmt entering an endless loop.
2021-03-04 20:54:09 -07:00
Andrew Kelley
bccef44196 Merge remote-tracking branch 'origin/master' into llvm12
Syncing with master branch because I want to re-run
update_clang_options.zig in the llvm12 branch.
2021-03-04 18:23:11 -07:00
Andrew Kelley
ffb2568a9f
Merge pull request #7763 from kivikakk/zig-elf-parse
std.elf: expose parsing decoupled from std.fs.File
2021-03-04 11:56:31 -08:00
daurnimator
34ca6b7b44 std: add io.Writer.writeStruct
We have readStruct, add writeStruct for symmetry
2021-03-03 22:45:45 +01:00
Veikka Tuominen
904f774563 translate-c: fix c tokenizer giving invalid tokens 2021-03-03 11:33:14 -08:00
Isaac Freund
3ad9cb8b47 zig fmt: allow and trim whitespace around zig fmt: (off|on)
Currently `//  zig fmt: off` does not work as there are two spaces
after the `//` instead of one. This can cause confusion, so allow
arbitrary whitespace before the `zig fmt: (off|on)` in the comment but
trim this whitespace to the canonical single space in the output.
2021-03-03 01:06:09 +01:00
Andrew Kelley
934b170d67 Revert "update i386 assembly to satisify llvm12"
This reverts commit 6af6c3c979.
2021-03-02 15:03:19 -07:00
Andrew Kelley
68c00122b1 x86: detect and set 16bit_mode and 32bit_mode CPU features 2021-03-02 14:49:28 -07:00
Vincent Rischmann
3dd8396a55 os/linux: fix IO_Uring.timeout
According to the io_uring PDF (https://kernel.dk/io_uring.pdf) the
timeout struct must be 64 bits on both 32 and 64 bit architectures.
2021-03-02 14:13:11 +02:00
Andrew Kelley
f9c9b92175
Merge pull request #7946 from koachan/sparc64-framefixes
SPARCv9: Handle various stack frame related quirks.
2021-03-01 19:10:36 -08:00
Andrew Kelley
a20169a610 zig fmt the std lib 2021-03-01 20:04:28 -07:00
Martin Wickham
7613e51a57 Add some bit set variants 2021-03-01 18:52:15 -08:00
Isaac Freund
7b5b7bda87 parser: fix infinite loop on missing comma in param list 2021-03-01 16:09:57 -08:00
LemonBoy
cd7c870bd8 std: Deprecate 'x'/'X'/'e'/'E' special cases for u8 slices
Let's follow the road paved by the removal of 'z'/'Z', the Formatter
pattern is nice enough to let us remove the remaining four special cases
and declare u8 slices free from any special casing!
2021-03-01 15:33:10 -08:00
Andrew Kelley
584cb2e4fb Merge remote-tracking branch 'origin/master' into llvm12 2021-03-01 12:09:26 -07:00
LemonBoy
bee7db77fe std: Replace lastIndexOf with lastIndexOfScalar
This may work around the miscompilation in LLVM 12.
2021-03-01 11:08:16 -08:00
fancl20
baab1b2f31
std: Add std.fs.path.joinZ (#7974)
* std: Add std.fs.path.joinZ

* Merge std.fs.path.join and std.fs.path.joinZZ tests
2021-03-01 10:38:56 +02:00
Evan Haas
45d220cac6 translate-c: add <assert.h> support
Implement __builtin_expect so C code that uses assert() can be translated.
2021-03-01 10:34:23 +02:00
Andrew Kelley
6af6c3c979 update i386 assembly to satisify llvm12
Without this, LLVM 12 says:
error: ambiguous instructions require an explicit suffix (could be
'retw', or 'retl')
2021-02-28 21:59:45 -07:00
Andrew Kelley
9550db33cb
Merge pull request #8097 from LemonBoy/thread-spawn-order
std: Swap arguments in Thread.spawn
2021-02-28 20:42:34 -08:00
Frank Denis
a5a3ad4f95 std/crypto: add AES-OCB
OCB has been around for a long time.

It's simpler, faster and more secure than AES-GCM.

RFC 7253 was published in 2014. OCB also won the CAESAR competition
along with AEGIS.

It's been implemented in OpenSSL and other libraries for years.

So, why isn't everybody using it instead of GCM? And why don't we
have it in Zig already?

The sad reason for this was patents. GCM was invented only to work
around these patents, and for all this time, OCB was that nice
thing that everybody knew existed but that couldn't be freely used.

That just changed. The OCB patents are now abandoned, and OCB's
author just announced that OCB was officially public domain.
2021-02-28 20:40:49 -08:00
daurnimator
1f17221bc4 std: add sendmsg 2021-02-28 21:57:43 +02:00
Frank Denis
0423f0f7d8 std/crypto/aes: fix AES {encrypt,decrypt}Wide
These functions are  not used by anything yet, but run the last
round only once.
2021-02-28 21:55:58 +02:00
Frank Denis
b959029f88 std/crypto/benchmark: update format strings
Use the s formatter to format strings.
2021-02-28 21:55:24 +02:00
LemonBoy
566adc2510 std: Swap arguments in Thread.spawn
Beside the new order being consistent with the ThreadPool API and making
more sense, this shuffling allows to write the context argument type in
terms of the startFn arguments, reducing the use of anytype (eg. less
explicit casts when using comptime_int parameters, yay).

Sorry for the breakage.

Closes #8082
2021-02-28 14:03:19 +01:00
Andrew Kelley
ab36a162d0 update ARM target CPU features
This completes the process. All target CPU features are now
auto-generated by the tools/update_cpu_features.zig script, which
contains all the overrides.

Invoking this tool against LLVM 12rc2 now produces an empty git diff.
2021-02-27 21:10:00 -07:00
Andrew Kelley
85ab1b01e7 tools/update_cpu_features: add a "flatten" feature
and use it to clean up aarch64 target CPU features
2021-02-27 17:26:06 -07:00
Andrew Kelley
e02acc0288 tools/update_cpu_features: better patching API
With this change, added & modified cpus & features participate in the
same pruning system, and sorting takes into account the zig name, not
the pre-modified llvm name.

The modified target files in this commit are due to the improved
sorting and pruning.

The script now fully supports extra cpus & features.
2021-02-27 15:57:01 -07:00
Michael Dusan
6fe2fb6cdb std.Target.Abi: add gnuilp32 2021-02-27 11:53:08 -08:00
daurnimator
d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
Andrew Kelley
280195038a std.Target: add powerpcle 2021-02-27 02:51:35 -07:00
Andrew Kelley
9e8943736e Merge remote-tracking branch 'origin/master' into llvm12 2021-02-27 02:25:58 -07:00
Andrew Kelley
02bda72d91 update amdgpu target CPU features 2021-02-27 01:54:07 -07:00
Andrew Kelley
a9f19221e9 update RISC-V target CPU features 2021-02-27 01:49:35 -07:00
Andrew Kelley
490654c332 std.ascii: add lessThanIgnoreCase and orderIgnoreCase
For sorting ascii strings, case insensitively.
2021-02-27 01:21:01 -07:00
Andrew Kelley
50a5fc98dc update most target CPU features to llvm12
The tools/update_cpu_features script is coming along, and generates
correct information for all these targets. The remaining targets are:

 * arm
 * aarch64
 * amdgpu
 * riscv

I will commit them once the issues with the updater tool are resolved.
2021-02-27 01:05:53 -07:00
Andrew Kelley
59b4facd34 update x86 CPU features 2021-02-27 00:54:40 -07:00
Andrew Kelley
3f844cba0b std.zig.fmt escaped string formatting recognizes single quote style
This introduces {'} to indicate escape for a single-quoted string,
and {} to indicate escape for a double quoted string.

Without this, there would be unnecessary \' inside double quoted
strings, and unnecessary \" inside single quoted strings.

Motivated by the llvm12 branch, in the new tool I am writing for
updating target CPU features.
2021-02-27 00:27:53 -07:00
Andrew Kelley
03de5ec6dd tools/update_cpu_features: handle ISAs with no features
These are represented by not having a file for them.
2021-02-26 23:52:04 -07:00
Michael Dusan
659f712ae8 llvm12: sync with llvmorg-12.0.0-rc2
- update lib/include
- update lib/libcxx
- update lib/libcxxabi
- update lib/libunwind
- (no changes) src/libcxx.zig
- (no changes) src/libunwind.zig
2021-02-26 13:44:33 -08:00
Andrew Kelley
0b58b61799 Merge remote-tracking branch 'origin/master' into llvm12
Conflicts:
 * src/clang.zig
 * src/llvm.zig
   - this file got moved to src/llvm/bindings.zig in master branch so I
     had to put the new LLVM arch/os enum tags into it.
 * lib/std/target.zig, src/stage1/target.cpp
   - haiku had an inconsistency with its default target ABI, gnu vs
     eabi. In this commit we make it gnu in both places to match the
     latest changes by @hoanga.
 * src/translate_c.zig
2021-02-25 21:04:23 -07:00
Andrew Kelley
4360f45d7f std.os: remove special case for haiku
This is an accident from a merge conflict introduced in
7edb204edf.

The new pipe2 code I believe is supposed to work for all posix-like
systems. If haiku needs special handling here, it should be
re-introduced.
2021-02-25 17:42:14 -07:00
Andrew Kelley
37a1d08de2 haiku: minor fixups
* no isHaiku() function since there is not more than one os tag that
   this applies to.
 * clean up some control flow into a switch
 * add some TODO comments to investigate panics that suspiciously look
   like they should be compile errors (see #363)
2021-02-25 16:54:32 -07:00
Al Hoang
96a08c1698 initial support for haiku defer debug 2021-02-25 16:41:42 -07:00
Al Hoang
c17396691c initial support for haiku sync update
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku
2021-02-25 16:41:42 -07:00
Al Hoang
6b0372229d initial support for haiku continue clean up
* remove unused definitions
* setup os specific blocks
2021-02-25 16:41:42 -07:00
Al Hoang
025635c3f8 initial support for haiku past stage0 2021-02-25 16:41:42 -07:00
Hubert Jasudowicz
3c0238e731 std/build: Add support for LTO configuration 2021-02-25 22:25:42 +02:00
LemonBoy
53cc63f0c9 std: Clear old memory on free
Re-enable the clear-on-free step, it was previously disabled due to
translate-c using freed memory.
2021-02-25 22:20:30 +02:00
Andrew Kelley
9b8a94265a zig fmt: fix extern function with missing param name
Regressed in d7049fc8e0.
2021-02-24 21:50:57 -07:00
Andrew Kelley
5f35dc0c0d zig fmt the std lib 2021-02-24 21:29:23 -07:00
Andrew Kelley
9ada7638a5 zig fmt: function with labeled block as return type 2021-02-24 16:42:46 -07:00
Andrew Kelley
8e6c2b7a47 Merge remote-tracking branch 'origin/master' into ast-memory-layout 2021-02-24 15:08:23 -07:00
Andrew Kelley
38441b5eab MultiArrayList: use @memcpy as a workaround
Reverts bf642204b3 and uses a different
workaround, suggested by @LemonBoy.

There is either a compiler bug or a design flaw somewhere around here.
It does not have to block this branch, but I need to understand exactly
what's going on here and make it so that nobody ever has to run into
this problem again.
2021-02-24 12:49:12 -07:00
Isaac Freund
52c45bf44d
zig fmt: rework single statement if/while/for indentation
This approach properly handles nesting unlike the approach in the
previous commit.
2021-02-24 17:28:29 +01:00
Josh Wolfe
8b9434871e
Avoid concept of a "Unicode character" in documentation and error messages (#8059) 2021-02-24 08:26:13 -05:00
Isaac Freund
371b21bdfb
zig fmt: fix comment indent after multiline single statement if/while/for 2021-02-24 13:46:11 +01:00
Isaac Freund
15c7c6ab97
zig fmt: handle comments in switch case value list 2021-02-24 12:29:17 +01:00
Isaac Freund
1b8eca030e
zig fmt: fix firstToken() for switch_case 2021-02-24 12:14:15 +01:00