Skip to content

Commit 8d41c44

Browse files
Merge branch 'master' into feature/hash-package-command
2 parents b4d3bb7 + 8d63364 commit 8d41c44

File tree

341 files changed

+24110
-8220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

341 files changed

+24110
-8220
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,12 @@ set(ZIG_BUILD_ARGS
860860
)
861861

862862
add_custom_target(stage3 ALL
863-
COMMAND zig2 build compile ${ZIG_BUILD_ARGS}
864-
DEPENDS zig2
863+
DEPENDS "${CMAKE_BINARY_DIR}/stage3/bin/zig"
864+
)
865+
866+
add_custom_command(
867+
OUTPUT "${CMAKE_BINARY_DIR}/stage3/bin/zig"
868+
COMMAND zig2 build --prefix "${CMAKE_BINARY_DIR}/stage3" ${ZIG_BUILD_ARGS}
865869
COMMENT STATUS "Building stage3"
866870
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
867871
)

build.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ pub fn build(b: *std.Build) !void {
179179
exe.entitlements = entitlements;
180180
b.installArtifact(exe);
181181

182-
const compile_step = b.step("compile", "Build the self-hosted compiler");
183-
compile_step.dependOn(&exe.step);
184-
185182
test_step.dependOn(&exe.step);
186183

187184
exe.single_threaded = single_threaded;

ci/aarch64-linux-debug.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ stage3-debug/bin/zig build -Dtarget=arm-linux-musleabihf
6060
# TODO: add -fqemu back to this line
6161

6262
stage3-debug/bin/zig build test docs \
63+
--maxrss 24696061952 \
6364
-fwasmtime \
6465
-Dstatic-llvm \
6566
-Dtarget=native-native-musl \

ci/aarch64-linux-release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ stage3-release/bin/zig build -Dtarget=arm-linux-musleabihf
6060
# TODO: add -fqemu back to this line
6161

6262
stage3-release/bin/zig build test docs \
63+
--maxrss 24696061952 \
6364
-fwasmtime \
6465
-Dstatic-llvm \
6566
-Dtarget=native-native-musl \

doc/docgen.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ fn genHtml(
14241424
const result = try ChildProcess.exec(.{
14251425
.allocator = allocator,
14261426
.argv = build_args.items,
1427+
.cwd = tmp_dir_name,
14271428
.env_map = &env_map,
14281429
.max_output_bytes = max_doc_file_size,
14291430
});

doc/langref.html.in

Lines changed: 88 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,8 @@ fn foo() i32 {
14221422

14231423
{#header_open|Thread Local Variables#}
14241424
<p>A variable may be specified to be a thread-local variable using the
1425-
{#syntax#}threadlocal{#endsyntax#} keyword:</p>
1425+
{#syntax#}threadlocal{#endsyntax#} keyword,
1426+
which makes each thread work with a separate instance of the variable:</p>
14261427
{#code_begin|test|test_thread_local_variables#}
14271428
const std = @import("std");
14281429
const assert = std.debug.assert;
@@ -4278,7 +4279,7 @@ const expectError = std.testing.expectError;
42784279
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
42794280
const fields = @typeInfo(T).Struct.fields;
42804281
return switch (field_index) {
4281-
// This prong is analyzed `fields.len - 1` times with `idx` being an
4282+
// This prong is analyzed `fields.len - 1` times with `idx` being a
42824283
// unique comptime-known value each time.
42834284
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
42844285
else => return error.IndexOutOfBounds,
@@ -4667,6 +4668,29 @@ test "for basics" {
46674668
sum2 += @intCast(i32, i);
46684669
}
46694670
try expect(sum2 == 10);
4671+
4672+
// To iterate over consecutive integers, use the range syntax.
4673+
// Unbounded range is always a compile error.
4674+
var sum3 : usize = 0;
4675+
for (0..5) |i| {
4676+
sum3 += i;
4677+
}
4678+
try expect(sum3 == 10);
4679+
}
4680+
4681+
test "multi object for" {
4682+
const items = [_]usize{ 1, 2, 3 };
4683+
const items2 = [_]usize{ 4, 5, 6 };
4684+
var count: usize = 0;
4685+
4686+
// Iterate over multiple objects.
4687+
// All lengths must be equal at the start of the loop, otherwise detectable
4688+
// illegal behavior occurs.
4689+
for (items, items2) |i, j| {
4690+
count += i + j;
4691+
}
4692+
4693+
try expect(count == 21);
46704694
}
46714695

46724696
test "for reference" {
@@ -4710,8 +4734,8 @@ const expect = std.testing.expect;
47104734

47114735
test "nested break" {
47124736
var count: usize = 0;
4713-
outer: for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
4714-
for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
4737+
outer: for (1..6) |_| {
4738+
for (1..6) |_| {
47154739
count += 1;
47164740
break :outer;
47174741
}
@@ -4721,8 +4745,8 @@ test "nested break" {
47214745

47224746
test "nested continue" {
47234747
var count: usize = 0;
4724-
outer: for ([_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }) |_| {
4725-
for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
4748+
outer: for (1..9) |_| {
4749+
for (1..6) |_| {
47264750
count += 1;
47274751
continue :outer;
47284752
}
@@ -5160,7 +5184,8 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }
51605184

51615185
// The extern specifier is used to declare a function that will be resolved
51625186
// at link time, when linking statically, or at runtime, when linking
5163-
// dynamically.
5187+
// dynamically. The quoted identifier after the extern keyword specifies
5188+
// the library that has the function. (e.g. "c" -> libc.so)
51645189
// The callconv specifier changes the calling convention of the function.
51655190
const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall else .C;
51665191
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(WINAPI) noreturn;
@@ -8017,7 +8042,7 @@ pub const CallModifier = enum {
80178042
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
80188043
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
80198044
<p>
8020-
This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer.
8045+
Counts the number of most-significant (leading in a big-endian sense) zeroes in an integer - "count leading zeroes".
80218046
</p>
80228047
<p>
80238048
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
@@ -8167,7 +8192,7 @@ test "main" {
81678192
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
81688193
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
81698194
<p>
8170-
This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer.
8195+
Counts the number of least-significant (trailing in a big-endian sense) zeroes in an integer - "count trailing zeroes".
81718196
</p>
81728197
<p>
81738198
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
@@ -8553,16 +8578,27 @@ test "@hasDecl" {
85538578
</p>
85548579
<ul>
85558580
<li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
8556-
<li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information.
8581+
<li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
85578582
The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
85588583
</li>
8559-
<li>{#syntax#}@import("root"){#endsyntax#} - Points to the root source file.
8560-
This is usually <code>src/main.zig</code> but it depends on what file is chosen to be built.
8584+
<li>{#syntax#}@import("root"){#endsyntax#} - Root source file
8585+
This is usually <code>src/main.zig</code> but depends on what file is built.
85618586
</li>
85628587
</ul>
85638588
{#see_also|Compile Variables|@embedFile#}
85648589
{#header_close#}
85658590

8591+
{#header_open|@inComptime#}
8592+
<pre>{#syntax#}@inComptime() bool{#endsyntax#}</pre>
8593+
<p>
8594+
Returns whether the builtin was run in a {#syntax#}comptime{#endsyntax#} context. The result is a compile-time constant.
8595+
</p>
8596+
<p>
8597+
This can be used to provide alternative, comptime-friendly implementations of functions. It should not be used, for instance, to exclude certain functions from being evaluated at comptime.
8598+
</p>
8599+
{#see_also|comptime#}
8600+
{#header_close#}
8601+
85668602
{#header_open|@intCast#}
85678603
<pre>{#syntax#}@intCast(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
85688604
<p>
@@ -8646,40 +8682,30 @@ test "integer cast panic" {
86468682
{#header_close#}
86478683

86488684
{#header_open|@memcpy#}
8649-
<pre>{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize) void{#endsyntax#}</pre>
8650-
<p>
8651-
This function copies bytes from one region of memory to another. {#syntax#}dest{#endsyntax#} and
8652-
{#syntax#}source{#endsyntax#} are both pointers and must not overlap.
8653-
</p>
8654-
<p>
8655-
This function is a low level intrinsic with no safety mechanisms. Most code
8656-
should not use this function, instead using something like this:
8657-
</p>
8658-
<pre>{#syntax#}for (dest, source[0..byte_count]) |*d, s| d.* = s;{#endsyntax#}</pre>
8659-
<p>
8660-
The optimizer is intelligent enough to turn the above snippet into a memcpy.
8661-
</p>
8662-
<p>There is also a standard library function for this:</p>
8663-
<pre>{#syntax#}const mem = @import("std").mem;
8664-
mem.copy(u8, dest[0..byte_count], source[0..byte_count]);{#endsyntax#}</pre>
8685+
<pre>{#syntax#}@memcpy(noalias dest, noalias source) void{#endsyntax#}</pre>
8686+
<p>This function copies bytes from one region of memory to another.</p>
8687+
<p>{#syntax#}dest{#endsyntax#} must be a mutable slice, a mutable pointer to an array, or
8688+
a mutable many-item {#link|pointer|Pointers#}. It may have any
8689+
alignment, and it may have any element type.</p>
8690+
<p>Likewise, {#syntax#}source{#endsyntax#} must be a mutable slice, a
8691+
mutable pointer to an array, or a mutable many-item
8692+
{#link|pointer|Pointers#}. It may have any alignment, and it may have any
8693+
element type.</p>
8694+
<p>The {#syntax#}source{#endsyntax#} element type must support {#link|Type Coercion#}
8695+
into the {#syntax#}dest{#endsyntax#} element type. The element types may have
8696+
different ABI size, however, that may incur a performance penalty.</p>
8697+
<p>Similar to {#link|for#} loops, at least one of {#syntax#}source{#endsyntax#} and
8698+
{#syntax#}dest{#endsyntax#} must provide a length, and if two lengths are provided,
8699+
they must be equal.</p>
8700+
<p>Finally, the two memory regions must not overlap.</p>
86658701
{#header_close#}
86668702

86678703
{#header_open|@memset#}
8668-
<pre>{#syntax#}@memset(dest: [*]u8, c: u8, byte_count: usize) void{#endsyntax#}</pre>
8669-
<p>
8670-
This function sets a region of memory to {#syntax#}c{#endsyntax#}. {#syntax#}dest{#endsyntax#} is a pointer.
8671-
</p>
8672-
<p>
8673-
This function is a low level intrinsic with no safety mechanisms. Most
8674-
code should not use this function, instead using something like this:
8675-
</p>
8676-
<pre>{#syntax#}for (dest[0..byte_count]) |*b| b.* = c;{#endsyntax#}</pre>
8677-
<p>
8678-
The optimizer is intelligent enough to turn the above snippet into a memset.
8679-
</p>
8680-
<p>There is also a standard library function for this:</p>
8681-
<pre>{#syntax#}const mem = @import("std").mem;
8682-
mem.set(u8, dest, c);{#endsyntax#}</pre>
8704+
<pre>{#syntax#}@memset(dest, elem) void{#endsyntax#}</pre>
8705+
<p>This function sets all the elements of a memory region to {#syntax#}elem{#endsyntax#}.</p>
8706+
<p>{#syntax#}dest{#endsyntax#} must be a mutable slice or a mutable pointer to an array.
8707+
It may have any alignment, and it may have any element type.</p>
8708+
<p>{#syntax#}elem{#endsyntax#} is coerced to the element type of {#syntax#}dest{#endsyntax#}.</p>
86838709
{#header_close#}
86848710

86858711
{#header_open|@min#}
@@ -8780,7 +8806,9 @@ test "@wasmMemoryGrow" {
87808806
<pre>{#syntax#}@popCount(operand: anytype) anytype{#endsyntax#}</pre>
87818807
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p>
87828808
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
8783-
<p>Counts the number of bits set in an integer.</p>
8809+
<p>
8810+
Counts the number of bits set in an integer - "population count".
8811+
</p>
87848812
<p>
87858813
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
87868814
the return type is {#syntax#}comptime_int{#endsyntax#}.
@@ -8812,6 +8840,8 @@ test "@wasmMemoryGrow" {
88128840
pub const PrefetchOptions = struct {
88138841
/// Whether the prefetch should prepare for a read or a write.
88148842
rw: Rw = .read,
8843+
/// The data's locality in an inclusive range from 0 to 3.
8844+
///
88158845
/// 0 means no temporal locality. That is, the data can be immediately
88168846
/// dropped from the cache after it is accessed.
88178847
///
@@ -8821,12 +8851,12 @@ pub const PrefetchOptions = struct {
88218851
/// The cache that the prefetch should be preformed on.
88228852
cache: Cache = .data,
88238853

8824-
pub const Rw = enum {
8854+
pub const Rw = enum(u1) {
88258855
read,
88268856
write,
88278857
};
88288858

8829-
pub const Cache = enum {
8859+
pub const Cache = enum(u1) {
88308860
instruction,
88318861
data,
88328862
};
@@ -10948,7 +10978,7 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke
1094810978
</p>
1094910979
<p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p>
1095010980
<ul>
10951-
<li>Supports all the syntax of the other two pointer types.</li>
10981+
<li>Supports all the syntax of the other two pointer types ({#syntax#}*T{#endsyntax#}) and ({#syntax#}[*]T{#endsyntax#}).</li>
1095210982
<li>Coerces to other pointer types, as well as {#link|Optional Pointers#}.
1095310983
When a C pointer is coerced to a non-optional pointer, safety-checked
1095410984
{#link|Undefined Behavior#} occurs if the address is 0.
@@ -11966,6 +11996,17 @@ fn readU32Be() u32 {}
1196611996
</ul>
1196711997
</td>
1196811998
</tr>
11999+
<tr>
12000+
<th scope="row">
12001+
<pre>{#syntax#}noinline{#endsyntax#}</pre>
12002+
</th>
12003+
<td>
12004+
{#syntax#}noinline{#endsyntax#} disallows function to be inlined in all call sites.
12005+
<ul>
12006+
<li>See also {#link|Functions#}</li>
12007+
</ul>
12008+
</td>
12009+
</tr>
1196912010
<tr>
1197012011
<th scope="row">
1197112012
<pre>{#syntax#}nosuspend{#endsyntax#}</pre>

0 commit comments

Comments
 (0)