997 Commits

Author SHA1 Message Date
Jonathan Marler
e0ef61d46d simplify ContainerDeclarations grammar rule
Noticed this grammar rule could be simplified using a repeating sequence
rather than recursion.
2023-09-28 14:18:54 +03:00
Jonathan Marler
18f1db134c docs: remove unnecessary nesting in grammar
noticed this extra level of nesting in the Decl grammar that looks
unnecssary.
2023-09-28 13:58:14 +03:00
antlilja
8191199951 fmt: add rewrite from @fabs to @abs 2023-09-27 11:24:45 -07:00
antlilja
bcf4a13913 Remove @fabs, fabs and absCast/Int from std lib
Replaces occurences of @fabs absCast and absInt with new @abs builtin.
Also removes the std.math.fabs alias from math.zig.
2023-09-27 11:24:28 -07:00
Andrew Kelley
3fc7413574
Merge pull request #17069 from squeek502/resinator
Add a `.rc` -> `.res` compiler to the Zig compiler
2023-09-22 12:18:50 -07:00
Andrew Kelley
62a12e0631 LLVM 17 std lib updates and fixes
* some manual fixes to generated CPU features code. in the future it
   would be nice to make the script do those automatically. I suspect
   the sm_90a thing is a bug in LLVM.
 * add liteos to various target OS switches. I know nothing about this
   OS; someone will need to work specifically on support for this OS
   when the time comes to support it properly in zig.
 * while waiting for the compiler, I went ahead and made more
   conservative choices about when to use `inline` in std/Target.zig
2023-09-19 09:37:31 -07:00
r00ster91
ee4ced9683 write function types consistently with a space before fn keyword
Currently, the compiler (like @typeName) writes it `fn(...) Type` but
zig fmt writes it `fn (...) Type` (notice the space after `fn`).
This inconsistency is now resolved and function types are consistently
written the zig fmt way. Before this there were more `fn (...) Type`
occurrences than `fn(...) Type` already.
2023-09-19 15:15:05 +03:00
Banacial
d2a937838e
std.zig.c_translation.zig: fix L suffix with sized ints
Closes #15066
2023-09-18 13:27:32 +03:00
Ryan Liptak
8e35be0640 ErrorBundle: rename addBundle to addBundleAsNotes, add addBundleAsRoots 2023-09-15 23:36:44 -07:00
Ryan Liptak
fc69529dab ErrorBundle.addOtherSourceLocation: Fix source_line ending up as garbage when source_line is 0
The zero value needs special handling since it means 'no source line' and should be preserved through the copy.
2023-09-15 23:36:44 -07:00
mlugg
88f5315ddf compiler: implement destructuring syntax
This change implements the following syntax into the compiler:

```zig
const x: u32, var y, foo.bar = .{ 1, 2, 3 };
```

A destructure expression may only appear within a block (i.e. not at
comtainer scope). The LHS consists of a sequence of comma-separated var
decls and/or lvalue expressions. The RHS is a normal expression.

A new result location type, `destructure`, is used, which contains
result pointers for each component of the destructure. This means that
when the RHS is a more complicated expression, peer type resolution is
not used: each result value is individually destructured and written to
the result pointers. RLS is always used for destructure expressions,
meaning every `const` on the LHS of such an expression creates a true
stack allocation.

Aside from anonymous array literals, Sema is capable of destructuring
the following types:
* Tuples
* Arrays
* Vectors

A destructure may be prefixed with the `comptime` keyword, in which case
the entire destructure is evaluated at comptime: this means all `var`s
in the LHS are `comptime var`s, every lvalue expression is evaluated at
comptime, and the RHS is evaluated at comptime. If every LHS is a
`const`, this is not allowed: as with single declarations, the user
should instead mark the RHS as `comptime`.

There are a few subtleties in the grammar changes here. For one thing,
if every LHS is an lvalue expression (rather than a var decl), a
destructure is considered an expression. This makes, for instance,
`if (cond) x, y = .{ 1, 2 };` valid Zig code. A destructure is allowed
in almost every context where a standard assignment expression is
permitted. The exception is `switch` prongs, which cannot be
destructures as the comma is ambiguous with the end of the prong.

