There's an unfortunate footgun in the current design of error sets.
The debug info type for every error set is the same as the debug info
type of the global error set, which is essentially an enum forward
declaration. The problem is that when we "replace" the forward
declaration with the final value, once we know all the possible errors,
we have to update the pointers of every error set.
So the footgun is that if you ever copy the debug info type of the
global error set, you have to add the address of the pointer to a list
of pointers that need to be updated once we "replace" the forward
declaration. I activated the footgun when I introduced the optimization
that `?anyerror` types are the same size as `anyerror` types (using 0 as
the null value), because I introduced a pointer copy of the global error
set debug info type, but forgot to add it to the list.
I'm sure that there is a better way to code this, which does not have
the footgun, but this commit contains only a fix, not a reworking of the
logic.
closes#1937
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.
This makes release mode test builds more accurately test
the actual code that will be run.
However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.
Here is the explanation of when to use either one, copied from
the assert doc comments:
Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.
closes#1304
* zig fmt
* std.mem.join takes a slice of slices instead of var args
* std.mem.join takes a separator slice rather than byte,
and always inserts it. Previously it would not insert the separator
if there already was one, violating the documented behavior.
* std.mem.join calculates exactly the correct amount to allocate
and has no call to allocator.shrink()
* bring back joinWindows and joinPosix and the corresponding tests.
it is intended to be able to call these functions from any OS.
* rename std.os.path.resolveSlice to resolve (now resolve takes
a slice of slices instead of var args)
this should actually improve CI times a bit too
See the description at the top of std/os/startup.zig (deleted in this
commit) for a more detailed understanding of what this commit does.
`std.mem.Allocator.createOne` is renamed to `std.mem.Allocator.create`.
The problem with the previous API is that even after copy elision,
the initalization value passed as a parameter would always be a copy.
With the new API, once copy elision is done, initialization
functions can directly initialize allocated memory in place.
Related:
* #1872
* #1873
closes#1764
This adds another boolean to the test matrix; hopefully it does not
inflate the time too much.
std.event.Loop does not work with this option yet. See #1908
Previously, it pointed to the start of the current token, but this made
it difficult to tell where the error occurred when it was, say, in the
middle of a string.
This commit contains everything from the copy-elision-2
branch that does not have to do with copy elision directly,
but is generally useful for master branch.
* All const values know their parents, when applicable, not
just structs and unions.
* Null pointers in const values are represented explicitly,
rather than as a HardCodedAddr value of 0.
* Rename "maybe" to "optional" in various code locations.
* Separate DeclVarSrc and DeclVarGen
* Separate PtrCastSrc and PtrCastGen
* Separate CmpxchgSrc and CmpxchgGen
* Represent optional error set as an integer, using the 0 value.
In a const value, it uses nullptr.
* Introduce type_has_one_possible_value and use it where applicable.
* Fix debug builds not setting memory to 0xaa when storing
undefined.
* Separate the type of a variable from the const value of a variable.
* Use copy_const_val where appropriate.
* Rearrange structs to pack data more efficiently.
* Move test/cases/* to test/behavior/*
* Use `std.debug.assertOrPanic` in behavior tests instead of
`std.debug.assert`.
* Fix outdated slice syntax in docs.
* bitreverse - give bswap behavior
* bitreverse, comptime_ints, negative values still not working?
* bitreverse working for negative comptime ints
* Finished bitreverse test cases
* Undo exporting a bigint function. @bitreverse test name includes ampersand
* added docs entry for @bitreverse
* add `@bswap` builtin function. See #767
* comptime evaluation facilities are improved to be able to
handle a `@ptrCast` with a backing array.
* `@truncate` allows "truncating" a u0 value to any integer
type, and the result is always comptime known to be `0`.
* when specifying pointer alignment in a type expression,
the alignment value of pointers which do not have addresses
at runtime is ignored, and always has the default/ABI alignment
* threw in a fix to freebsd/x86_64.zig to update syntax from
language changes
* some improvements are pending #863closes#638closes#1733
std lib API changes
* io.InStream().readIntNe renamed to readIntNative
* io.InStream().readIntLe renamed to readIntLittle
* io.InStream().readIntBe renamed to readIntBig
* introduced io.InStream().readIntForeign
* io.InStream().readInt has parameter order changed
* io.InStream().readVarInt has parameter order changed
* io.InStream().writeIntNe renamed to writeIntNative
* introduced io.InStream().writeIntForeign
* io.InStream().writeIntLe renamed to writeIntLittle
* io.InStream().writeIntBe renamed to writeIntBig
* io.InStream().writeInt has parameter order changed
* mem.readInt has different parameters and semantics
* introduced mem.readIntNative
* introduced mem.readIntForeign
* mem.readIntBE renamed to mem.readIntBig and different API
* mem.readIntLE renamed to mem.readIntLittle and different API
* introduced mem.readIntSliceNative
* introduced mem.readIntSliceForeign
* introduced mem.readIntSliceLittle
* introduced mem.readIntSliceBig
* introduced mem.readIntSlice
* mem.writeInt has different parameters and semantics
* introduced mem.writeIntNative
* introduced mem.writeIntForeign
* mem.writeIntBE renamed to mem.readIntBig and different semantics
* mem.writeIntLE renamed to mem.readIntLittle and different semantics
* introduced mem.writeIntSliceForeign
* introduced mem.writeIntSliceNative
* introduced mem.writeIntSliceBig
* introduced mem.writeIntSliceLittle
* introduced mem.writeIntSlice
* removed mem.endianSwapIfLe
* removed mem.endianSwapIfBe
* removed mem.endianSwapIf
* added mem.littleToNative
* added mem.bigToNative
* added mem.toNative
* added mem.nativeTo
* added mem.nativeToLittle
* added mem.nativeToBig
* codegen: LLVMConstInlineAsm is deprecated.
* codegen: replace commas in asm constraint strings by pipes as required by LLVM.
* ir: enforce usage of '=' constraint modifier for inline assembly outputs.
Others are not currently supported and this was just asserted alter in `ir_render_asm`.
* asm: forbid comptime_int/floats as inputs in favor of explicitely sized constants.
Fixes a crash due to comptime_int/floats having no type_ref.
* asm: handle inputs with integers of <8 or non power of 2 bitsize.
We widen them to the next highest power of two.
We were caching the ConstExprValue of string literals,
which works if you can never modify ConstExprValues.
This premise is broken with `comptime var ...`.
So I implemented an optimization in ConstExprValue
arrays, where it stores a `Buf *` directly rather
than an array of ConstExprValues for the elements,
and then similar to array of undefined, it is
expanded into the canonical form when necessary.
However many operations can happen directly on the
`Buf *`, which is faster.
Furthermore, before a ConstExprValue array is expanded
into canonical form, it removes itself from the string
literal cache. This fixes the issue, because before an
array element is modified it would have to be expanded.
closes#1076
init-lib creates a working static library with tests, and
init-exe creates a working hello world with a `run` target.
both now have test coverage with the new "cli tests" file.
closes#1035
closes#1381
The union was generated as a 3 byte struct when it needed to be
4 bytes so that the packed struct bitcast could work correctly.
Now it recognizes this situation and adds padding bytes to become
the correct size so that it can fit into an array.
* error.BadFd is not a valid error code. it would always be a bug to
get this error code.
* merge error.Io with existing error.InputOutput
* merge error.PathNotFound with existing error.FileNotFound.
Not all OS's support both.
* add os.File.openReadC
* add error.BadPathName for windows file operations with invalid
characters
* add os.toPosixPath to help stack allocate a null terminating byte
* add some TODOs for other functions to investigate removing the
allocator requirement
* optimize some implementations to use the alternate functions when
a null byte is already available
* add a missing error.SkipZigTest
* os.selfExePath uses a non-allocating API
* os.selfExeDirPath uses a non-allocating API
* os.path.real uses a non-allocating API
* add os.path.realAlloc and os.path.realC
* convert many windows syscalls to use the W versions (See #534)
ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.
test/translate_c.zig: enum: add wider range of values (u64) to try;
This reverts commit b8ce8f219c.
Squashing the commits from the pull request resulted in kristopher tate
from being omitted from the authors. A future commit will merge
the code correctly.
* translate-c: Correctly translate enum init values
* translate-c: Test enum initialization
* translate-c: Flip to positive using APSInt builtins
* src/translate_c.cpp: correctly bridge llvm::APSInt with Zig BigInt;
ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.
* test/translate_c.zig: enum: add wider range of values (u64) to try;
closes#1360
* fix race condition in std.event.Channel deinit
* add support to zig build for --no-rosegment
* add passing self-hosted compare-output test for calling a function
* put a global lock on LLD linking because it's not thread safe