4335 Commits

Author SHA1 Message Date
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
7884d84315 std.os.windows: reorg to avoid usingnamespace
Down to 19 uses of `usingnamespace`.
2021-09-01 17:54:06 -07:00
Andrew Kelley
b781ef464d std.os: fix FILENO constants mapped to wrong values
yikes!
2021-09-01 17:54:06 -07:00
Andrew Kelley
7f03cfe161 std.os: more reorganization efforts
* std lib tests are passing on x86_64-linux with and without -lc
 * stage2 is building from source on x86_64-linux
 * down to 38 remaining uses of `usingnamespace`
2021-09-01 17:54:06 -07:00
Andrew Kelley
c09ba8796c std.os.linux: remove the "bits" namespace altogether
Now there is only 1 architecture-specific file for Linux kernel bits.
2021-09-01 17:54:06 -07:00
Andrew Kelley
1bbfcb95ab std: reorganize std.c to eliminate usingnamespace
Behavior tests pass on x86_64-linux with -lc
2021-09-01 17:54:06 -07:00
Andrew Kelley
3deda15e21 std.os reorganization, avoiding usingnamespace
The main purpose of this branch is to explore avoiding the
`usingnamespace` feature of the zig language, specifically with regards
to `std.os` and related functionality.

If this experiment is successful, it will provide a data point on
whether or not it would be practical to entirely remove `usingnamespace`
from the language.

In this commit, `usingnamespace` has been completely eliminated from
the Linux x86_64 compilation path, aside from io_uring.

The behavior tests pass, however that's as far as this branch goes. It is
very breaking, and a lot more work is needed before it could be
considered mergeable. I wanted to put a pull requset up early so that
zig programmers have time to provide feedback.

This is progress towards closing #6600 since it clarifies where the
actual "owner" of each declaration is, and reduces the number of
different ways to import the same declarations.

One of the main organizational strategies used here is to do namespacing
with real namespaces (e.g. structs) rather than by having declarations
share a common prefix (the C strategy). It's no coincidence that
`usingnamespace` has similar semantics to `#include` and becomes much
less necessary when using proper namespaces.
2021-09-01 17:54:06 -07:00
Jan Philipp Hafer
81e2034d4a compiler_rt: add __clzdi2 and __clzti2
- structure derived from shift.zig
- rename clzsi2.zig to count0bits.zig
- test cases derived from clzsi2_test.zig