A follow-up commit will begin utilizing this syntax in the Zig compiler.

Resolves: #498
2023-09-15 11:33:53 -07:00
Rafael Fernández López
69982339ed std: add compile error when using std.os.getenv on the wasi target
`std.process.getEnvMap` or `std.process.getEnvVarOwned` should be used
instead, requiring allocation.
2023-09-14 20:04:35 +03:00
Jakub Konka
3b2b9fcbc5 darwin: move inference of SDK version into the linker
`std.zig.system.darwin.getSdk` now pulls only the SDK path
so we execute a child process only once and not twice as it was
until now since we parse the SDK version directly from the pulled path.
This is actually how `ld64` does it too.
2023-08-29 06:43:41 +02:00
Jacob Young
750998eef6 Build: fail tests that log errors, like zig test does 2023-08-25 15:36:25 -07:00
Ryan Liptak
e078324dbe Add NetworkNotFound to ReadLinkError
This matches how other filesystem functions were made to handle BAD_NETWORK_PATH/BAD_NETWORK_NAME in https://github.com/ziglang/zig/pull/16568. ReadLink was the odd one out, but that is no longer the case.
2023-08-18 18:07:16 -07:00
Lewis Gaul
387b0ac4f1
Make NaNs quiet by default and other NaN tidy-up (#16826)
* Generalise NaN handling and make std.math.nan() give quiet NaNs

* Address uses of std.math.qnan_* and std.math.nan_* consts

* Comment out failing test due to issues with signalling NaN

* Fix issue in c_builtins.zig where we need qnan_u32
2023-08-18 02:07:49 -04:00
Andrew Kelley
d0fd67cffe std.zig.system.NativePaths: remove bad framework dir
This path actually has nothing useful in it.
2023-08-03 09:52:15 -07:00
Andrew Kelley
c012f5d55d std.zig.system.darwin.isSdkInstalled: fix implementation
* don't assert that the child process doesn't crash
* don't give a false negative on warnings printed to stderr

Also fix getSdk from the same file in the same way
2023-08-03 09:52:15 -07:00
Andrew Kelley
e582a3642b std.zig.system.darwin: fix redundant names 2023-08-03 09:52:15 -07:00
Andrew Kelley
c94bbebb91 std.zig.system.NativePaths: simplify and integrate with Darwin SDK 2023-08-03 09:52:15 -07:00
Jakub Konka
20f4216af5 macos: fix parsing of SDK version string into std.SemanticVersion 2023-07-28 21:13:56 +02:00
techatrix
7e25fb4a43 add bound check on for and while nodes 2023-07-28 00:20:53 -07:00
Ryan Liptak
9a3adeea6e windows.OpenFile/DeleteFile: Add NetworkNotFound as a possible error
When calling NtCreateFile with a UNC path, if either `\\server` or `\\server\share` are not found, then the statuses `BAD_NETWORK_PATH` or `BAD_NETWORK_NAME` are returned (respectively).

These statuses are not translated into `error.FileNotFound` because they convey more information than the typical FileNotFound error. For example, if you were trying to call `Dir.makePath` with an absolute UNC path like `\\MyServer\MyShare\a\b\c\d`, then knowing that `\\MyServer\MyShare` was not found allows for returning after trying to create the first directory instead of then trying to create `a\b\c`, `a\b`, etc. when it's already known that they will all fail in the same way.
2023-07-27 09:35:29 -07:00
Wooster
b5a471db3c ErrorBundle: remove extra newline
This is another minor change but still makes a visual difference and will reduce the amount you have to scroll in your terminal by a little bit.

Reasoning:
1. The `for (0..src.data.reference_trace_len)` loop will run at least once due to the `src.data.reference_trace_len > 0` check above.
2. In all 3 branches of the `if` in that `for` it will print something.
3. The 3 strings of all of those prints already end in `\n`.
Therefore, the extra `try stderr.writeByte('\n');` is unnecessary.
2023-07-25 11:05:14 -07:00
Zachary Raineri
d82b359010 Use builtin inference over @as where possible 2023-07-24 10:23:51 -07:00
Andrew Kelley
23a806102a Revert "zig fmt: additionally auto-fix @byteSwap (#16462)"
This reverts commit f31e114f633f5d57f6d09a616f5997d83949f641.

This commit was incorrect; `@byteSwap` was not modified during the
0.11.0 release cycle.
2023-07-23 20:30:34 -07:00
Zachary Raineri
7dcbabef51
std.zig.Parse: Fix assertion (#16500)
The assert was copied from a few lines above without updating the target variable.
2023-07-23 20:18:02 -04:00
iacore
f31e114f63
zig fmt: additionally auto-fix @byteSwap (#16462) 2023-07-22 01:42:39 -04:00
Eric Joldasov
0a868dacdd std.cstr: deprecate namespace
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-25 14:51:03 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
mlugg
283d650973 fmt: add rewrite for cast builtin type parameters 2023-06-24 16:47:49 -07:00
r00ster91
d82ab4fd8a ErrorBundle: fix integer overflow printing caret 2023-06-23 23:58:21 -07:00
Michael Dusan
1cf06706be openbsd: fix NativeTargetInfo semver
- supply ".0" as .Z component and satisfy semver X.Y.Z requirement
- previously only X.Y was supplied and semver parse failed
2023-06-23 23:41:29 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Eric Joldasov
a6c8ee5231 compiler: rename "@XToY" to "@YFromX", zig fmt: rewrite them
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:24 -07:00
r00ster91
6e84f46990 std: replace builtin.Version with SemanticVersion 2023-06-17 13:17:34 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Jan200101
d7b73af8f6 Never implicitly add rpaths for each lib dir, add NixOS libdir to rpath 2023-06-13 11:11:10 -07:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
Evin Yulo
6c2f374556 Use the word 'base' consistently instead of 'radix' 2023-06-01 00:02:16 +03:00
Veikka Tuominen
ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
Linus Groh
0f6fa3f20b std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.tty
Also get rid of the TTY wrapper struct, which was exlusively used as a
namespace - this is done by the tty.zig root struct now.

detectTTYConfig has been renamed to just detectConfig, which is enough
given the new namespace. Additionally, a doc comment had been added.
2023-05-24 10:15:02 +01:00
Linus Groh
39c2eee285 std.debug: Rename TTY.Color enum values to snake case 2023-05-24 10:15:02 +01:00
Ryan Liptak
104f4053a2 std.mem: Rename splitFull/tokenizeFull to splitSequence/tokenizeSequence
I think this makes the name less ambiguous and more obvious that the suffix applies to the `delimiter`.
2023-05-13 13:45:05 -07:00
Ryan Liptak
2129f28953 Update all std.mem.split calls to their appropriate function
Everywhere that can now use `splitScalar` should get a nice little performance boost.
2023-05-13 13:45:05 -07:00
Ryan Liptak
815e53b147 Update all std.mem.tokenize calls to their appropriate function
Everywhere that can now use `tokenizeScalar` should get a nice little performance boost.
2023-05-13 13:45:04 -07:00
Dominic
5a3eca5d4c
Disallow named test decls with duplicate names 2023-05-08 10:59:06 +03:00
Jacob Young
bac3a28214 fmt: avoid canonicalizing enum fields named @"_" to _
This can be used to escape the usual meaning of `_` to indicate a
non-exhaustive enum and create an enum tag that is a literal underscore,
so zig fmt should allow this syntax.

Before, zig fmt changes

    const E = enum { @"_" };

to the semantically different

    const E = enum { _ };

After, it remains the same.
2023-05-08 10:58:31 +03:00
Dominic
e1f5ad3cc8
Fix parsing of hexadecimal literals 2023-05-07 08:05:53 +00:00
Linus Groh
94e30a756e std: fix a bunch of typos
The majority of these are in comments, some in doc comments which might
affect the generated documentation, and a few in parameter names -
nothing that should be breaking, however.
2023-04-30 18:16:04 -07:00