Commit Graph

3705 Commits

Author SHA1 Message Date
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
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
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
daurnimator
d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02: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
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
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
Andrew Kelley
db4c15be50 zig fmt: respect extra newline between fn and pub usingnamespace 2021-02-23 23:01:16 -07:00
Andrew Kelley
bf642204b3 std.MultiArrayList: add workaround for LLVM bug 2021-02-23 22:24:59 -07:00
Andrew Kelley
05f304807f zig fmt: add 3 more disabled failing test cases
Found by running `zig fmt` on the std lib.
2021-02-23 18:48:01 -07:00
Andrew Kelley
4420fe97be zig fmt: for loop with ptr payload and index 2021-02-23 18:33:13 -07:00
Andrew Kelley
988f1c6a6f zig fmt: fn proto end with anytype and comma
also

zig fmt: space after top level doc comment
2021-02-23 18:23:49 -07:00
Andrew Kelley
08107a555e zig fmt: fix inline assembly test cases
All zig fmt test cases are now passing again in this branch.
2021-02-23 17:19:01 -07:00
Andrew Kelley
bb89c619ed zig fmt: multiline string literals + array init 2021-02-23 17:00:33 -07:00
Andrew Kelley
6f4a1bafcf zig fmt: fn call with comments and multiline strings
forcing the parameters over multiple lines
2021-02-23 16:09:51 -07:00
Isaac Freund
4ee368c4b3
zig fmt: comments/line breaks in field access chain 2021-02-23 23:17:38 +01:00
Andrew Kelley
ca9259340d zig fmt now intentionally respects all empty line comments 2021-02-23 14:30:21 -07:00
Isaac Freund
b028a92a60
zig fmt: handle comments in array type/init/access 2021-02-23 19:56:56 +01:00
Isaac Freund
abfe213830
zig fmt: enable array init trailing comment insertion test
Modify the test case slightly to match similar modifications done in
5820bd0 and 0f24b61.
2021-02-23 19:40:34 +01:00
Isaac Freund
6b9f19a644
zig fmt: remove stray std.debug.print() 2021-02-23 19:18:36 +01:00
Isaac Freund
0f24b61ed5
zig fmt: insert trailing comma in struct init with comment 2021-02-23 19:17:11 +01:00
Isaac Freund
5820bd0e64
zig fmt: insert trailing comma in fn params with comment 2021-02-23 19:11:50 +01:00
Isaac Freund
5306b1a9ab
zig fmt: container doc comments 2021-02-23 18:32:47 +01:00
johnLate
d9e46dceec std.Thread.Semaphore: Fix wrong variable name
Fixes ziglang#8052
2021-02-23 11:10:24 +02:00
Andrew Kelley
1e3a200ba6 zig fmt: array literal with hint
This regresses the test case of `zig fmt` deleting empty line comments.
Two open questions here:

 * What should the rules be about deleting empty line comments?
   It makes sense usually, but for array initization, empty line
   comments cause a line break, affecting the row/column alignment.
   Perhaps we should therefore respect all empty line comments?
   Or should we special case array initializations?

 * If we decide to special case some kinds of line comments to respect
   them (which is status quo!), how should that be implemented?
2021-02-22 23:25:12 -07:00
Andrew Kelley
1253903fef zig fmt: struct literal containing a multiline expression
I modified this test case to expect different results.