See #1290
2021-09-01 16:15:21 -04:00
Philip Åkesson
4f0aa7d639 std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
2021-08-31 22:03:54 -04:00
fn ⌃ ⌥
b25e58b0ac
std.hash_map: add getKey methods (#9607) 2021-08-31 00:32:34 -04:00
Lee Cannon
ede47d49eb
Print enum values for build options in help output (#9650) 2021-08-30 21:39:02 -04:00
Boo
ef39725055
Fix float formatting for 0.0 when precision is 0 (#9642) 2021-08-30 13:39:05 -04:00
jdmichaud
49c9975484
zig fmt: respect trailing commas in inline assembly 2021-08-29 11:57:32 +02:00
Andrew Kelley
05cf44933d stage2: delete keywords true, false, undefined, null
The grammar does not need these as keywords; they are merely primitives
provided by the language the same as `void`, `u32`, etc.
2021-08-28 12:10:55 -07:00
Lee Cannon
311797f686
Rework build system build_options API (#9623)
* rework `build_options` to integrate with the FileSource abstraction
* support mapping as an arbitrarily named package
* support mapping to multiple different artifacts
* use hash of contents for options filename
2021-08-26 19:53:23 -04:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Koakuma
dd75302563 Linux/SPARCv9: use C calling convention for restore_rt
This is needed to prevent infinite loop when calling rt_sigreturn.
2021-08-24 14:08:54 -04:00
Koakuma
e3840817d7 Linux/SPARCv9: account for branch delay in freeAndExit() 2021-08-24 14:08:54 -04:00
Frank Denis
8a37fe2176
BoundedArray: a simple way to represent small data whose max size is known (#9134)
This is a simple structure containing an array and a length, that can be viewed as a slice.

It is useful to pass-by-copy small data whose exact size is known at runtime, but whose maximum size is known at comptime. This greatly simplifies code that otherwise would require an allocator, or reimplementing what this type does.
2021-08-24 13:59:28 +02:00
lucky
8c41a8e761
add scrypt kdf (#9577)
add phc encoding parser
add password hash functions to benchmark
change bcrypt to be consistent with scrypt

Co-authored-by: lucky <>
2021-08-24 13:58:09 +02:00
Andrew Kelley
a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
Nguyễn Gia Phong
d5ef5da594
Update comment: s/var/anytype/ (#9611) 2021-08-23 16:22:27 +02:00
William Stein
c465b34d32
Trivial typo "for for" --> "for" (also a few nearby run-on sentence). (#9610) 2021-08-23 08:31:21 +02:00
daurnimator
72c4b80d31
std.os: (p)writev should perform partial writes if iov.len > IOV_MAX
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-08-22 22:22:53 +03:00
Aydin Mercan
e3e6df17ed linux: Add recent clone/clone3 and missing signalfd flags.
The following flags have been introduced:
- CLONE_PIDFD (>=5.2)
- CLONE_INTO_CGROUP (>=5.7)
- SFD_CLOEXEC and SFD_NONBLOCK (>=2.6.27)
2021-08-21 19:41:00 +03:00
Takeshi Yoneda
bbb96e112c build: allow specifying -mexec-model flag.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-21 14:45:42 +03:00
Andrew Kelley
0cd361219c stage2: field type expressions support referencing locals
The big change in this commit is making `semaDecl` resolve the fields if
the Decl ends up being a struct or union. It needs to do this while
the `Sema` is still in scope, because it will have the resolved AIR
instructions that the field type expressions possibly reference. We do
this after the decl is populated and set to `complete` so that a `Decl`
may reference itself.

Everything else is fixes and improvements to make the test suite pass
again after making this change.

 * New AIR instruction: `ptr_elem_ptr`
   - Implemented for LLVM backend
 * New Type tag: `type_info` which represents `std.builtin.TypeInfo`. It
   is used by AstGen for the operand type of `@Type`.
 * ZIR instruction `set_float_mode` uses `coerced_ty` to avoid
   superfluous `as` instruction on operand.
 * ZIR instruction `Type` uses `coerced_ty` to properly handle result
   location type of operand.

 * Fix two instances of `enum_nonexhaustive` Value Tag not handled
   properly - it should generally be handled the same as `enum_full`.
 * Fix struct and union field resolution not copying Type and Value
   objects into its Decl arena.
 * Fix enum tag value resolution discarding the ZIR=>AIR instruction map
   for the child Sema, when they still needed to be accessed.
 * Fix `zirResolveInferredAlloc` use-after-free in the AIR instructions
   data array.
 * Fix `elemPtrArray` not respecting const/mutable attribute of pointer
   in the result type.
 * Fix LLVM backend crashing when `updateDeclExports` is called before
   `updateDecl`/`updateFunc` (which is, according to the API, perfectly
   legal for the frontend to do).
 * Fix LLVM backend handling element pointer of pointer-to-array. It
   needed another index in the GEP otherwise LLVM saw the wrong type.
 * Fix LLVM test cases not returning 0 from main, causing test failures.
   Fixes a regression introduced in
   6a5094872f10acc629543cc7f10533b438d0283a.

 * Implement comptime shift-right.
 * Implement `@Type` for integers and `@TypeInfo` for integers.
 * Implement union initialization syntax.
 * Implement `zirFieldType` for unions.
 * Implement `elemPtrArray` for a runtime-known operand.

 * Make `zirLog2IntType` support RHS of shift being `comptime_int`. In
   this case it returns `comptime_int`.

The motivating test case for this commit was originally:

```zig
test "example" {
    var l: List(10) = undefined;
    l.array[1] = 1;
}

fn List(comptime L: usize) type {
    var T = u8;
    return struct {
        array: [L]T,
    };
}
```

However I changed it to:

```zig
test "example" {
    var l: List = undefined;
    l.array[1] = 1;
}

const List = blk: {
    const T = [10]u8;
    break :blk struct {
        array: T,
    };
};
```

Which ended up being a similar, smaller problem. The former test case
will require a similar solution in the implementation of comptime
function calls - checking if the result of the function call is a struct
or union, and using the child `Sema` before it is destroyed to resolve
the fields.
2021-08-20 15:41:57 -07:00
rgreenblatt
2f1abd919a Fix issue where root.os.panic could return 2021-08-20 19:37:53 +03:00
Dmitry Matveyev
b2e970d157
std.json: Add support for recursive objects to std.json.parse (#9307)
* Add support for recursive objects to std.json.parse

* Remove previously defined error set

* Try with function which returns an error set

* Don't analyze already inferred types

* Add comptime to inferred_type parameter

* Make ParseInternalError to accept only a single argument

* Add public `ParseError` for `parse` function

* Use error.Foo syntax for errors instead of a named error set

* Better formatting

* Update to latest code changes
2021-08-20 14:52:48 +03:00
Tom Maenan Read Cutting
0cecdca6a2 Resolve order-of-call dependencies in build.zig 2021-08-20 13:11:19 +03:00
Veikka Tuominen
b3d3e93636
Merge pull request #9224 from marler8997/defaultLog
A couple std.log conveniences
2021-08-20 12:24:02 +03:00
Samadi van Koten
e94f3c4e25 Add std.io.Reader.readUntilDelimiter() 2021-08-20 12:20:42 +03:00
Isaac Yonemoto
8c39ab2659 enables user-custom code to work with LI and SI 2021-08-20 12:10:45 +03:00
Ryan Liptak
2f6dbaa0ea fs.Dir.walk: Do not close the initial dir during/after walking it
Closing the initial directory was unexpected to me, and does not mesh very well with how the rest of the Dir API works.

Fixes #9556
2021-08-20 10:02:54 +03:00
Justin Whear
62fe4a0ba8
std.rand.Random: add enumValue() (#9583)
* add Random.enumValue()

* edits suggested by review

* applied zig fmt

* Rewrite to use std.enums.values

Implemented pfgithub's suggestion to rewrite against this function, greatly simplifying the implementation.

Co-authored-by: Justin Whear <justin@economicmodeling.com>
2021-08-19 22:18:23 +03:00
Meghan
7e7d67d8ee
std.fmt: add support for printing slices strings (#9562) 2021-08-19 14:12:11 +03:00
Veikka Tuominen
e9bf8014bd
Merge pull request #9559 from squeek502/walker-basename
fs.Dir.Walker: Fix basename missing its first character for direct children of the initial directory
2021-08-14 11:08:10 +03:00
Meghan
fcf2ce0ffe std.fmt: add name of type in unsupport format string compile error 2021-08-14 11:07:01 +03:00
Thom Chiovoloni
c2635f9b02
Fix darwin ulock usage on macOS (#9545)
* Fix darwin ulock usage on macOS

* Fix review comments, and correctly handle timeout overflow on darwin

* Apply more review suggestions
2021-08-13 22:43:42 -05:00
Ayende Rahien
65208a7fa2
Expose register_eventfd, register_eventfd_async, unregister_eventfd i… (#9449)
* Expose register_eventfd, register_eventfd_async, unregister_eventfd in the IO URing API

* Fixing formatting

* Fixing typo

* Removing unnecessary casts and adding better comments for a single registration of eventfd

* Update lib/std/os/linux/io_uring.zig

Co-authored-by: Joran Dirk Greef <joran@coil.com>

* Update lib/std/os/linux/io_uring.zig

Co-authored-by: Joran Dirk Greef <joran@coil.com>

* Updating util function name

Co-authored-by: Joran Dirk Greef <joran@coil.com>
2021-08-13 22:41:18 -05:00
Ryan Liptak
f6bb56f8c7 Improve fs.Walker test
- Take into account that iteration order is undefined by checking against a map instead of relying on numerically sorted iteration order
- Check both path and basename for each entry instead of just path
2021-08-13 16:43:52 -07:00
Ryan Liptak
7e07df06a4 ComptimeStringMap: expose kvs array in returned struct
Allows for iterating over the kvs when constructing with a list literal instead of having to create a separate array to pass into ComptimeStringMap in order to maintain access to the values.

For example when making a set, before in order to loop over the kvs you'd have to do something like:

    const MyKV = struct { @"0": []const u8 };
    const kvs: []const MyKV = &[_]MyKV{ .{ @"0" = "foo"}, .{ @"0" = "bar" } };
    const map = ComptimeStringMap(void, kvs);
    for (kvs) |kv| {}

whereas now it's possible to do:

    const map = ComptimeStringMap(void, .{ .{"foo"}, .{"bar"} });
    for (map.kvs) |kv| {}
2021-08-13 16:22:56 -07:00
Ryan Liptak
8ff49966bc fs.Walker: Fix basename missing its first character for direct children of the initial directory
Closes #9557
2021-08-13 16:22:56 -07:00
Jakub Konka
1373df4c34
Merge pull request #9227 from mathetake/libc-wasi-test
WASI,libc: fix libstd with wasi-libc linkage, and enable tests.
2021-08-13 21:56:32 +02:00
Takeshi Yoneda
68617c9fb0 Add comment about compiletime check.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-13 21:54:18 +09:00
Takeshi Yoneda
ca4898c0f3 Use std.buuiltin instead of importing builtin
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-13 21:49:52 +09:00
Andrew Kelley
fc55814faa compiler-rt: do not depend on usingnamespace
The idea is to depend on this language feature as little as possible
with the hopes that it can be adjusted to be less of an anti-pattern.
This also helps self-hosted, which does not yet implement
`usingnamespace`, get closer to being able to build compiler-rt.
2021-08-12 10:48:54 -07:00
Ryan Liptak
493822ac3b Update mem.split/mem.tokenize doc comments
Follow up to #9531
2021-08-11 21:19:03 -04:00
Jakub Konka
e9bee08f88 Try audodetecting sysroot when building Darwin on Darwin
This is now no longer limited to targeting macOS natively but also
tries to detect the sysroot when targeting different Apple platforms
from macOS; for instance targeting iPhone Simulator from macOS. In
this case, Zig will try detecting the SDK path by invoking
`xcrun --sdk iphonesimulator --show-sdk-path`, and if the command
fails because the SDK doesn't exist (case when having CLT installed only)
or not having either Xcode or CLT installed, we simply return null
signaling that the user has to provide the sysroot themselves.
2021-08-10 13:41:10 +02:00
Jakub Konka
7007684984 macho: swap out VERSION_MIN for BUILD_VERSION
this makes the app successfully run on the iOS simluator!
2021-08-10 13:41:10 +02:00