Skip to content

Commit

Permalink
Merge branch 'master' into patch-json
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgithub authored Sep 7, 2024
2 parents c64ca0a + 5f3d9e0 commit 3a1ea6a
Show file tree
Hide file tree
Showing 443 changed files with 11,730 additions and 8,048 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ concurrency:
# Cancels pending runs when a PR gets updated.
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: true
permissions:
# Sets permission policy for `GITHUB_TOKEN`
contents: read
jobs:
x86_64-linux-debug:
timeout-minutes: 420
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ set(ZIG_STAGE2_SOURCES
src/link/Elf.zig
src/link/Elf/Archive.zig
src/link/Elf/Atom.zig
src/link/Elf/AtomList.zig
src/link/Elf/LdScript.zig
src/link/Elf/LinkerDefined.zig
src/link/Elf/Object.zig
Expand All @@ -613,7 +614,7 @@ set(ZIG_STAGE2_SOURCES
src/link/Elf/relocatable.zig
src/link/Elf/relocation.zig
src/link/Elf/synthetic_sections.zig
src/link/Elf/thunks.zig
src/link/Elf/Thunk.zig
src/link/MachO.zig
src/link/MachO/Archive.zig
src/link/MachO/Atom.zig
Expand All @@ -638,7 +639,7 @@ set(ZIG_STAGE2_SOURCES
src/link/MachO/load_commands.zig
src/link/MachO/relocatable.zig
src/link/MachO/synthetic.zig
src/link/MachO/thunks.zig
src/link/MachO/Thunk.zig
src/link/MachO/uuid.zig
src/link/NvPtx.zig
src/link/Plan9.zig
Expand Down
18 changes: 18 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,24 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
.strip = options.strip,
.sanitize_thread = options.sanitize_thread,
.single_threaded = options.single_threaded,
.code_model = switch (options.target.result.cpu.arch) {
// NB:
// For loongarch, LLVM supports only small, medium and large
// code model. If we don't explicitly specify the code model,
// the default value `small' will be used.
//
// Since zig binary itself is relatively large, using a `small'
// code model will cause
//
// relocation R_LARCH_B26 out of range
//
// error when linking a loongarch64 zig binary.
//
// Here we explicitly set code model to `medium' to avoid this
// error.
.loongarch64 => .medium,
else => .default,
},
});
exe.root_module.valgrind = options.valgrind;
exe.stack_size = stack_size;
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ stage3-debug/bin/zig build \

stage3-debug/bin/zig build test docs \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Debug-70b8227f1/bin/lldb \
-Dlldb=$HOME/deps/lldb-zig/Debug-befcd57a8/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ stage3-release/bin/zig build \

stage3-release/bin/zig build test docs \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Release-70b8227f1/bin/lldb \
-Dlldb=$HOME/deps/lldb-zig/Release-befcd57a8/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
Expand Down
26 changes: 14 additions & 12 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,7 @@ or
</p>
{#code|struct_default_field_values.zig#}

{#header_open|Faulty Default Field Values#}
<p>
Default field values are only appropriate when the data invariants of a struct
cannot be violated by omitting that field from an initialization.
Expand All @@ -2162,6 +2163,7 @@ or
without violating data invariants, then use an initialization method that accepts
those runtime values, and populates the remaining fields.</p>
{#header_close#}
{#header_close#}

{#header_open|extern struct#}
<p>An {#syntax#}extern struct{#endsyntax#} has in-memory layout matching
Expand Down Expand Up @@ -4299,7 +4301,7 @@ comptime {
Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
</p>
<p>
Asserts that {#syntax#}@typeInfo(DestType) != .Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@ptrFromInt{#endsyntax#} if you need this.
Asserts that {#syntax#}@typeInfo(DestType) != .pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@ptrFromInt{#endsyntax#} if you need this.
</p>
<p>
Can be used for these things for example:
Expand Down Expand Up @@ -4517,7 +4519,7 @@ comptime {
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
</p>
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
{#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#}
{#header_close#}
Expand Down Expand Up @@ -4549,7 +4551,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
</p>
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
{#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#}
{#header_close#}
Expand Down Expand Up @@ -4672,7 +4674,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<p>
Floored division. Rounds toward negative infinity. For unsigned integers it is
the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
{#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
{#syntax#}!(@typeInfo(T) == .int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
</p>
<ul>
<li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
Expand All @@ -4686,7 +4688,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<p>
Truncated division. Rounds toward zero. For unsigned integers it is
the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
{#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
{#syntax#}!(@typeInfo(T) == .int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
</p>
<ul>
<li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
Expand Down Expand Up @@ -5320,8 +5322,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
any bits that disagree with the resultant sign bit are shifted out.
</p>
<p>
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).int.bits){#endsyntax#} bits.
This is because {#syntax#}shift_amt >= @typeInfo(T).int.bits{#endsyntax#} is undefined behavior.
</p>
<p>
{#syntax#}comptime_int{#endsyntax#} is modeled as an integer with an infinite number of bits,
Expand All @@ -5337,8 +5339,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
Performs {#syntax#}a << b{#endsyntax#} and returns a tuple with the result and a possible overflow bit.
</p>
<p>
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(@TypeOf(a)).Int.bits){#endsyntax#} bits.
This is because {#syntax#}shift_amt >= @typeInfo(@TypeOf(a)).Int.bits{#endsyntax#} is undefined behavior.
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(@TypeOf(a)).int.bits){#endsyntax#} bits.
This is because {#syntax#}shift_amt >= @typeInfo(@TypeOf(a)).int.bits{#endsyntax#} is undefined behavior.
</p>
{#see_also|@shlExact|@shrExact#}
{#header_close#}
Expand All @@ -5350,8 +5352,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
that the shift will not shift any 1 bits out.
</p>
<p>
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).int.bits){#endsyntax#} bits.
This is because {#syntax#}shift_amt >= @typeInfo(T).int.bits{#endsyntax#} is undefined behavior.
</p>
{#see_also|@shlExact|@shlWithOverflow#}
{#header_close#}
Expand Down Expand Up @@ -5405,7 +5407,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
This size may contain padding bytes. If there were two consecutive T in memory, the padding would be the offset
in bytes between element at index 0 and the element at index 1. For {#link|integer|Integers#},
consider whether you want to use {#syntax#}@sizeOf(T){#endsyntax#} or
{#syntax#}@typeInfo(T).Int.bits{#endsyntax#}.
{#syntax#}@typeInfo(T).int.bits{#endsyntax#}.
</p>
<p>
This function measures the size at runtime. For types that are disallowed at runtime, such as
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/inline_prong_range.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
const fields = @typeInfo(T).Struct.fields;
const fields = @typeInfo(T).@"struct".fields;
return switch (field_index) {
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .optional,
else => return error.IndexOutOfBounds,
};
}
Expand Down
6 changes: 3 additions & 3 deletions doc/langref/poc_printValue_fn.zig
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Writer = struct {
pub fn printValue(self: *Writer, value: anytype) !void {
switch (@typeInfo(@TypeOf(value))) {
.Int => {
.int => {
return self.writeInt(value);
},
.Float => {
.float => {
return self.writeFloat(value);
},
.Pointer => {
.pointer => {
return self.write(value);
},
else => {
Expand Down
6 changes: 3 additions & 3 deletions doc/langref/test_enums.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ const Small = enum {
four,
};
test "std.meta.Tag" {
try expect(@typeInfo(Small).Enum.tag_type == u2);
try expect(@typeInfo(Small).@"enum".tag_type == u2);
}

// @typeInfo tells us the field count and the fields names:
test "@typeInfo" {
try expect(@typeInfo(Small).Enum.fields.len == 4);
try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
try expect(@typeInfo(Small).@"enum".fields.len == 4);
try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));
}

// @tagName gives a [:0]const u8 representation of an enum value:
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/test_error_union.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ test "error union" {
foo = error.SomeError;

// Use compile-time reflection to access the payload type of an error union:
try comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32);
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);

// Use compile-time reflection to access the error set type of an error union:
try comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror);
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
}

// test
6 changes: 3 additions & 3 deletions doc/langref/test_fn_reflection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const math = std.math;
const testing = std.testing;

test "fn reflection" {
try testing.expect(@typeInfo(@TypeOf(testing.expect)).Fn.params[0].type.? == bool);
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).Fn.return_type.? == testing.TmpDir);
try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);

try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).Fn.is_generic);
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
}

// test
4 changes: 2 additions & 2 deletions doc/langref/test_inline_else.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const AnySlice = union(enum) {
};

fn withFor(any: AnySlice) usize {
const Tag = @typeInfo(AnySlice).Union.tag_type.?;
inline for (@typeInfo(Tag).Enum.fields) |field| {
const Tag = @typeInfo(AnySlice).@"union".tag_type.?;
inline for (@typeInfo(Tag).@"enum".fields) |field| {
// With `inline for` the function gets generated as
// a series of `if` statements relying on the optimizer
// to convert it to a switch.
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/test_inline_switch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const expect = std.testing.expect;
const expectError = std.testing.expectError;

fn isFieldOptional(comptime T: type, field_index: usize) !bool {
const fields = @typeInfo(T).Struct.fields;
const fields = @typeInfo(T).@"struct".fields;
return switch (field_index) {
// This prong is analyzed twice with `idx` being a
// comptime-known value each time.
inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .optional,
else => return error.IndexOutOfBounds,
};
}
Expand Down
2 changes: 1 addition & 1 deletion doc/langref/test_optional_type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test "optional type" {
foo = 1234;

// Use compile-time reflection to access the child type of the optional:
try comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32);
try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32);
}

// test
2 changes: 1 addition & 1 deletion doc/langref/test_pointer_casting.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test "pointer casting" {

test "pointer child type" {
// pointer types have a `child` field which tells you the type they point to.
try expect(@typeInfo(*u32).Pointer.child == u32);
try expect(@typeInfo(*u32).pointer.child == u32);
}

// test
2 changes: 1 addition & 1 deletion doc/langref/test_variable_alignment.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test "variable alignment" {
try expect(@TypeOf(&x) == *i32);
try expect(*i32 == *align(align_of_i32) i32);
if (builtin.target.cpu.arch == .x86_64) {
try expect(@typeInfo(*i32).Pointer.alignment == 4);
try expect(@typeInfo(*i32).pointer.alignment == 4);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/langref/test_variable_func_alignment.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const expect = @import("std").testing.expect;
var foo: u8 align(4) = 100;

test "global variable alignment" {
try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4);
try expect(@TypeOf(&foo) == *align(4) u8);
const as_pointer_to_array: *align(4) [1]u8 = &foo;
const as_slice: []align(4) u8 = as_pointer_to_array;
Expand Down
2 changes: 1 addition & 1 deletion doc/langref/test_variadic_function.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;

test "variadic function" {
try testing.expect(printf("Hello, world!\n") == 14);
try testing.expect(@typeInfo(@TypeOf(printf)).Fn.is_var_args);
try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args);
}

// test
Expand Down
Loading

0 comments on commit 3a1ea6a

Please sign in to comment.