Now, the trailing comma on a list of struct fields is the only deciding
factor, not whether or not the field init expressions contain a newline.
2021-02-22 21:33:21 -07:00
Andrew Kelley
8379fff804 zig fmt: alignment in anonymous literal 2021-02-22 21:04:22 -07:00
Andrew Kelley
a6038f0375 zig fmt: function params should align nicely 2021-02-22 18:17:26 -07:00
Andrew Kelley
fec51ad7c5 zig fmt: while 2021-02-22 17:55:19 -07:00
Andrew Kelley
20cfa0b5b6 zig fmt: if condition has line break, no fn call comma 2021-02-22 17:34:30 -07:00
Andrew Kelley
ec987a7a46 zig fmt: if condition has line break but must not wrap 2021-02-22 16:39:50 -07:00
Andrew Kelley
b301999cd3 zig fmt: if condition wraps 2021-02-22 16:21:19 -07:00
Andrew Kelley
253906fb93 zig fmt: 2nd arg multiline string 2021-02-22 16:00:21 -07:00
Isaac Freund
45634851de
zig fmt: fix firstToken() for extern fn_protos 2021-02-22 23:51:54 +01:00
Isaac Freund
550688f427
zig fmt: insert trailing comma in switches 2021-02-22 23:51:54 +01:00
Isaac Freund
f3ee10b454
zig fmt: fix comments ending with EOF after decls
Achieve this by reducing the amount of special casing to handle EOF so
that the already correct logic for normal comments does not need to be
duplicated.
2021-02-22 18:32:37 +01:00
Isaac Freund
ce9b3ee0f9
parser: anytype is not a vaild return type 2021-02-22 17:38:09 +01:00
Isaac Freund
34c08a91d5
zig fmt: fix formatting of parser tests 2021-02-22 17:37:17 +01:00
Veikka Tuominen
928790364a
zig fmt: correct Node.firstToken for .fn_decl, add error for missing container 2021-02-22 17:39:41 +02:00
Veikka Tuominen
69d5a106da
render: handle comments ending in EOF 2021-02-22 16:59:44 +02:00
Veikka Tuominen
67dac2936c
parser: warn on missing for loop payload, recover from invalid global error set access 2021-02-22 10:04:05 +02:00
Andrew Kelley
621ad241d6 zig fmt: if nested 2021-02-21 20:25:31 -07:00
Andrew Kelley
c6efb23796 zig fmt: rewrite inline functions as callconv(.Inline) 2021-02-21 18:20:46 -07:00
Andrew Kelley
878e99d580 parser: fix recovery for missing semicolons 2021-02-21 18:04:23 -07:00
Andrew Kelley
1247b7b9ef parser: modify another recovery test case
Zig no longer has `error` as the global error set; it is now a special
case keyword. The new parse error message is correct.
2021-02-21 18:00:37 -07:00
Andrew Kelley
79f1876367 parser: remove support for recovering from extra top level end curlies
After #35 is implemented,
we should be able to recover from this *at any indentation level*,
reporting a parse error and yet also parsing all the decls even
inside structs. Until then, I don't want to add any hacks to make
this work.
2021-02-21 17:57:04 -07:00
Andrew Kelley
2da2123128 parser: remove support for a recovery test case
I don't understand the idea here of this kind of recovery. If we
want to resurrect this test case we need some comments on it to explain
the purpose, example use cases, expected behavior, etc.
2021-02-21 17:37:39 -07:00
Andrew Kelley
866f7dc7d6 parser: support more recovery test cases 2021-02-21 17:37:10 -07:00
Andrew Kelley
15603f403c AST: use fn_proto not fn_decl for extern decls
saves a few bytes per extern function declaration
2021-02-21 16:01:22 -07:00
ducdetronquito
0aef1faa82 std.fifo.LinearFifo - Expose reader and writer type. 2021-02-22 00:22:46 +02:00
Ryan Greenblatt
36178caf3e
Added support for passing write file args as build options (#7909)
* Added support for passing write file args as build options

* Fix missing fmtEscapes and unused format

* Actually fixed now, must be formatted

* remove addPathBuildOption
2021-02-21 12:26:46 +02:00
Veikka Tuominen
ef6aa3d027
Merge pull request #7960 from Luukdegram/wasm-extern
stage2: Add support for extern functions for the wasm backend
2021-02-21 12:22:01 +02:00
LemonBoy
057bf1afc9 std: Add more error checking in hexToBytes
Prevent the function from turning into an endless loop that may or may
not perform OOB accesses.
2021-02-21 12:19:03 +02:00
Asherah Connor
4272f07f66
std.os.uefi.Guid fixes (#8032)
* uefi: Guid.format compiles again

Also use "writer" nomenclature in argument name.

* uefi: add Guid.eql
2021-02-21 12:17:59 +02:00
Bill Nagel
cc5e5cca83 fix race condition in linuxWaitFd 2021-02-21 12:16:48 +02:00
jacob gw
1bd434fd18 std.Progress: improve support for "dumb" terminals 2021-02-21 12:12:17 +02:00
Tau
840331ee48 Rebase link(at) properly 2021-02-21 12:04:40 +02:00
Benjamin Graf
c70832bc41 replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00
Jonathan Marler
a448210fcf remove z/Z format specifier deprecations
The z/Z format specifiers were merged last October (4 months ago).  They were then deprecated in January (just over a month ago).  This PR removes them altogether.
2021-02-21 11:55:21 +02:00
rgreenblatt
f9be7471bc fix readable slice bug (and add tests) 2021-02-21 11:48:38 +02:00
data-man
340825a7af Add epoll_pwait2 Linux syscall 2021-02-21 11:47:13 +02:00
Andrew Kelley
88d0e77b97 parse: implement error for invalid bit range and alignment 2021-02-21 00:18:20 -07:00
rgreenblatt
a5dcd07382 fix unspecified fmt 2021-02-21 01:31:46 +02:00
Andrew Kelley
ed1e5cb3f6 stage2: fix a couple off by one errors
All stage2 tests are passing again in this branch.

Remaining checklist for this branch:
 * get the rest of the zig fmt test cases passing
   - re-enable the translate-c test case that is blocking on this
 * implement the 2 `@panic(TODO)`'s in parse.zig
 * use fn_proto not fn_decl for extern function declarations
2021-02-19 21:47:11 -07:00
Andrew Kelley
d8560edc29 stage2: fix incorrect ast.Tree.getNodeSource impl 2021-02-19 20:28:47 -07:00
Andrew Kelley
8fee41b1d5 stage2: AST: clean up parse errors
* struct instead of tagged union
 * delete dead code
 * simplify parser code
 * remove unnecessary metaprogramming
2021-02-19 18:04:52 -07:00
Isaac Freund
95b95ea33e
stage2: make same line doc comments a parse error
Allowing same line doc comments causes some ambiguity as to how
generated docs should represent the case in which both same line
and preceding line doc comments are present:

/// preceding line
const foobar = 42; /// same line

Furthermore disallowing these makes things simpler as there is now only
one way to add a doc comment to a decl or struct field.
2021-02-19 22:59:27 +01:00
Veikka Tuominen
d672c20b8a
Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Andrew Kelley
9010bd8aec stage2: astgen: fix most of the remaining compile errors
more progress on converting astgen to the new AST memory layout.
only a few code paths left to update.
2021-02-18 20:09:29 -07:00
Andrew Kelley
29daf10639 stage2: fix a couple more compilation errors 2021-02-17 22:34:06 -07:00
Andrew Kelley
c66481f9bc astgen: finish updating expressions to new mem layout
Now all that is left is compile errors and whatever regressions this
branch introduced.
2021-02-17 20:59:21 -07:00
Isaac Freund
4b226286e8
zig fmt: get rid of Space.no_comment
Using this in its current state would be a bug as it could cause line
comments to be deleted or a `// zig fmt: (on|off)` directive to be
missed.

Removing it doesn't currently cause any test failures, if a reason for
its continued existence is discovered in the future another solution
will have to be found.
2021-02-17 00:03:39 +01:00
Isaac Freund
895fb2bd6d
zig fmt: implement 'zig fmt: (on|off)' directives
With the new implementation, these now work anywhere in the source code
as opposed to only at the top level.
2021-02-16 23:20:53 +01:00
Isaac Freund
070e548acf
std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Andrew Kelley
68e7726478 std.fs.net.Stream: add writev and writevAll
I noticed that the write function does not properly use non-blocking
I/O. This file needs to be reworked for evented I/O to properly take
advantage of non-blocking writes to network sockets.
2021-02-16 11:01:17 -07:00
Veikka Tuominen
78fba4e021
translate-c: get all run-translated-c tests passing 2021-02-16 16:40:43 +02:00