diff --git a/CMakeLists.txt b/CMakeLists.txt
index 20d19fa167..0e4d5cfb43 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -426,7 +426,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/os.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
- "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno-generic.zig"
+ "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno/generic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
diff --git a/build.zig b/build.zig
index 449c6a7f1a..e2665557b8 100644
--- a/build.zig
+++ b/build.zig
@@ -17,8 +17,10 @@ pub fn build(b: *Builder) !void {
b.setPreferredReleaseMode(.ReleaseFast);
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
+ const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode") orelse false;
var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
+ docgen_exe.single_threaded = single_threaded;
const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
const langref_out_path = fs.path.join(
@@ -41,6 +43,7 @@ pub fn build(b: *Builder) !void {
var test_stage2 = b.addTest("src/test.zig");
test_stage2.setBuildMode(mode);
test_stage2.addPackagePath("test_cases", "test/cases.zig");
+ test_stage2.single_threaded = single_threaded;
const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
@@ -104,10 +107,15 @@ pub fn build(b: *Builder) !void {
exe.setTarget(target);
toolchain_step.dependOn(&exe.step);
b.default_step.dependOn(&exe.step);
+ exe.single_threaded = single_threaded;
+
+ const exe_options = b.addOptions();
+ exe.addOptions("build_options", exe_options);
+
+ exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames);
+ exe_options.addOption(bool, "skip_non_native", skip_non_native);
+ exe_options.addOption(bool, "have_llvm", enable_llvm);
- exe.addBuildOption(u32, "mem_leak_frames", mem_leak_frames);
- exe.addBuildOption(bool, "skip_non_native", skip_non_native);
- exe.addBuildOption(bool, "have_llvm", enable_llvm);
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
@@ -131,6 +139,7 @@ pub fn build(b: *Builder) !void {
softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086");
softfloat.addIncludeDir("deps/SoftFloat-3e/source/include");
softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
+ softfloat.single_threaded = single_threaded;
exe.linkLibrary(softfloat);
test_stage2.linkLibrary(softfloat);
@@ -213,15 +222,15 @@ pub fn build(b: *Builder) !void {
},
}
};
- exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
+ exe_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
const semver = try std.SemanticVersion.parse(version);
- exe.addBuildOption(std.SemanticVersion, "semver", semver);
+ exe_options.addOption(std.SemanticVersion, "semver", semver);
- exe.addBuildOption(bool, "enable_logging", enable_logging);
- exe.addBuildOption(bool, "enable_tracy", tracy != null);
- exe.addBuildOption(bool, "is_stage1", is_stage1);
- exe.addBuildOption(bool, "omit_stage2", omit_stage2);
+ exe_options.addOption(bool, "enable_logging", enable_logging);
+ exe_options.addOption(bool, "enable_tracy", tracy != null);
+ exe_options.addOption(bool, "is_stage1", is_stage1);
+ exe_options.addOption(bool, "omit_stage2", omit_stage2);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
@@ -243,20 +252,23 @@ pub fn build(b: *Builder) !void {
const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false;
const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
- test_stage2.addBuildOption(bool, "enable_logging", enable_logging);
- test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
- test_stage2.addBuildOption(bool, "skip_compile_errors", skip_compile_errors);
- test_stage2.addBuildOption(bool, "is_stage1", is_stage1);
- test_stage2.addBuildOption(bool, "omit_stage2", omit_stage2);
- test_stage2.addBuildOption(bool, "have_llvm", enable_llvm);
- test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
- test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
- test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);
- test_stage2.addBuildOption(u32, "mem_leak_frames", mem_leak_frames * 2);
- test_stage2.addBuildOption(bool, "enable_darling", is_darling_enabled);
- test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
- test_stage2.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
- test_stage2.addBuildOption(std.SemanticVersion, "semver", semver);
+ const test_stage2_options = b.addOptions();
+ test_stage2.addOptions("build_options", test_stage2_options);
+
+ test_stage2_options.addOption(bool, "enable_logging", enable_logging);
+ test_stage2_options.addOption(bool, "skip_non_native", skip_non_native);
+ test_stage2_options.addOption(bool, "skip_compile_errors", skip_compile_errors);
+ test_stage2_options.addOption(bool, "is_stage1", is_stage1);
+ test_stage2_options.addOption(bool, "omit_stage2", omit_stage2);
+ test_stage2_options.addOption(bool, "have_llvm", enable_llvm);
+ test_stage2_options.addOption(bool, "enable_qemu", is_qemu_enabled);
+ test_stage2_options.addOption(bool, "enable_wine", is_wine_enabled);
+ test_stage2_options.addOption(bool, "enable_wasmtime", is_wasmtime_enabled);
+ test_stage2_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2);
+ test_stage2_options.addOption(bool, "enable_darling", is_darling_enabled);
+ test_stage2_options.addOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
+ test_stage2_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
+ test_stage2_options.addOption(std.SemanticVersion, "semver", semver);
const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests");
test_stage2_step.dependOn(&test_stage2.step);
@@ -296,7 +308,7 @@ pub fn build(b: *Builder) !void {
"behavior",
"Run the behavior tests",
modes,
- false,
+ false, // skip_single_threaded
skip_non_native,
skip_libc,
is_wine_enabled,
@@ -313,9 +325,9 @@ pub fn build(b: *Builder) !void {
"compiler-rt",
"Run the compiler_rt tests",
modes,
- true,
+ true, // skip_single_threaded
skip_non_native,
- true,
+ true, // skip_libc
is_wine_enabled,
is_qemu_enabled,
is_wasmtime_enabled,
@@ -330,9 +342,9 @@ pub fn build(b: *Builder) !void {
"minilibc",
"Run the mini libc tests",
modes,
- true,
+ true, // skip_single_threaded
skip_non_native,
- true,
+ true, // skip_libc
is_wine_enabled,
is_qemu_enabled,
is_wasmtime_enabled,
diff --git a/doc/docgen.zig b/doc/docgen.zig
index f2d2e2845b..8d920dcf6a 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -887,16 +887,6 @@ fn tokenizeAndPrintRaw(
next_tok_is_fn = true;
},
- .keyword_undefined,
- .keyword_null,
- .keyword_true,
- .keyword_false,
- => {
- try out.writeAll("");
- try writeEscaped(out, src[token.loc.start..token.loc.end]);
- try out.writeAll("");
- },
-
.string_literal,
.multiline_string_literal_line,
.char_literal,
@@ -921,9 +911,18 @@ fn tokenizeAndPrintRaw(
},
.identifier => {
- if (prev_tok_was_fn) {
+ const tok_bytes = src[token.loc.start..token.loc.end];
+ if (mem.eql(u8, tok_bytes, "undefined") or
+ mem.eql(u8, tok_bytes, "null") or
+ mem.eql(u8, tok_bytes, "true") or
+ mem.eql(u8, tok_bytes, "false"))
+ {
+ try out.writeAll("");
+ try writeEscaped(out, tok_bytes);
+ try out.writeAll("");
+ } else if (prev_tok_was_fn) {
try out.writeAll("");
- try writeEscaped(out, src[token.loc.start..token.loc.end]);
+ try writeEscaped(out, tok_bytes);
try out.writeAll("");
} else {
const is_int = blk: {
@@ -938,12 +937,12 @@ fn tokenizeAndPrintRaw(
}
break :blk true;
};
- if (is_int or isType(src[token.loc.start..token.loc.end])) {
+ if (is_int or isType(tok_bytes)) {
try out.writeAll("");
- try writeEscaped(out, src[token.loc.start..token.loc.end]);
+ try writeEscaped(out, tok_bytes);
try out.writeAll("");
} else {
- try writeEscaped(out, src[token.loc.start..token.loc.end]);
+ try writeEscaped(out, tok_bytes);
}
}
},
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 386fe9f41a..62e3da7277 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -38,15 +38,20 @@
.file {
text-decoration: underline;
}
- pre,code {
- font-size: 12pt;
- }
pre > code {
display: block;
overflow: auto;
padding: 0.5em;
color: #333;
background: #f8f8f8;
+ border: 1px dotted silver;
+ line-height: normal;
+ }
+ code {
+ background-color: #f8f8f8;
+ border: 1px dotted silver;
+ padding-left: 0.3em;
+ padding-right: 0.3em;
}
.table-wrapper {
width: 100%;
@@ -95,6 +100,7 @@
#contents {
max-width: 60em;
margin: auto;
+ line-height: 1.5;
}
#toc {
@@ -153,6 +159,11 @@
pre > code {
color: #ccc;
background: #222;
+ border-color: #444;
+ }
+ code {
+ background-color: #222;
+ border-color: #444;
}
.tok-kw {
color: #eee;
@@ -3152,7 +3163,9 @@ test "switch using enum literals" {
It must specify a tag type and cannot consume every enumeration value.
- {#link|@intToEnum#} on a non-exhaustive enum cannot fail.
+ {#link|@intToEnum#} on a non-exhaustive enum involves the safety semantics
+ of {#link|@intCast#} to the integer tag type, but beyond that always results in
+ a well-defined enum value.
A switch on a non-exhaustive enum can include a '_' prong as an alternative to an {#syntax#}else{#endsyntax#} prong
@@ -6634,14 +6647,21 @@ test "global assembly" {
When a function is called, a frame is pushed to the stack,
the function runs until it reaches a return statement, and then the frame is popped from the stack.
- At the callsite, the following code does not run until the function returns.
+ The code following the callsite does not run until the function returns.
- An async function is a function whose callsite is split into an {#syntax#}async{#endsyntax#} initiation,
+ An async function is a function whose execution is split into an {#syntax#}async{#endsyntax#} initiation,
followed by an {#syntax#}await{#endsyntax#} completion. Its frame is
provided explicitly by the caller, and it can be suspended and resumed any number of times.
+ The code following the {#syntax#}async{#endsyntax#} callsite runs immediately after the async
+ function first suspends. When the return value of the async function is needed,
+ the calling code can {#syntax#}await{#endsyntax#} on the async function frame.
+ This will suspend the calling code until the async function completes, at which point
+ execution resumes just after the {#syntax#}await{#endsyntax#} callsite.
+
+
Zig infers that a function is {#syntax#}async{#endsyntax#} when it observes that the function contains
a suspension point. Async functions can be called the same as normal functions. A
function call of an async function is a suspend point.
@@ -6744,7 +6764,14 @@ fn testResumeFromSuspend(my_result: *i32) void {
{#header_open|Async and Await#}
In the same way that every {#syntax#}suspend{#endsyntax#} has a matching
- {#syntax#}resume{#endsyntax#}, every {#syntax#}async{#endsyntax#} has a matching {#syntax#}await{#endsyntax#}.
+ {#syntax#}resume{#endsyntax#}, every {#syntax#}async{#endsyntax#} has a matching {#syntax#}await{#endsyntax#}
+ in standard code.
+
+
+ However, it is possible to have an {#syntax#}async{#endsyntax#} call
+ without a matching {#syntax#}await{#endsyntax#}. Upon completion of the async function,
+ execution would continue at the most recent {#syntax#}async{#endsyntax#} callsite or {#syntax#}resume{#endsyntax#} callsite,
+ and the return value of the async function would be lost.
{#code_begin|test#}
const std = @import("std");
@@ -6779,7 +6806,9 @@ fn func() void {
{#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that
- coerces to {#syntax#}anyframe->T{#endsyntax#}.
+ coerces to {#syntax#}anyframe->T{#endsyntax#}. Calling {#syntax#}await{#endsyntax#} on
+ the frame of an async function will cause execution to continue at the
+ {#syntax#}await{#endsyntax#} callsite once the target function completes.
There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function.
@@ -7945,7 +7974,7 @@ test "@hasDecl" {
{#header_close#}
{#header_open|@intToEnum#}
-
{#syntax#}@intToEnum(comptime DestType: type, int_value: std.meta.Tag(DestType)) DestType{#endsyntax#}
+ {#syntax#}@intToEnum(comptime DestType: type, integer: anytype) DestType{#endsyntax#}
Converts an integer into an {#link|enum#} value.
@@ -11535,11 +11564,7 @@ PrimaryTypeExpr
/ INTEGER
/ KEYWORD_comptime TypeExpr
/ KEYWORD_error DOT IDENTIFIER
- / KEYWORD_false
- / KEYWORD_null
/ KEYWORD_anyframe
- / KEYWORD_true
- / KEYWORD_undefined
/ KEYWORD_unreachable
/ STRINGLITERAL
/ SwitchExpr
@@ -11908,7 +11933,6 @@ KEYWORD_errdefer <- 'errdefer' end_of_word
KEYWORD_error <- 'error' end_of_word
KEYWORD_export <- 'export' end_of_word
KEYWORD_extern <- 'extern' end_of_word
-KEYWORD_false <- 'false' end_of_word
KEYWORD_fn <- 'fn' end_of_word
KEYWORD_for <- 'for' end_of_word
KEYWORD_if <- 'if' end_of_word
@@ -11916,7 +11940,6 @@ KEYWORD_inline <- 'inline' end_of_word
KEYWORD_noalias <- 'noalias' end_of_word
KEYWORD_nosuspend <- 'nosuspend' end_of_word
KEYWORD_noinline <- 'noinline' end_of_word
-KEYWORD_null <- 'null' end_of_word
KEYWORD_opaque <- 'opaque' end_of_word
KEYWORD_or <- 'or' end_of_word
KEYWORD_orelse <- 'orelse' end_of_word
@@ -11930,9 +11953,7 @@ KEYWORD_suspend <- 'suspend' end_of_word
KEYWORD_switch <- 'switch' end_of_word
KEYWORD_test <- 'test' end_of_word
KEYWORD_threadlocal <- 'threadlocal' end_of_word
-KEYWORD_true <- 'true' end_of_word
KEYWORD_try <- 'try' end_of_word
-KEYWORD_undefined <- 'undefined' end_of_word
KEYWORD_union <- 'union' end_of_word
KEYWORD_unreachable <- 'unreachable' end_of_word
KEYWORD_usingnamespace <- 'usingnamespace' end_of_word
@@ -11945,13 +11966,13 @@ keyword <- KEYWORD_align / KEYWORD_allowzero / KEYWORD_and / KEYWORD_anyframe
/ KEYWORD_break / KEYWORD_callconv / KEYWORD_catch / KEYWORD_comptime
/ KEYWORD_const / KEYWORD_continue / KEYWORD_defer / KEYWORD_else
/ KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
- / KEYWORD_extern / KEYWORD_false / KEYWORD_fn / KEYWORD_for / KEYWORD_if
+ / KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if
/ KEYWORD_inline / KEYWORD_noalias / KEYWORD_nosuspend / KEYWORD_noinline
- / KEYWORD_null / KEYWORD_opaque / KEYWORD_or / KEYWORD_orelse / KEYWORD_packed
+ / KEYWORD_opaque / KEYWORD_or / KEYWORD_orelse / KEYWORD_packed
/ KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
/ KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch
- / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try
- / KEYWORD_undefined / KEYWORD_union / KEYWORD_unreachable
+ / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_try
+ / KEYWORD_union / KEYWORD_unreachable
/ KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
{#header_close#}
diff --git a/lib/libc/mingw/lib-common/compstui.def b/lib/libc/mingw/lib-common/compstui.def
new file mode 100644
index 0000000000..240a6ccc9a
--- /dev/null
+++ b/lib/libc/mingw/lib-common/compstui.def
@@ -0,0 +1,12 @@
+;
+; Exports of file COMPSTUI.dll
+;
+; Autogenerated by gen_exportdef
+; Written by Kai Tietz, 2007
+;
+LIBRARY COMPSTUI.dll
+EXPORTS
+CommonPropertySheetUIA
+CommonPropertySheetUIW
+GetCPSUIUserData
+SetCPSUIUserData
diff --git a/lib/libcxx/include/__config b/lib/libcxx/include/__config
index 174c73c4d8..eae2b9ae30 100644
--- a/lib/libcxx/include/__config
+++ b/lib/libcxx/include/__config
@@ -125,7 +125,7 @@
# endif
// Feature macros for disabling pre ABI v1 features. All of these options
// are deprecated.
-# if defined(__FreeBSD__)
+# if defined(__FreeBSD__) || defined(__DragonFly__)
# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
# endif
#endif
@@ -380,7 +380,7 @@
# if __ANDROID_API__ >= 29
# define _LIBCPP_HAS_TIMESPEC_GET
# endif
-# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
+# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__) || defined(__DragonFly__)
# define _LIBCPP_HAS_ALIGNED_ALLOC
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_TIMESPEC_GET
@@ -938,11 +938,11 @@ typedef unsigned int char32_t;
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
- defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
+ defined(__sun__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CloudABI__)
#define _LIBCPP_LOCALE__L_EXTENSIONS 1
#endif
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
#define _DECLARE_C99_LDBL_MATH 1
#endif
@@ -970,11 +970,11 @@ typedef unsigned int char32_t;
# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
#endif
-#if defined(__APPLE__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
#define _LIBCPP_HAS_DEFAULTRUNELOCALE
#endif
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__sun__)
#define _LIBCPP_WCTYPE_IS_MASK
#endif
@@ -1138,6 +1138,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
defined(__wasi__) || \
defined(__NetBSD__) || \
defined(__OpenBSD__) || \
+ defined(__DragonFly__) || \
defined(__NuttX__) || \
defined(__linux__) || \
defined(__GNU__) || \
diff --git a/lib/libcxx/include/__locale b/lib/libcxx/include/__locale
index ad742997d9..0a99f824ec 100644
--- a/lib/libcxx/include/__locale
+++ b/lib/libcxx/include/__locale
@@ -35,7 +35,7 @@
# include <__support/newlib/xlocale.h>
#elif defined(__OpenBSD__)
# include <__support/openbsd/xlocale.h>
-#elif (defined(__APPLE__) || defined(__FreeBSD__) \
+#elif (defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) \
|| defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
# include
#elif defined(__Fuchsia__)
@@ -450,10 +450,10 @@ public:
static const mask blank = _BLANK;
static const mask __regex_word = 0x80;
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
-#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__DragonFly__)
# ifdef __APPLE__
typedef __uint32_t mask;
-# elif defined(__FreeBSD__)
+# elif defined(__FreeBSD__) || defined(__DragonFly__)
typedef unsigned long mask;
# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
typedef unsigned short mask;
diff --git a/lib/libcxx/include/locale b/lib/libcxx/include/locale
index 8e584005da..7d0de4f5d0 100644
--- a/lib/libcxx/include/locale
+++ b/lib/libcxx/include/locale
@@ -228,7 +228,7 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
-#if defined(__APPLE__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
# define _LIBCPP_GET_C_LOCALE 0
#elif defined(__CloudABI__) || defined(__NetBSD__)
# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
diff --git a/lib/libcxx/src/locale.cpp b/lib/libcxx/src/locale.cpp
index d5ab8fb3b8..72982aa7d7 100644
--- a/lib/libcxx/src/locale.cpp
+++ b/lib/libcxx/src/locale.cpp
@@ -1133,7 +1133,7 @@ ctype::classic_table() noexcept
const ctype::mask*
ctype::classic_table() noexcept
{
-#if defined(__APPLE__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
return _DefaultRuneLocale.__runetype;
#elif defined(__NetBSD__)
return _C_ctype_tab_ + 1;
diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig
index ba60f91233..e99b298c1e 100644
--- a/lib/std/Progress.zig
+++ b/lib/std/Progress.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! This API non-allocating, non-fallible, and thread-safe.
//! The tradeoff is that users of this API must provide the storage
//! for each `Progress.Node`.
diff --git a/lib/std/SemanticVersion.zig b/lib/std/SemanticVersion.zig
index 17d5b65571..fb09f85ff2 100644
--- a/lib/std/SemanticVersion.zig
+++ b/lib/std/SemanticVersion.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! A software version formatted according to the Semantic Version 2 specification.
//!
//! See: https://semver.org
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index cd742cc955..3c0a53612c 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -1,17 +1,12 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! This struct represents a kernel thread, and acts as a namespace for concurrency
//! primitives that operate on kernel threads. For concurrency primitives that support
//! both evented I/O and async I/O, see the respective names in the top level std namespace.
const std = @import("std.zig");
+const builtin = @import("builtin");
const os = std.os;
const assert = std.debug.assert;
-const target = std.Target.current;
+const target = builtin.target;
const Atomic = std.atomic.Atomic;
pub const AutoResetEvent = @import("Thread/AutoResetEvent.zig");
@@ -24,7 +19,8 @@ pub const Condition = @import("Thread/Condition.zig");
pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");
-pub const use_pthreads = target.os.tag != .windows and std.Target.current.os.tag != .wasi and std.builtin.link_libc;
+pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc;
+const is_gnu = target.abi.isGnu();
const Thread = @This();
const Impl = if (target.os.tag == .windows)
@@ -38,7 +34,7 @@ else
impl: Impl,
-pub const max_name_len = switch (std.Target.current.os.tag) {
+pub const max_name_len = switch (target.os.tag) {
.linux => 15,
.windows => 31,
.macos, .ios, .watchos, .tvos => 63,
@@ -64,20 +60,21 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
break :blk name_buf[0..name.len :0];
};
- switch (std.Target.current.os.tag) {
+ switch (target.os.tag) {
.linux => if (use_pthreads) {
const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
- return switch (err) {
- 0 => {},
- os.ERANGE => unreachable,
- else => return os.unexpectedErrno(err),
- };
+ switch (err) {
+ .SUCCESS => return,
+ .RANGE => unreachable,
+ else => |e| return os.unexpectedErrno(e),
+ }
} else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {
+ // TODO: this is dead code. what did the author of this code intend to happen here?
const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)});
- return switch (err) {
- 0 => {},
- else => return os.unexpectedErrno(err),
- };
+ switch (@intToEnum(os.E, err)) {
+ .SUCCESS => return,
+ else => |e| return os.unexpectedErrno(e),
+ }
} else {
var buf: [32]u8 = undefined;
const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
@@ -87,7 +84,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
try file.writer().writeAll(name);
},
- .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| {
+ .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
// SetThreadDescription is only available since version 1607, which is 10.0.14393.795
// See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
if (!res) {
@@ -110,24 +107,25 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
if (self.getHandle() != std.c.pthread_self()) return error.Unsupported;
const err = std.c.pthread_setname_np(name_with_terminator.ptr);
- return switch (err) {
- 0 => {},
- else => return os.unexpectedErrno(err),
- };
+ switch (err) {
+ .SUCCESS => return,
+ else => |e| return os.unexpectedErrno(e),
+ }
},
.netbsd => if (use_pthreads) {
const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);
- return switch (err) {
- 0 => {},
- os.EINVAL => unreachable,
- os.ESRCH => unreachable,
- os.ENOMEM => unreachable,
- else => return os.unexpectedErrno(err),
- };
+ switch (err) {
+ .SUCCESS => return,
+ .INVAL => unreachable,
+ .SRCH => unreachable,
+ .NOMEM => unreachable,
+ else => |e| return os.unexpectedErrno(e),
+ }
},
.freebsd, .openbsd => if (use_pthreads) {
// Use pthread_set_name_np for FreeBSD because pthread_setname_np is FreeBSD 12.2+ only.
- // TODO maybe revisit this if depending on FreeBSD 12.2+ is acceptable because pthread_setname_np can return an error.
+ // TODO maybe revisit this if depending on FreeBSD 12.2+ is acceptable because
+ // pthread_setname_np can return an error.
std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);
},
@@ -151,20 +149,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
buffer_ptr[max_name_len] = 0;
var buffer = std.mem.span(buffer_ptr);
- switch (std.Target.current.os.tag) {
- .linux => if (use_pthreads and comptime std.Target.current.abi.isGnu()) {
+ switch (target.os.tag) {
+ .linux => if (use_pthreads and is_gnu) {
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
- return switch (err) {
- 0 => std.mem.sliceTo(buffer, 0),
- os.ERANGE => unreachable,
- else => return os.unexpectedErrno(err),
- };
+ switch (err) {
+ .SUCCESS => return std.mem.sliceTo(buffer, 0),
+ .RANGE => unreachable,
+ else => |e| return os.unexpectedErrno(e),
+ }
} else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {
const err = try os.prctl(.GET_NAME, .{@ptrToInt(buffer.ptr)});
- return switch (err) {
- 0 => std.mem.sliceTo(buffer, 0),
- else => return os.unexpectedErrno(err),
- };
+ switch (@intToEnum(os.E, err)) {
+ .SUCCESS => return std.mem.sliceTo(buffer, 0),
+ else => |e| return os.unexpectedErrno(e),
+ }
} else if (!use_pthreads) {
var buf: [32]u8 = undefined;
const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
@@ -179,7 +177,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
// musl doesn't provide pthread_getname_np and there's no way to retrieve the thread id of an arbitrary thread.
return error.Unsupported;
},
- .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| {
+ .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
// GetThreadDescription is only available since version 1607, which is 10.0.14393.795
// See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
if (!res) {
@@ -198,20 +196,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
},
.macos, .ios, .watchos, .tvos => if (use_pthreads) {
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
- return switch (err) {
- 0 => std.mem.sliceTo(buffer, 0),
- os.ESRCH => unreachable,
- else => return os.unexpectedErrno(err),
- };
+ switch (err) {
+ .SUCCESS => return std.mem.sliceTo(buffer, 0),
+ .SRCH => unreachable,
+ else => |e| return os.unexpectedErrno(e),
+ }
},
.netbsd => if (use_pthreads) {
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
- return switch (err) {
- 0 => std.mem.sliceTo(buffer, 0),
- os.EINVAL => unreachable,
- os.ESRCH => unreachable,
- else => return os.unexpectedErrno(err),
- };
+ switch (err) {
+ .SUCCESS => return std.mem.sliceTo(buffer, 0),
+ .INVAL => unreachable,
+ .SRCH => unreachable,
+ else => |e| return os.unexpectedErrno(e),
+ }
},
.freebsd, .openbsd => if (use_pthreads) {
// Use pthread_get_name_np for FreeBSD because pthread_getname_np is FreeBSD 12.2+ only.
@@ -288,7 +286,7 @@ pub const SpawnError = error{
/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources
/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.
pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {
- if (std.builtin.single_threaded) {
+ if (builtin.single_threaded) {
@compileError("Cannot spawn thread when building in single-threaded mode");
}
@@ -611,13 +609,13 @@ const PosixThreadImpl = struct {
errdefer allocator.destroy(args_ptr);
var attr: c.pthread_attr_t = undefined;
- if (c.pthread_attr_init(&attr) != 0) return error.SystemResources;
- defer assert(c.pthread_attr_destroy(&attr) == 0);
+ if (c.pthread_attr_init(&attr) != .SUCCESS) return error.SystemResources;
+ defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);
// Use the same set of parameters used by the libc-less impl.
const stack_size = std.math.max(config.stack_size, 16 * 1024);
- assert(c.pthread_attr_setstacksize(&attr, stack_size) == 0);
- assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == 0);
+ assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);
+ assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);
var handle: c.pthread_t = undefined;
switch (c.pthread_create(
@@ -626,10 +624,10 @@ const PosixThreadImpl = struct {
Instance.entryFn,
if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined,
)) {
- 0 => return Impl{ .handle = handle },
- os.EAGAIN => return error.SystemResources,
- os.EPERM => unreachable,
- os.EINVAL => unreachable,
+ .SUCCESS => return Impl{ .handle = handle },
+ .AGAIN => return error.SystemResources,
+ .PERM => unreachable,
+ .INVAL => unreachable,
else => |err| return os.unexpectedErrno(err),
}
}
@@ -640,19 +638,19 @@ const PosixThreadImpl = struct {
fn detach(self: Impl) void {
switch (c.pthread_detach(self.handle)) {
- 0 => {},
- os.EINVAL => unreachable, // thread handle is not joinable
- os.ESRCH => unreachable, // thread handle is invalid
+ .SUCCESS => {},
+ .INVAL => unreachable, // thread handle is not joinable
+ .SRCH => unreachable, // thread handle is invalid
else => unreachable,
}
}
fn join(self: Impl) void {
switch (c.pthread_join(self.handle, null)) {
- 0 => {},
- os.EINVAL => unreachable, // thread handle is not joinable (or another thread is already joining in)
- os.ESRCH => unreachable, // thread handle is invalid
- os.EDEADLK => unreachable, // two threads tried to join each other
+ .SUCCESS => {},
+ .INVAL => unreachable, // thread handle is not joinable (or another thread is already joining in)
+ .SRCH => unreachable, // thread handle is invalid
+ .DEADLK => unreachable, // two threads tried to join each other
else => unreachable,
}
}
@@ -806,8 +804,10 @@ const LinuxThreadImpl = struct {
\\ 1:
\\ cmp %%sp, 0
\\ beq 2f
+ \\ nop
\\ restore
\\ ba 1f
+ \\ nop
\\ 2:
\\ mov 73, %%g1
\\ mov %[ptr], %%o0
@@ -937,13 +937,13 @@ const LinuxThreadImpl = struct {
tls_ptr,
&instance.thread.child_tid.value,
))) {
- 0 => return Impl{ .thread = &instance.thread },
- os.EAGAIN => return error.ThreadQuotaExceeded,
- os.EINVAL => unreachable,
- os.ENOMEM => return error.SystemResources,
- os.ENOSPC => unreachable,
- os.EPERM => unreachable,
- os.EUSERS => unreachable,
+ .SUCCESS => return Impl{ .thread = &instance.thread },
+ .AGAIN => return error.ThreadQuotaExceeded,
+ .INVAL => unreachable,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => unreachable,
+ .PERM => unreachable,
+ .USERS => unreachable,
else => |err| return os.unexpectedErrno(err),
}
}
@@ -982,9 +982,9 @@ const LinuxThreadImpl = struct {
tid,
null,
))) {
- 0 => continue,
- os.EINTR => continue,
- os.EAGAIN => continue,
+ .SUCCESS => continue,
+ .INTR => continue,
+ .AGAIN => continue,
else => unreachable,
}
}
@@ -1011,7 +1011,7 @@ fn testThreadName(thread: *Thread) !void {
}
test "setName, getName" {
- if (std.builtin.single_threaded) return error.SkipZigTest;
+ if (builtin.single_threaded) return error.SkipZigTest;
const Context = struct {
start_wait_event: ResetEvent = undefined,
@@ -1029,7 +1029,7 @@ test "setName, getName" {
// Wait for the main thread to have set the thread field in the context.
ctx.start_wait_event.wait();
- switch (std.Target.current.os.tag) {
+ switch (target.os.tag) {
.windows => testThreadName(&ctx.thread) catch |err| switch (err) {
error.Unsupported => return error.SkipZigTest,
else => return err,
@@ -1054,7 +1054,7 @@ test "setName, getName" {
context.start_wait_event.set();
context.test_done_event.wait();
- switch (std.Target.current.os.tag) {
+ switch (target.os.tag) {
.macos, .ios, .watchos, .tvos => {
const res = thread.setName("foobar");
try std.testing.expectError(error.Unsupported, res);
@@ -1063,7 +1063,7 @@ test "setName, getName" {
error.Unsupported => return error.SkipZigTest,
else => return err,
},
- else => |tag| if (tag == .linux and use_pthreads and comptime std.Target.current.abi.isMusl()) {
+ else => |tag| if (tag == .linux and use_pthreads and comptime target.abi.isMusl()) {
try thread.setName("foobar");
var name_buffer: [max_name_len:0]u8 = undefined;
@@ -1096,7 +1096,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
}
test "Thread.join" {
- if (std.builtin.single_threaded) return error.SkipZigTest;
+ if (builtin.single_threaded) return error.SkipZigTest;
var value: usize = 0;
var event: ResetEvent = undefined;
@@ -1110,7 +1110,7 @@ test "Thread.join" {
}
test "Thread.detach" {
- if (std.builtin.single_threaded) return error.SkipZigTest;
+ if (builtin.single_threaded) return error.SkipZigTest;
var value: usize = 0;
var event: ResetEvent = undefined;
diff --git a/lib/std/Thread/AutoResetEvent.zig b/lib/std/Thread/AutoResetEvent.zig
index 13e404d602..49639d60e9 100644
--- a/lib/std/Thread/AutoResetEvent.zig
+++ b/lib/std/Thread/AutoResetEvent.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Similar to `StaticResetEvent` but on `set()` it also (atomically) does `reset()`.
//! Unlike StaticResetEvent, `wait()` can only be called by one thread (MPSC-like).
//!
diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig
index 8485f84aa4..647a50b913 100644
--- a/lib/std/Thread/Condition.zig
+++ b/lib/std/Thread/Condition.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! A condition provides a way for a kernel thread to block until it is signaled
//! to wake up. Spurious wakeups are possible.
//! This API supports static initialization and does not require deinitialization.
@@ -81,17 +75,17 @@ pub const PthreadCondition = struct {
pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void {
const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn signal(cond: *PthreadCondition) void {
const rc = std.c.pthread_cond_signal(&cond.cond);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn broadcast(cond: *PthreadCondition) void {
const rc = std.c.pthread_cond_broadcast(&cond.cond);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
};
@@ -115,9 +109,9 @@ pub const AtomicCondition = struct {
0,
null,
))) {
- 0 => {},
- std.os.EINTR => {},
- std.os.EAGAIN => {},
+ .SUCCESS => {},
+ .INTR => {},
+ .AGAIN => {},
else => unreachable,
}
},
@@ -136,8 +130,8 @@ pub const AtomicCondition = struct {
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
1,
))) {
- 0 => {},
- std.os.EFAULT => {},
+ .SUCCESS => {},
+ .FAULT => {},
else => unreachable,
}
},
diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig
index 81dba07996..5a3da5cd94 100644
--- a/lib/std/Thread/Futex.zig
+++ b/lib/std/Thread/Futex.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Futex is a mechanism used to block (`wait`) and unblock (`wake`) threads using a 32bit memory address as hints.
//! Blocking a thread is acknowledged only if the 32bit memory address is equal to a given value.
//! This check helps avoid block/unblock deadlocks which occur if a `wake()` happens before a `wait()`.
@@ -152,12 +146,12 @@ const LinuxFutex = struct {
@bitCast(i32, expect),
ts_ptr,
))) {
- 0 => {}, // notified by `wake()`
- std.os.EINTR => {}, // spurious wakeup
- std.os.EAGAIN => {}, // ptr.* != expect
- std.os.ETIMEDOUT => return error.TimedOut,
- std.os.EINVAL => {}, // possibly timeout overflow
- std.os.EFAULT => unreachable,
+ .SUCCESS => {}, // notified by `wake()`
+ .INTR => {}, // spurious wakeup
+ .AGAIN => {}, // ptr.* != expect
+ .TIMEDOUT => return error.TimedOut,
+ .INVAL => {}, // possibly timeout overflow
+ .FAULT => unreachable,
else => unreachable,
}
}
@@ -168,9 +162,9 @@ const LinuxFutex = struct {
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),
))) {
- 0 => {}, // successful wake up
- std.os.EINVAL => {}, // invalid futex_wait() on ptr done elsewhere
- std.os.EFAULT => {}, // pointer became invalid while doing the wake
+ .SUCCESS => {}, // successful wake up
+ .INVAL => {}, // invalid futex_wait() on ptr done elsewhere
+ .FAULT => {}, // pointer became invalid while doing the wake
else => unreachable,
}
}
@@ -215,13 +209,13 @@ const DarwinFutex = struct {
};
if (status >= 0) return;
- switch (-status) {
- darwin.EINTR => {},
+ switch (@intToEnum(std.os.E, -status)) {
+ .INTR => {},
// Address of the futex is paged out. This is unlikely, but possible in theory, and
// pthread/libdispatch on darwin bother to handle it. In this case we'll return
// without waiting, but the caller should retry anyway.
- darwin.EFAULT => {},
- darwin.ETIMEDOUT => if (!timeout_overflowed) return error.TimedOut,
+ .FAULT => {},
+ .TIMEDOUT => if (!timeout_overflowed) return error.TimedOut,
else => unreachable,
}
}
@@ -237,11 +231,11 @@ const DarwinFutex = struct {
const status = darwin.__ulock_wake(flags, addr, 0);
if (status >= 0) return;
- switch (-status) {
- darwin.EINTR => continue, // spurious wake()
- darwin.EFAULT => continue, // address of the lock was paged out
- darwin.ENOENT => return, // nothing was woken up
- darwin.EALREADY => unreachable, // only for ULF_WAKE_THREAD
+ switch (@intToEnum(std.os.E, -status)) {
+ .INTR => continue, // spurious wake()
+ .FAULT => continue, // address of the lock was paged out
+ .NOENT => return, // nothing was woken up
+ .ALREADY => unreachable, // only for ULF_WAKE_THREAD
else => unreachable,
}
}
@@ -255,8 +249,8 @@ const PosixFutex = struct {
var waiter: List.Node = undefined;
{
- assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);
- defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);
+ assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
+ defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
if (ptr.load(.SeqCst) != expect) {
return;
@@ -272,8 +266,8 @@ const PosixFutex = struct {
waiter.data.wait(null) catch unreachable;
};
- assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);
- defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);
+ assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
+ defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
if (waiter.data.address == address) {
timed_out = true;
@@ -297,8 +291,8 @@ const PosixFutex = struct {
waiter.data.notify();
};
- assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);
- defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);
+ assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
+ defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
var waiters = bucket.list.first;
while (waiters) |waiter| {
@@ -340,16 +334,13 @@ const PosixFutex = struct {
};
fn deinit(self: *Self) void {
- const rc = std.c.pthread_cond_destroy(&self.cond);
- assert(rc == 0 or rc == std.os.EINVAL);
-
- const rm = std.c.pthread_mutex_destroy(&self.mutex);
- assert(rm == 0 or rm == std.os.EINVAL);
+ _ = std.c.pthread_cond_destroy(&self.cond);
+ _ = std.c.pthread_mutex_destroy(&self.mutex);
}
fn wait(self: *Self, timeout: ?u64) error{TimedOut}!void {
- assert(std.c.pthread_mutex_lock(&self.mutex) == 0);
- defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0);
+ assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS);
+ defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS);
switch (self.state) {
.empty => self.state = .waiting,
@@ -378,28 +369,31 @@ const PosixFutex = struct {
}
const ts_ref = ts_ptr orelse {
- assert(std.c.pthread_cond_wait(&self.cond, &self.mutex) == 0);
+ assert(std.c.pthread_cond_wait(&self.cond, &self.mutex) == .SUCCESS);
continue;
};
const rc = std.c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ref);
- assert(rc == 0 or rc == std.os.ETIMEDOUT);
- if (rc == std.os.ETIMEDOUT) {
- self.state = .empty;
- return error.TimedOut;
+ switch (rc) {
+ .SUCCESS => {},
+ .TIMEDOUT => {
+ self.state = .empty;
+ return error.TimedOut;
+ },
+ else => unreachable,
}
}
}
fn notify(self: *Self) void {
- assert(std.c.pthread_mutex_lock(&self.mutex) == 0);
- defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0);
+ assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS);
+ defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS);
switch (self.state) {
.empty => self.state = .notified,
.waiting => {
self.state = .notified;
- assert(std.c.pthread_cond_signal(&self.cond) == 0);
+ assert(std.c.pthread_cond_signal(&self.cond) == .SUCCESS);
},
.notified => unreachable,
}
diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig
index 35095b2a3c..ee54a1582b 100644
--- a/lib/std/Thread/Mutex.zig
+++ b/lib/std/Thread/Mutex.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Lock may be held only once. If the same thread tries to acquire
//! the same mutex twice, it deadlocks. This type supports static
//! initialization and is at most `@sizeOf(usize)` in size. When an
@@ -143,9 +137,9 @@ pub const AtomicMutex = struct {
@enumToInt(new_state),
null,
))) {
- 0 => {},
- std.os.EINTR => {},
- std.os.EAGAIN => {},
+ .SUCCESS => {},
+ .INTR => {},
+ .AGAIN => {},
else => unreachable,
}
},
@@ -164,8 +158,8 @@ pub const AtomicMutex = struct {
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
1,
))) {
- 0 => {},
- std.os.EFAULT => {},
+ .SUCCESS => {},
+ .FAULT => unreachable, // invalid pointer passed to futex_wake
else => unreachable,
}
},
@@ -182,10 +176,10 @@ pub const PthreadMutex = struct {
pub fn release(held: Held) void {
switch (std.c.pthread_mutex_unlock(&held.mutex.pthread_mutex)) {
- 0 => return,
- std.c.EINVAL => unreachable,
- std.c.EAGAIN => unreachable,
- std.c.EPERM => unreachable,
+ .SUCCESS => return,
+ .INVAL => unreachable,
+ .AGAIN => unreachable,
+ .PERM => unreachable,
else => unreachable,
}
}
@@ -195,7 +189,7 @@ pub const PthreadMutex = struct {
/// the mutex is unavailable. Otherwise returns Held. Call
/// release on Held.
pub fn tryAcquire(m: *PthreadMutex) ?Held {
- if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == 0) {
+ if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == .SUCCESS) {
return Held{ .mutex = m };
} else {
return null;
@@ -206,12 +200,12 @@ pub const PthreadMutex = struct {
/// held by the calling thread.
pub fn acquire(m: *PthreadMutex) Held {
switch (std.c.pthread_mutex_lock(&m.pthread_mutex)) {
- 0 => return Held{ .mutex = m },
- std.c.EINVAL => unreachable,
- std.c.EBUSY => unreachable,
- std.c.EAGAIN => unreachable,
- std.c.EDEADLK => unreachable,
- std.c.EPERM => unreachable,
+ .SUCCESS => return Held{ .mutex = m },
+ .INVAL => unreachable,
+ .BUSY => unreachable,
+ .AGAIN => unreachable,
+ .DEADLK => unreachable,
+ .PERM => unreachable,
else => unreachable,
}
}
diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig
index 356b8eb78d..d9304dd70b 100644
--- a/lib/std/Thread/ResetEvent.zig
+++ b/lib/std/Thread/ResetEvent.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! A thread-safe resource which supports blocking until signaled.
//! This API is for kernel threads, not evented I/O.
//! This API requires being initialized at runtime, and initialization
@@ -130,7 +124,7 @@ pub const PosixEvent = struct {
pub fn init(ev: *PosixEvent) !void {
switch (c.getErrno(c.sem_init(&ev.sem, 0, 0))) {
- 0 => return,
+ .SUCCESS => return,
else => return error.SystemResources,
}
}
@@ -147,9 +141,9 @@ pub const PosixEvent = struct {
pub fn wait(ev: *PosixEvent) void {
while (true) {
switch (c.getErrno(c.sem_wait(&ev.sem))) {
- 0 => return,
- c.EINTR => continue,
- c.EINVAL => unreachable,
+ .SUCCESS => return,
+ .INTR => continue,
+ .INVAL => unreachable,
else => unreachable,
}
}
@@ -165,10 +159,10 @@ pub const PosixEvent = struct {
ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.ns_per_s));
while (true) {
switch (c.getErrno(c.sem_timedwait(&ev.sem, &ts))) {
- 0 => return .event_set,
- c.EINTR => continue,
- c.EINVAL => unreachable,
- c.ETIMEDOUT => return .timed_out,
+ .SUCCESS => return .event_set,
+ .INTR => continue,
+ .INVAL => unreachable,
+ .TIMEDOUT => return .timed_out,
else => unreachable,
}
}
@@ -177,10 +171,10 @@ pub const PosixEvent = struct {
pub fn reset(ev: *PosixEvent) void {
while (true) {
switch (c.getErrno(c.sem_trywait(&ev.sem))) {
- 0 => continue, // Need to make it go to zero.
- c.EINTR => continue,
- c.EINVAL => unreachable,
- c.EAGAIN => return, // The semaphore currently has the value zero.
+ .SUCCESS => continue, // Need to make it go to zero.
+ .INTR => continue,
+ .INVAL => unreachable,
+ .AGAIN => return, // The semaphore currently has the value zero.
else => unreachable,
}
}
diff --git a/lib/std/Thread/RwLock.zig b/lib/std/Thread/RwLock.zig
index 1d606a9cf1..cfe06c76e8 100644
--- a/lib/std/Thread/RwLock.zig
+++ b/lib/std/Thread/RwLock.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! A lock that supports one writer or many readers.
//! This API is for kernel threads, not evented I/O.
//! This API requires being initialized at runtime, and initialization
@@ -13,7 +7,7 @@ impl: Impl,
const RwLock = @This();
const std = @import("../std.zig");
-const builtin = std.builtin;
+const builtin = @import("builtin");
const assert = std.debug.assert;
const Mutex = std.Thread.Mutex;
const Semaphore = std.Semaphore;
@@ -165,43 +159,41 @@ pub const PthreadRwLock = struct {
}
pub fn deinit(rwl: *PthreadRwLock) void {
- const safe_rc = switch (std.builtin.os.tag) {
- .dragonfly, .netbsd => std.os.EAGAIN,
- else => 0,
+ const safe_rc: std.os.E = switch (builtin.os.tag) {
+ .dragonfly, .netbsd => .AGAIN,
+ else => .SUCCESS,
};
-
const rc = std.c.pthread_rwlock_destroy(&rwl.rwlock);
- assert(rc == 0 or rc == safe_rc);
-
+ assert(rc == .SUCCESS or rc == safe_rc);
rwl.* = undefined;
}
pub fn tryLock(rwl: *PthreadRwLock) bool {
- return pthread_rwlock_trywrlock(&rwl.rwlock) == 0;
+ return pthread_rwlock_trywrlock(&rwl.rwlock) == .SUCCESS;
}
pub fn lock(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_wrlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn unlock(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_unlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn tryLockShared(rwl: *PthreadRwLock) bool {
- return pthread_rwlock_tryrdlock(&rwl.rwlock) == 0;
+ return pthread_rwlock_tryrdlock(&rwl.rwlock) == .SUCCESS;
}
pub fn lockShared(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_rdlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn unlockShared(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_unlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
};
diff --git a/lib/std/Thread/Semaphore.zig b/lib/std/Thread/Semaphore.zig
index 169975b362..b5bde88d73 100644
--- a/lib/std/Thread/Semaphore.zig
+++ b/lib/std/Thread/Semaphore.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! A semaphore is an unsigned integer that blocks the kernel thread if
//! the number would become negative.
//! This API supports static initialization and does not require deinitialization.
diff --git a/lib/std/Thread/StaticResetEvent.zig b/lib/std/Thread/StaticResetEvent.zig
index 40974938d0..d779a4de9e 100644
--- a/lib/std/Thread/StaticResetEvent.zig
+++ b/lib/std/Thread/StaticResetEvent.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! A thread-safe resource which supports blocking until signaled.
//! This API is for kernel threads, not evented I/O.
//! This API is statically initializable. It cannot fail to be initialized
@@ -201,7 +195,7 @@ pub const AtomicEvent = struct {
const waiting = std.math.maxInt(i32); // wake_count
const ptr = @ptrCast(*const i32, waiters);
const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);
- assert(linux.getErrno(rc) == 0);
+ assert(linux.getErrno(rc) == .SUCCESS);
}
fn wait(waiters: *u32, timeout: ?u64) !void {
@@ -221,10 +215,10 @@ pub const AtomicEvent = struct {
const ptr = @ptrCast(*const i32, waiters);
const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);
switch (linux.getErrno(rc)) {
- 0 => continue,
- os.ETIMEDOUT => return error.TimedOut,
- os.EINTR => continue,
- os.EAGAIN => return,
+ .SUCCESS => continue,
+ .TIMEDOUT => return error.TimedOut,
+ .INTR => continue,
+ .AGAIN => return,
else => unreachable,
}
}
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig
index 4ca603d2e8..37612a1266 100644
--- a/lib/std/array_hash_map.zig
+++ b/lib/std/array_hash_map.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const debug = std.debug;
const assert = debug.assert;
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 1e74d34922..f6ee5cdad2 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const debug = std.debug;
const assert = debug.assert;
diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig
index afaf9f8ca4..c999162b36 100644
--- a/lib/std/ascii.zig
+++ b/lib/std/ascii.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Does NOT look at the locale the way C89's toupper(3), isspace() et cetera does.
// I could have taken only a u7 to make this clear, but it would be slower
// It is my opinion that encodings other than UTF-8 should not be supported.
diff --git a/lib/std/atomic.zig b/lib/std/atomic.zig
index 42d57eb8fa..95d218736a 100644
--- a/lib/std/atomic.zig
+++ b/lib/std/atomic.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std.zig");
const target = std.Target.current;
diff --git a/lib/std/atomic/Atomic.zig b/lib/std/atomic/Atomic.zig
index f4e3ebda9d..deb364b7d3 100644
--- a/lib/std/atomic/Atomic.zig
+++ b/lib/std/atomic/Atomic.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../std.zig");
const testing = std.testing;
diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig
index cee431951c..f3781b4ce7 100644
--- a/lib/std/atomic/queue.zig
+++ b/lib/std/atomic/queue.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const assert = std.debug.assert;
diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig
index cfdf40fa60..a1747db0f5 100644
--- a/lib/std/atomic/stack.zig
+++ b/lib/std/atomic/stack.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const assert = std.debug.assert;
const builtin = std.builtin;
const expect = std.testing.expect;
diff --git a/lib/std/base64.zig b/lib/std/base64.zig
index 4b01455112..7e593900e6 100644
--- a/lib/std/base64.zig
+++ b/lib/std/base64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const assert = std.debug.assert;
const testing = std.testing;
diff --git a/lib/std/bit_set.zig b/lib/std/bit_set.zig
index 261c6af2df..dd8afb4168 100644
--- a/lib/std/bit_set.zig
+++ b/lib/std/bit_set.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! This file defines several variants of bit sets. A bit set
//! is a densely stored set of integers with a known maximum,
//! in which each integer gets a single bit. Bit sets have very
diff --git a/lib/std/bounded_array.zig b/lib/std/bounded_array.zig
new file mode 100644
index 0000000000..587251458e
--- /dev/null
+++ b/lib/std/bounded_array.zig
@@ -0,0 +1,315 @@
+const std = @import("std.zig");
+const assert = std.debug.assert;
+const mem = std.mem;
+const testing = std.testing;
+
+/// A structure with an array and a length, that can be used as a slice.
+///
+/// Useful to pass around small arrays whose exact size is only known at
+/// runtime, but whose maximum size is known at comptime, without requiring
+/// an `Allocator`.
+///
+/// ```zig
+/// var actual_size = 32;
+/// var a = try BoundedArray(u8, 64).init(actual_size);
+/// var slice = a.slice(); // a slice of the 64-byte array
+/// var a_clone = a; // creates a copy - the structure doesn't use any internal pointers
+/// ```
+pub fn BoundedArray(comptime T: type, comptime capacity: usize) type {
+ return struct {
+ const Self = @This();
+ buffer: [capacity]T,
+ len: usize = 0,
+
+ /// Set the actual length of the slice.
+ /// Returns error.Overflow if it exceeds the length of the backing array.
+ pub fn init(len: usize) !Self {
+ if (len > capacity) return error.Overflow;
+ return Self{ .buffer = undefined, .len = len };
+ }
+
+ /// View the internal array as a mutable slice whose size was previously set.
+ pub fn slice(self: *Self) []T {
+ return self.buffer[0..self.len];
+ }
+
+ /// View the internal array as a constant slice whose size was previously set.
+ pub fn constSlice(self: Self) []const T {
+ return self.buffer[0..self.len];
+ }
+
+ /// Adjust the slice's length to `len`.
+ /// Does not initialize added items if any.
+ pub fn resize(self: *Self, len: usize) !void {
+ if (len > capacity) return error.Overflow;
+ self.len = len;
+ }
+
+ /// Copy the content of an existing slice.
+ pub fn fromSlice(m: []const T) !Self {
+ var list = try init(m.len);
+ std.mem.copy(T, list.slice(), m);
+ return list;
+ }
+
+ /// Return the element at index `i` of the slice.
+ pub fn get(self: Self, i: usize) T {
+ return self.constSlice()[i];
+ }
+
+ /// Set the value of the element at index `i` of the slice.
+ pub fn set(self: *Self, i: usize, item: T) void {
+ self.slice()[i] = item;
+ }
+
+ /// Return the maximum length of a slice.
+ pub fn capacity(self: Self) usize {
+ return self.buffer.len;
+ }
+
+ /// Check that the slice can hold at least `additional_count` items.
+ pub fn ensureUnusedCapacity(self: Self, additional_count: usize) !void {
+ if (self.len + additional_count > capacity) {
+ return error.Overflow;
+ }
+ }
+
+ /// Increase length by 1, returning a pointer to the new item.
+ pub fn addOne(self: *Self) !*T {
+ try self.ensureUnusedCapacity(1);
+ return self.addOneAssumeCapacity();
+ }
+
+ /// Increase length by 1, returning pointer to the new item.
+ /// Asserts that there is space for the new item.
+ pub fn addOneAssumeCapacity(self: *Self) *T {
+ assert(self.len < capacity);
+ self.len += 1;
+ return &self.slice()[self.len - 1];
+ }
+
+ /// Resize the slice, adding `n` new elements, which have `undefined` values.
+ /// The return value is a slice pointing to the uninitialized elements.
+ pub fn addManyAsArray(self: *Self, comptime n: usize) !*[n]T {
+ const prev_len = self.len;
+ try self.resize(self.len + n);
+ return self.slice()[prev_len..][0..n];
+ }
+
+ /// Remove and return the last element from the slice.
+ /// Asserts the slice has at least one item.
+ pub fn pop(self: *Self) T {
+ const item = self.get(self.len - 1);
+ self.len -= 1;
+ return item;
+ }
+
+ /// Remove and return the last element from the slice, or
+ /// return `null` if the slice is empty.
+ pub fn popOrNull(self: *Self) ?T {
+ return if (self.len == 0) null else self.pop();
+ }
+
+ /// Return a slice of only the extra capacity after items.
+ /// This can be useful for writing directly into it.
+ /// Note that such an operation must be followed up with a
+ /// call to `resize()`
+ pub fn unusedCapacitySlice(self: *Self) []T {
+ return self.buffer[self.len..];
+ }
+
+ /// Insert `item` at index `i` by moving `slice[n .. slice.len]` to make room.
+ /// This operation is O(N).
+ pub fn insert(self: *Self, i: usize, item: T) !void {
+ if (i >= self.len) {
+ return error.IndexOutOfBounds;
+ }
+ _ = try self.addOne();
+ var s = self.slice();
+ mem.copyBackwards(T, s[i + 1 .. s.len], s[i .. s.len - 1]);
+ self.buffer[i] = item;
+ }
+
+ /// Insert slice `items` at index `i` by moving `slice[i .. slice.len]` to make room.
+ /// This operation is O(N).
+ pub fn insertSlice(self: *Self, i: usize, items: []const T) !void {
+ try self.ensureUnusedCapacity(items.len);
+ self.len += items.len;
+ mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);
+ mem.copy(T, self.slice()[i .. i + items.len], items);
+ }
+
+ /// Replace range of elements `slice[start..start+len]` with `new_items`.
+ /// Grows slice if `len < new_items.len`.
+ /// Shrinks slice if `len > new_items.len`.
+ pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) !void {
+ const after_range = start + len;
+ var range = self.slice()[start..after_range];
+
+ if (range.len == new_items.len) {
+ mem.copy(T, range, new_items);
+ } else if (range.len < new_items.len) {
+ const first = new_items[0..range.len];
+ const rest = new_items[range.len..];
+ mem.copy(T, range, first);
+ try self.insertSlice(after_range, rest);
+ } else {
+ mem.copy(T, range, new_items);
+ const after_subrange = start + new_items.len;
+ for (self.constSlice()[after_range..]) |item, i| {
+ self.slice()[after_subrange..][i] = item;
+ }
+ self.len -= len - new_items.len;
+ }
+ }
+
+ /// Extend the slice by 1 element.
+ pub fn append(self: *Self, item: T) !void {
+ const new_item_ptr = try self.addOne();
+ new_item_ptr.* = item;
+ }
+
+ /// Remove the element at index `i`, shift elements after index
+ /// `i` forward, and return the removed element.
+ /// Asserts the slice has at least one item.
+ /// This operation is O(N).
+ pub fn orderedRemove(self: *Self, i: usize) T {
+ const newlen = self.len - 1;
+ if (newlen == i) return self.pop();
+ const old_item = self.get(i);
+ for (self.slice()[i..newlen]) |*b, j| b.* = self.get(i + 1 + j);
+ self.set(newlen, undefined);
+ self.len = newlen;
+ return old_item;
+ }
+
+ /// Remove the element at the specified index and return it.
+ /// The empty slot is filled from the end of the slice.
+ /// This operation is O(1).
+ pub fn swapRemove(self: *Self, i: usize) T {
+ if (self.len - 1 == i) return self.pop();
+ const old_item = self.get(i);
+ self.set(i, self.pop());
+ return old_item;
+ }
+
+ /// Append the slice of items to the slice.
+ pub fn appendSlice(self: *Self, items: []const T) !void {
+ try self.ensureUnusedCapacity(items.len);
+ self.appendSliceAssumeCapacity(items);
+ }
+
+ /// Append the slice of items to the slice, asserting the capacity is already
+ /// enough to store the new items.
+ pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
+ const oldlen = self.len;
+ self.len += items.len;
+ mem.copy(T, self.slice()[oldlen..], items);
+ }
+
+ /// Append a value to the slice `n` times.
+ /// Allocates more memory as necessary.
+ pub fn appendNTimes(self: *Self, value: T, n: usize) !void {
+ const old_len = self.len;
+ try self.resize(old_len + n);
+ mem.set(T, self.slice()[old_len..self.len], value);
+ }
+
+ /// Append a value to the slice `n` times.
+ /// Asserts the capacity is enough.
+ pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
+ const old_len = self.len;
+ self.len += n;
+ assert(self.len <= capacity);
+ mem.set(T, self.slice()[old_len..self.len], value);
+ }
+ };
+}
+
+test "BoundedArray" {
+ var a = try BoundedArray(u8, 64).init(32);
+
+ try testing.expectEqual(a.capacity(), 64);
+ try testing.expectEqual(a.slice().len, 32);
+ try testing.expectEqual(a.constSlice().len, 32);
+
+ try a.resize(48);
+ try testing.expectEqual(a.len, 48);
+
+ const x = [_]u8{1} ** 10;
+ a = try BoundedArray(u8, 64).fromSlice(&x);
+ try testing.expectEqualSlices(u8, &x, a.constSlice());
+
+ var a2 = a;
+ try testing.expectEqualSlices(u8, a.constSlice(), a.constSlice());
+ a2.set(0, 0);
+ try testing.expect(a.get(0) != a2.get(0));
+
+ try testing.expectError(error.Overflow, a.resize(100));
+ try testing.expectError(error.Overflow, BoundedArray(u8, x.len - 1).fromSlice(&x));
+
+ try a.resize(0);
+ try a.ensureUnusedCapacity(a.capacity());
+ (try a.addOne()).* = 0;
+ try a.ensureUnusedCapacity(a.capacity() - 1);
+ try testing.expectEqual(a.len, 1);
+
+ const uninitialized = try a.addManyAsArray(4);
+ try testing.expectEqual(uninitialized.len, 4);
+ try testing.expectEqual(a.len, 5);
+
+ try a.append(0xff);
+ try testing.expectEqual(a.len, 6);
+ try testing.expectEqual(a.pop(), 0xff);
+
+ try a.resize(1);
+ try testing.expectEqual(a.popOrNull(), 0);
+ try testing.expectEqual(a.popOrNull(), null);
+ var unused = a.unusedCapacitySlice();
+ mem.set(u8, unused[0..8], 2);
+ unused[8] = 3;
+ unused[9] = 4;
+ try testing.expectEqual(unused.len, a.capacity());
+ try a.resize(10);
+
+ try a.insert(5, 0xaa);
+ try testing.expectEqual(a.len, 11);
+ try testing.expectEqual(a.get(5), 0xaa);
+ try testing.expectEqual(a.get(9), 3);
+ try testing.expectEqual(a.get(10), 4);
+
+ try a.appendSlice(&x);
+ try testing.expectEqual(a.len, 11 + x.len);
+
+ try a.appendNTimes(0xbb, 5);
+ try testing.expectEqual(a.len, 11 + x.len + 5);
+ try testing.expectEqual(a.pop(), 0xbb);
+
+ a.appendNTimesAssumeCapacity(0xcc, 5);
+ try testing.expectEqual(a.len, 11 + x.len + 5 - 1 + 5);
+ try testing.expectEqual(a.pop(), 0xcc);
+
+ try testing.expectEqual(a.len, 29);
+ try a.replaceRange(1, 20, &x);
+ try testing.expectEqual(a.len, 29 + x.len - 20);
+
+ try a.insertSlice(0, &x);
+ try testing.expectEqual(a.len, 29 + x.len - 20 + x.len);
+
+ try a.replaceRange(1, 5, &x);
+ try testing.expectEqual(a.len, 29 + x.len - 20 + x.len + x.len - 5);
+
+ try a.append(10);
+ try testing.expectEqual(a.pop(), 10);
+
+ try a.append(20);
+ const removed = a.orderedRemove(5);
+ try testing.expectEqual(removed, 1);
+ try testing.expectEqual(a.len, 34);
+
+ a.set(0, 0xdd);
+ a.set(a.len - 1, 0xee);
+ const swapped = a.swapRemove(0);
+ try testing.expectEqual(swapped, 0xdd);
+ try testing.expectEqual(a.get(0), 0xee);
+}
diff --git a/lib/std/buf_map.zig b/lib/std/buf_map.zig
index 3494fce032..1e4462e6ae 100644
--- a/lib/std/buf_map.zig
+++ b/lib/std/buf_map.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const StringHashMap = std.StringHashMap;
const mem = std.mem;
diff --git a/lib/std/buf_set.zig b/lib/std/buf_set.zig
index c2a1f9bcb9..ce2d51b056 100644
--- a/lib/std/buf_set.zig
+++ b/lib/std/buf_set.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const StringHashMap = std.StringHashMap;
const mem = @import("mem.zig");
diff --git a/lib/std/build.zig b/lib/std/build.zig
index efb305d4a3..afbe580f6d 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const io = std.io;
@@ -28,6 +23,7 @@ pub const WriteFileStep = @import("build/WriteFileStep.zig");
pub const RunStep = @import("build/RunStep.zig");
pub const CheckFileStep = @import("build/CheckFileStep.zig");
pub const InstallRawStep = @import("build/InstallRawStep.zig");
+pub const OptionsStep = @import("build/OptionsStep.zig");
pub const Builder = struct {
install_tls: TopLevelStep,
@@ -252,6 +248,10 @@ pub const Builder = struct {
return LibExeObjStep.createExecutable(builder, name, root_src);
}
+ pub fn addOptions(self: *Builder) *OptionsStep {
+ return OptionsStep.create(self);
+ }
+
pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
return addObjectSource(self, name, convertOptionalPathToFileSource(root_src));
}
@@ -1380,16 +1380,6 @@ pub const FileSource = union(enum) {
}
};
-const BuildOptionArtifactArg = struct {
- name: []const u8,
- artifact: *LibExeObjStep,
-};
-
-const BuildOptionFileSourceArg = struct {
- name: []const u8,
- source: FileSource,
-};
-
pub const LibExeObjStep = struct {
pub const base_id = .lib_exe_obj;
@@ -1432,15 +1422,13 @@ pub const LibExeObjStep = struct {
single_threaded: bool,
test_evented_io: bool = false,
code_model: builtin.CodeModel = .default,
+ wasi_exec_model: ?builtin.WasiExecModel = null,
root_src: ?FileSource,
out_h_filename: []const u8,
out_lib_filename: []const u8,
out_pdb_filename: []const u8,
packages: ArrayList(Pkg),
- build_options_contents: std.ArrayList(u8),
- build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg),
- build_options_file_source_args: std.ArrayList(BuildOptionFileSourceArg),
object_src: []const u8,
@@ -1607,9 +1595,6 @@ pub const LibExeObjStep = struct {
.rpaths = ArrayList([]const u8).init(builder.allocator),
.framework_dirs = ArrayList([]const u8).init(builder.allocator),
.object_src = undefined,
- .build_options_contents = std.ArrayList(u8).init(builder.allocator),
- .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator),
- .build_options_file_source_args = std.ArrayList(BuildOptionFileSourceArg).init(builder.allocator),
.c_std = Builder.CStd.C99,
.override_lib_dir = null,
.main_pkg_path = null,
@@ -1735,7 +1720,6 @@ pub const LibExeObjStep = struct {
}
pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {
- assert(self.target.isDarwin());
// Note: No need to dupe because frameworks dupes internally.
self.frameworks.insert(framework_name) catch unreachable;
}
@@ -2043,119 +2027,6 @@ pub const LibExeObjStep = struct {
self.linkLibraryOrObject(obj);
}
- pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
- const out = self.build_options_contents.writer();
- switch (T) {
- []const []const u8 => {
- out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{std.zig.fmtId(name)}) catch unreachable;
- for (value) |slice| {
- out.print(" \"{}\",\n", .{std.zig.fmtEscapes(slice)}) catch unreachable;
- }
- out.writeAll("};\n") catch unreachable;
- return;
- },
- [:0]const u8 => {
- out.print("pub const {}: [:0]const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
- return;
- },
- []const u8 => {
- out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
- return;
- },
- ?[:0]const u8 => {
- out.print("pub const {}: ?[:0]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
- if (value) |payload| {
- out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
- } else {
- out.writeAll("null;\n") catch unreachable;
- }
- return;
- },
- ?[]const u8 => {
- out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
- if (value) |payload| {
- out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
- } else {
- out.writeAll("null;\n") catch unreachable;
- }
- return;
- },
- std.builtin.Version => {
- out.print(
- \\pub const {}: @import("std").builtin.Version = .{{
- \\ .major = {d},
- \\ .minor = {d},
- \\ .patch = {d},
- \\}};
- \\
- , .{
- std.zig.fmtId(name),
-
- value.major,
- value.minor,
- value.patch,
- }) catch unreachable;
- },
- std.SemanticVersion => {
- out.print(
- \\pub const {}: @import("std").SemanticVersion = .{{
- \\ .major = {d},
- \\ .minor = {d},
- \\ .patch = {d},
- \\
- , .{
- std.zig.fmtId(name),
-
- value.major,
- value.minor,
- value.patch,
- }) catch unreachable;
- if (value.pre) |some| {
- out.print(" .pre = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
- }
- if (value.build) |some| {
- out.print(" .build = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
- }
- out.writeAll("};\n") catch unreachable;
- return;
- },
- else => {},
- }
- switch (@typeInfo(T)) {
- .Enum => |enum_info| {
- out.print("pub const {} = enum {{\n", .{std.zig.fmtId(@typeName(T))}) catch unreachable;
- inline for (enum_info.fields) |field| {
- out.print(" {},\n", .{std.zig.fmtId(field.name)}) catch unreachable;
- }
- out.writeAll("};\n") catch unreachable;
- },
- else => {},
- }
- out.print("pub const {}: {s} = {};\n", .{ std.zig.fmtId(name), @typeName(T), value }) catch unreachable;
- }
-
- /// The value is the path in the cache dir.
- /// Adds a dependency automatically.
- pub fn addBuildOptionArtifact(self: *LibExeObjStep, name: []const u8, artifact: *LibExeObjStep) void {
- self.build_options_artifact_args.append(.{ .name = self.builder.dupe(name), .artifact = artifact }) catch unreachable;
- self.step.dependOn(&artifact.step);
- }
-
- /// The value is the path in the cache dir.
- /// Adds a dependency automatically.
- /// basename refers to the basename of the WriteFileStep
- pub fn addBuildOptionFileSource(
- self: *LibExeObjStep,
- name: []const u8,
- source: FileSource,
- ) void {
- self.build_options_file_source_args.append(.{
- .name = name,
- .source = source.dupe(self.builder),
- }) catch unreachable;
- source.addStepDependencies(&self.step);
- }
-
pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void {
self.include_dirs.append(IncludeDir{ .raw_path_system = self.builder.dupe(path) }) catch unreachable;
}
@@ -2181,6 +2052,10 @@ pub const LibExeObjStep = struct {
self.addRecursiveBuildDeps(package);
}
+ pub fn addOptions(self: *LibExeObjStep, package_name: []const u8, options: *OptionsStep) void {
+ self.addPackage(options.getPackage(package_name));
+ }
+
fn addRecursiveBuildDeps(self: *LibExeObjStep, package: Pkg) void {
package.path.addStepDependencies(&self.step);
if (package.dependencies) |deps| {
@@ -2247,28 +2122,6 @@ pub const LibExeObjStep = struct {
self.step.dependOn(&other.step);
self.link_objects.append(.{ .other_step = other }) catch unreachable;
self.include_dirs.append(.{ .other_step = other }) catch unreachable;
-
- // BUG: The following code introduces a order-of-call dependency:
- // var lib = addSharedLibrary(...);
- // var exe = addExecutable(...);
- // exe.linkLibrary(lib);
- // lib.linkSystemLibrary("foobar"); // this will be ignored for exe!
-
- // Inherit dependency on system libraries
- for (other.link_objects.items) |link_object| {
- switch (link_object) {
- .system_lib => |name| self.linkSystemLibrary(name),
- else => continue,
- }
- }
-
- // Inherit dependencies on darwin frameworks
- if (self.target.isDarwin() and !other.isDynamicLibrary()) {
- var it = other.frameworks.iterator();
- while (it.next()) |framework| {
- self.frameworks.insert(framework.*) catch unreachable;
- }
- }
}
fn makePackageCmd(self: *LibExeObjStep, pkg: Pkg, zig_args: *ArrayList([]const u8)) error{OutOfMemory}!void {
@@ -2322,6 +2175,31 @@ pub const LibExeObjStep = struct {
if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder));
var prev_has_extra_flags = false;
+
+ // Resolve transitive dependencies
+ for (self.link_objects.items) |link_object| {
+ switch (link_object) {
+ .other_step => |other| {
+ // Inherit dependency on system libraries
+ for (other.link_objects.items) |other_link_object| {
+ switch (other_link_object) {
+ .system_lib => |name| self.linkSystemLibrary(name),
+ else => continue,
+ }
+ }
+
+ // Inherit dependencies on darwin frameworks
+ if (!other.isDynamicLibrary()) {
+ var it = other.frameworks.iterator();
+ while (it.next()) |framework| {
+ self.frameworks.insert(framework.*) catch unreachable;
+ }
+ }
+ },
+ else => continue,
+ }
+ }
+
for (self.link_objects.items) |link_object| {
switch (link_object) {
.static_path => |static_path| try zig_args.append(static_path.getPath(builder)),
@@ -2395,41 +2273,6 @@ pub const LibExeObjStep = struct {
}
}
- if (self.build_options_contents.items.len > 0 or
- self.build_options_artifact_args.items.len > 0 or
- self.build_options_file_source_args.items.len > 0)
- {
- // Render build artifact and write file options at the last minute, now that the path is known.
- //
- // Note that pathFromRoot uses resolve path, so this will have
- // correct behavior even if getOutputPath is already absolute.
- for (self.build_options_artifact_args.items) |item| {
- self.addBuildOption(
- []const u8,
- item.name,
- self.builder.pathFromRoot(item.artifact.getOutputSource().getPath(self.builder)),
- );
- }
- for (self.build_options_file_source_args.items) |item| {
- self.addBuildOption(
- []const u8,
- item.name,
- item.source.getPath(self.builder),
- );
- }
-
- const build_options_file = try fs.path.join(
- builder.allocator,
- &[_][]const u8{ builder.cache_root, builder.fmt("{s}_build_options.zig", .{self.name}) },
- );
- const path_from_root = builder.pathFromRoot(build_options_file);
- try fs.cwd().writeFile(path_from_root, self.build_options_contents.items);
- try zig_args.append("--pkg-begin");
- try zig_args.append("build_options");
- try zig_args.append(path_from_root);
- try zig_args.append("--pkg-end");
- }
-
if (self.image_base) |image_base| {
try zig_args.append("--image-base");
try zig_args.append(builder.fmt("0x{x}", .{image_base}));
@@ -2547,6 +2390,9 @@ pub const LibExeObjStep = struct {
try zig_args.append("-mcmodel");
try zig_args.append(@tagName(self.code_model));
}
+ if (self.wasi_exec_model) |model| {
+ try zig_args.append(builder.fmt("-mexec-model={s}", .{@tagName(model)}));
+ }
if (!self.target.isNative()) {
try zig_args.append("-target");
@@ -2719,6 +2565,14 @@ pub const LibExeObjStep = struct {
zig_args.append("-framework") catch unreachable;
zig_args.append(framework.*) catch unreachable;
}
+ } else {
+ if (self.framework_dirs.items.len > 0) {
+ warn("Framework directories have been added for a non-darwin target, this will have no affect on the build\n", .{});
+ }
+
+ if (self.frameworks.count() > 0) {
+ warn("Frameworks have been added for a non-darwin target, this will have no affect on the build\n", .{});
+ }
}
if (builder.sysroot) |sysroot| {
@@ -3026,7 +2880,8 @@ pub const InstallDirStep = struct {
const self = @fieldParentPtr(InstallDirStep, "step", step);
const dest_prefix = self.builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
const full_src_dir = self.builder.pathFromRoot(self.options.source_dir);
- const src_dir = try std.fs.cwd().openDir(full_src_dir, .{ .iterate = true });
+ var src_dir = try std.fs.cwd().openDir(full_src_dir, .{ .iterate = true });
+ defer src_dir.close();
var it = try src_dir.walk(self.builder.allocator);
next_entry: while (try it.next()) |entry| {
for (self.options.exclude_extensions) |ext| {
@@ -3131,6 +2986,7 @@ pub const Step = struct {
run,
check_file,
install_raw,
+ options,
custom,
};
@@ -3302,43 +3158,6 @@ test "Builder.dupePkg()" {
try std.testing.expect(dupe_deps[0].path.path.ptr != pkg_dep.path.path.ptr);
}
-test "LibExeObjStep.addBuildOption" {
- if (builtin.os.tag == .wasi) return error.SkipZigTest;
-
- var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer arena.deinit();
- var builder = try Builder.create(
- &arena.allocator,
- "test",
- "test",
- "test",
- "test",
- );
- defer builder.destroy();
-
- var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
- exe.addBuildOption(usize, "option1", 1);
- exe.addBuildOption(?usize, "option2", null);
- exe.addBuildOption([]const u8, "string", "zigisthebest");
- exe.addBuildOption(?[]const u8, "optional_string", null);
- exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
-
- try std.testing.expectEqualStrings(
- \\pub const option1: usize = 1;
- \\pub const option2: ?usize = null;
- \\pub const string: []const u8 = "zigisthebest";
- \\pub const optional_string: ?[]const u8 = null;
- \\pub const semantic_version: @import("std").SemanticVersion = .{
- \\ .major = 0,
- \\ .minor = 1,
- \\ .patch = 2,
- \\ .pre = "foo",
- \\ .build = "bar",
- \\};
- \\
- , exe.build_options_contents.items);
-}
-
test "LibExeObjStep.addPackage" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
diff --git a/lib/std/build/CheckFileStep.zig b/lib/std/build/CheckFileStep.zig
index 1f1ed0884e..2b433b5448 100644
--- a/lib/std/build/CheckFileStep.zig
+++ b/lib/std/build/CheckFileStep.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const build = std.build;
const Step = build.Step;
diff --git a/lib/std/build/FmtStep.zig b/lib/std/build/FmtStep.zig
index 82faf32be9..62923623f2 100644
--- a/lib/std/build/FmtStep.zig
+++ b/lib/std/build/FmtStep.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const build = @import("../build.zig");
const Step = build.Step;
diff --git a/lib/std/build/InstallRawStep.zig b/lib/std/build/InstallRawStep.zig
index 743b25f3cd..39a2d29845 100644
--- a/lib/std/build/InstallRawStep.zig
+++ b/lib/std/build/InstallRawStep.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const Allocator = std.mem.Allocator;
diff --git a/lib/std/build/OptionsStep.zig b/lib/std/build/OptionsStep.zig
new file mode 100644
index 0000000000..2440fce16d
--- /dev/null
+++ b/lib/std/build/OptionsStep.zig
@@ -0,0 +1,257 @@
+const std = @import("../std.zig");
+const build = std.build;
+const fs = std.fs;
+const Step = build.Step;
+const Builder = build.Builder;
+const GeneratedFile = build.GeneratedFile;
+const LibExeObjStep = build.LibExeObjStep;
+const FileSource = build.FileSource;
+
+const OptionsStep = @This();
+
+step: Step,
+generated_file: GeneratedFile,
+builder: *Builder,
+
+contents: std.ArrayList(u8),
+artifact_args: std.ArrayList(OptionArtifactArg),
+file_source_args: std.ArrayList(OptionFileSourceArg),
+
+pub fn create(builder: *Builder) *OptionsStep {
+ const self = builder.allocator.create(OptionsStep) catch unreachable;
+ self.* = .{
+ .builder = builder,
+ .step = Step.init(.options, "options", builder.allocator, make),
+ .generated_file = undefined,
+ .contents = std.ArrayList(u8).init(builder.allocator),
+ .artifact_args = std.ArrayList(OptionArtifactArg).init(builder.allocator),
+ .file_source_args = std.ArrayList(OptionFileSourceArg).init(builder.allocator),
+ };
+ self.generated_file = .{ .step = &self.step };
+
+ return self;
+}
+
+pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value: T) void {
+ const out = self.contents.writer();
+ switch (T) {
+ []const []const u8 => {
+ out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{std.zig.fmtId(name)}) catch unreachable;
+ for (value) |slice| {
+ out.print(" \"{}\",\n", .{std.zig.fmtEscapes(slice)}) catch unreachable;
+ }
+ out.writeAll("};\n") catch unreachable;
+ return;
+ },
+ [:0]const u8 => {
+ out.print("pub const {}: [:0]const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
+ return;
+ },
+ []const u8 => {
+ out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
+ return;
+ },
+ ?[:0]const u8 => {
+ out.print("pub const {}: ?[:0]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
+ if (value) |payload| {
+ out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
+ } else {
+ out.writeAll("null;\n") catch unreachable;
+ }
+ return;
+ },
+ ?[]const u8 => {
+ out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
+ if (value) |payload| {
+ out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
+ } else {
+ out.writeAll("null;\n") catch unreachable;
+ }
+ return;
+ },
+ std.builtin.Version => {
+ out.print(
+ \\pub const {}: @import("std").builtin.Version = .{{
+ \\ .major = {d},
+ \\ .minor = {d},
+ \\ .patch = {d},
+ \\}};
+ \\
+ , .{
+ std.zig.fmtId(name),
+
+ value.major,
+ value.minor,
+ value.patch,
+ }) catch unreachable;
+ },
+ std.SemanticVersion => {
+ out.print(
+ \\pub const {}: @import("std").SemanticVersion = .{{
+ \\ .major = {d},
+ \\ .minor = {d},
+ \\ .patch = {d},
+ \\
+ , .{
+ std.zig.fmtId(name),
+
+ value.major,
+ value.minor,
+ value.patch,
+ }) catch unreachable;
+ if (value.pre) |some| {
+ out.print(" .pre = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
+ }
+ if (value.build) |some| {
+ out.print(" .build = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
+ }
+ out.writeAll("};\n") catch unreachable;
+ return;
+ },
+ else => {},
+ }
+ switch (@typeInfo(T)) {
+ .Enum => |enum_info| {
+ out.print("pub const {} = enum {{\n", .{std.zig.fmtId(@typeName(T))}) catch unreachable;
+ inline for (enum_info.fields) |field| {
+ out.print(" {},\n", .{std.zig.fmtId(field.name)}) catch unreachable;
+ }
+ out.writeAll("};\n") catch unreachable;
+ },
+ else => {},
+ }
+ out.print("pub const {}: {s} = {};\n", .{ std.zig.fmtId(name), @typeName(T), value }) catch unreachable;
+}
+
+/// The value is the path in the cache dir.
+/// Adds a dependency automatically.
+pub fn addOptionFileSource(
+ self: *OptionsStep,
+ name: []const u8,
+ source: FileSource,
+) void {
+ self.file_source_args.append(.{
+ .name = name,
+ .source = source.dupe(self.builder),
+ }) catch unreachable;
+ source.addStepDependencies(&self.step);
+}
+
+/// The value is the path in the cache dir.
+/// Adds a dependency automatically.
+pub fn addOptionArtifact(self: *OptionsStep, name: []const u8, artifact: *LibExeObjStep) void {
+ self.artifact_args.append(.{ .name = self.builder.dupe(name), .artifact = artifact }) catch unreachable;
+ self.step.dependOn(&artifact.step);
+}
+
+pub fn getPackage(self: OptionsStep, package_name: []const u8) build.Pkg {
+ return .{ .name = package_name, .path = self.getSource() };
+}
+
+pub fn getSource(self: OptionsStep) FileSource {
+ return .{ .generated = &self.generated_file };
+}
+
+fn make(step: *Step) !void {
+ const self = @fieldParentPtr(OptionsStep, "step", step);
+
+ for (self.artifact_args.items) |item| {
+ self.addOption(
+ []const u8,
+ item.name,
+ self.builder.pathFromRoot(item.artifact.getOutputSource().getPath(self.builder)),
+ );
+ }
+
+ for (self.file_source_args.items) |item| {
+ self.addOption(
+ []const u8,
+ item.name,
+ item.source.getPath(self.builder),
+ );
+ }
+
+ const options_directory = self.builder.pathFromRoot(
+ try fs.path.join(
+ self.builder.allocator,
+ &[_][]const u8{ self.builder.cache_root, "options" },
+ ),
+ );
+
+ try fs.cwd().makePath(options_directory);
+
+ const options_file = try fs.path.join(
+ self.builder.allocator,
+ &[_][]const u8{ options_directory, &self.hashContentsToFileName() },
+ );
+
+ try fs.cwd().writeFile(options_file, self.contents.items);
+
+ self.generated_file.path = options_file;
+}
+
+fn hashContentsToFileName(self: *OptionsStep) [64]u8 {
+ // This implementation is copied from `WriteFileStep.make`
+
+ var hash = std.crypto.hash.blake2.Blake2b384.init(.{});
+
+ // Random bytes to make OptionsStep unique. Refresh this with
+ // new random bytes when OptionsStep implementation is modified
+ // in a non-backwards-compatible way.
+ hash.update("yL0Ya4KkmcCjBlP8");
+ hash.update(self.contents.items);
+
+ var digest: [48]u8 = undefined;
+ hash.final(&digest);
+ var hash_basename: [64]u8 = undefined;
+ _ = fs.base64_encoder.encode(&hash_basename, &digest);
+ return hash_basename;
+}
+
+const OptionArtifactArg = struct {
+ name: []const u8,
+ artifact: *LibExeObjStep,
+};
+
+const OptionFileSourceArg = struct {
+ name: []const u8,
+ source: FileSource,
+};
+
+test "OptionsStep" {
+ if (std.builtin.os.tag == .wasi) return error.SkipZigTest;
+
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena.deinit();
+ var builder = try Builder.create(
+ &arena.allocator,
+ "test",
+ "test",
+ "test",
+ "test",
+ );
+ defer builder.destroy();
+
+ const options = builder.addOptions();
+
+ options.addOption(usize, "option1", 1);
+ options.addOption(?usize, "option2", null);
+ options.addOption([]const u8, "string", "zigisthebest");
+ options.addOption(?[]const u8, "optional_string", null);
+ options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
+
+ try std.testing.expectEqualStrings(
+ \\pub const option1: usize = 1;
+ \\pub const option2: ?usize = null;
+ \\pub const string: []const u8 = "zigisthebest";
+ \\pub const optional_string: ?[]const u8 = null;
+ \\pub const semantic_version: @import("std").SemanticVersion = .{
+ \\ .major = 0,
+ \\ .minor = 1,
+ \\ .patch = 2,
+ \\ .pre = "foo",
+ \\ .build = "bar",
+ \\};
+ \\
+ , options.contents.items);
+}
diff --git a/lib/std/build/RunStep.zig b/lib/std/build/RunStep.zig
index 89d9cd911c..67929b6f5d 100644
--- a/lib/std/build/RunStep.zig
+++ b/lib/std/build/RunStep.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const build = std.build;
diff --git a/lib/std/build/TranslateCStep.zig b/lib/std/build/TranslateCStep.zig
index 2f209b80b4..0d44ebd80a 100644
--- a/lib/std/build/TranslateCStep.zig
+++ b/lib/std/build/TranslateCStep.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const build = std.build;
const Step = build.Step;
diff --git a/lib/std/build/WriteFileStep.zig b/lib/std/build/WriteFileStep.zig
index 1287942110..5a8d806049 100644
--- a/lib/std/build/WriteFileStep.zig
+++ b/lib/std/build/WriteFileStep.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const build = @import("../build.zig");
const Step = build.Step;
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index 6643e07837..bb35d61375 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
// These are all deprecated.
@@ -237,7 +232,7 @@ pub const TypeInfo = union(enum) {
/// This field is an optional type.
/// The type of the sentinel is the element type of the pointer, which is
/// the value of the `child` field in this struct. However there is no way
- /// to refer to that type here, so we use `var`.
+ /// to refer to that type here, so we use `anytype`.
sentinel: anytype,
/// This data structure is used by the Zig language code generation and
@@ -259,7 +254,7 @@ pub const TypeInfo = union(enum) {
/// This field is an optional type.
/// The type of the sentinel is the element type of the array, which is
/// the value of the `child` field in this struct. However there is no way
- /// to refer to that type here, so we use `var`.
+ /// to refer to that type here, so we use `anytype`.
sentinel: anytype,
};
@@ -671,7 +666,12 @@ pub const PanicFn = fn ([]const u8, ?*StackTrace) noreturn;
/// This function is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
-pub const panic: PanicFn = if (@hasDecl(root, "panic")) root.panic else default_panic;
+pub const panic: PanicFn = if (@hasDecl(root, "panic"))
+ root.panic
+else if (@hasDecl(root, "os") and @hasDecl(root.os, "panic"))
+ root.os.panic
+else
+ default_panic;
/// This function is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
@@ -684,10 +684,6 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
@breakpoint();
}
}
- if (@hasDecl(root, "os") and @hasDecl(root.os, "panic")) {
- root.os.panic(msg, error_return_trace);
- unreachable;
- }
switch (os.tag) {
.freestanding => {
while (true) {
diff --git a/lib/std/c.zig b/lib/std/c.zig
index c8b3020dc7..0ad69f873f 100644
--- a/lib/std/c.zig
+++ b/lib/std/c.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const page_size = std.mem.page_size;
@@ -35,11 +30,11 @@ pub usingnamespace switch (std.Target.current.os.tag) {
else => struct {},
};
-pub fn getErrno(rc: anytype) c_int {
+pub fn getErrno(rc: anytype) E {
if (rc == -1) {
- return _errno().*;
+ return @intToEnum(E, _errno().*);
} else {
- return 0;
+ return .SUCCESS;
}
}
@@ -270,22 +265,22 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
-pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) c_int;
-pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
-pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
-pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int;
-pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
-pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
+pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) E;
+pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
+pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) E;
+pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E;
+pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E;
+pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E;
pub extern "c" fn pthread_self() pthread_t;
-pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
-pub extern "c" fn pthread_detach(thread: pthread_t) c_int;
+pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) E;
+pub extern "c" fn pthread_detach(thread: pthread_t) E;
pub extern "c" fn pthread_atfork(
prepare: ?fn () callconv(.C) void,
parent: ?fn () callconv(.C) void,
child: ?fn () callconv(.C) void,
) c_int;
-pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) c_int;
-pub extern "c" fn pthread_key_delete(key: pthread_key_t) c_int;
+pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) E;
+pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void;
pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int;
pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
@@ -339,24 +334,24 @@ pub extern "c" fn dn_expand(
) c_int;
pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
-pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
-pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
-pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int;
-pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int;
+pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};
-pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int;
-pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) c_int;
-pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int;
-pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int;
-pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int;
+pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E;
+pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
+pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
+pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
-pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) c_int;
-pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
-pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
-pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
-pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
-pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
+pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub const pthread_t = *opaque {};
pub const FILE = opaque {};
diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig
index 22473a3899..7fa07719a8 100644
--- a/lib/std/c/darwin.zig
+++ b/lib/std/c/darwin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = @import("builtin");
@@ -193,8 +188,8 @@ pub const pthread_attr_t = extern struct {
const pthread_t = std.c.pthread_t;
pub extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;
-pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
-pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
+pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E;
+pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig
index 7d722dad44..e5786d2bd4 100644
--- a/lib/std/c/dragonfly.zig
+++ b/lib/std/c/dragonfly.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
usingnamespace std.c;
extern "c" threadlocal var errno: c_int;
diff --git a/lib/std/c/emscripten.zig b/lib/std/c/emscripten.zig
index 526eb9e99c..0d78d4d73f 100644
--- a/lib/std/c/emscripten.zig
+++ b/lib/std/c/emscripten.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const pthread_mutex_t = extern struct {
size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(4) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
};
diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig
index eb449165d3..f7d1e07608 100644
--- a/lib/std/c/freebsd.zig
+++ b/lib/std/c/freebsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
usingnamespace std.c;
diff --git a/lib/std/c/fuchsia.zig b/lib/std/c/fuchsia.zig
index fc34f49d22..af6c4756b9 100644
--- a/lib/std/c/fuchsia.zig
+++ b/lib/std/c/fuchsia.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const pthread_mutex_t = extern struct {
size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
};
diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig
index fcf99db571..be6c180bed 100644
--- a/lib/std/c/haiku.zig
+++ b/lib/std/c/haiku.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//
const std = @import("../std.zig");
const builtin = std.builtin;
diff --git a/lib/std/c/hermit.zig b/lib/std/c/hermit.zig
index a159395ab3..ae13840e16 100644
--- a/lib/std/c/hermit.zig
+++ b/lib/std/c/hermit.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const pthread_mutex_t = extern struct {
inner: usize = ~@as(usize, 0),
};
diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig
index 694af28904..808b05bd6d 100644
--- a/lib/std/c/linux.zig
+++ b/lib/std/c/linux.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const maxInt = std.math.maxInt;
const abi = std.Target.current.abi;
@@ -186,8 +181,8 @@ const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
};
const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
-pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
-pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
+pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
+pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub const RTLD_LAZY = 1;
pub const RTLD_NOW = 2;
diff --git a/lib/std/c/minix.zig b/lib/std/c/minix.zig
index 3f03d31ed5..9c644a7986 100644
--- a/lib/std/c/minix.zig
+++ b/lib/std/c/minix.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
pub const pthread_mutex_t = extern struct {
size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig
index 32b7cc69e3..e45dc85d34 100644
--- a/lib/std/c/netbsd.zig
+++ b/lib/std/c/netbsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
@@ -95,5 +90,5 @@ pub const pthread_attr_t = extern struct {
pub const sem_t = ?*opaque {};
-pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) c_int;
-pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
+pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) E;
+pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig
index 15820fb0a9..e5ded7f3fb 100644
--- a/lib/std/c/openbsd.zig
+++ b/lib/std/c/openbsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig
index ed043018d0..7c70a01fc4 100644
--- a/lib/std/c/solaris.zig
+++ b/lib/std/c/solaris.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const pthread_mutex_t = extern struct {
__pthread_mutex_flag1: u16 = 0,
__pthread_mutex_flag2: u8 = 0,
diff --git a/lib/std/c/tokenizer.zig b/lib/std/c/tokenizer.zig
index f8709e12be..9ad5ab0179 100644
--- a/lib/std/c/tokenizer.zig
+++ b/lib/std/c/tokenizer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const mem = std.mem;
diff --git a/lib/std/c/wasi.zig b/lib/std/c/wasi.zig
index 0edc77de37..339bdcd127 100644
--- a/lib/std/c/wasi.zig
+++ b/lib/std/c/wasi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../os/bits.zig");
extern threadlocal var errno: c_int;
diff --git a/lib/std/c/windows.zig b/lib/std/c/windows.zig
index bed2e421ff..a10715f083 100644
--- a/lib/std/c/windows.zig
+++ b/lib/std/c/windows.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub extern "c" fn _errno() *c_int;
pub extern "c" fn _msize(memblock: ?*c_void) usize;
diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig
index 3f3fa9c754..7d8881a679 100644
--- a/lib/std/child_process.zig
+++ b/lib/std/child_process.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const cstr = std.cstr;
const unicode = std.unicode;
diff --git a/lib/std/coff.zig b/lib/std/coff.zig
index 8b00a24297..6caf214728 100644
--- a/lib/std/coff.zig
+++ b/lib/std/coff.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = std.builtin;
const std = @import("std.zig");
const io = std.io;
diff --git a/lib/std/compress.zig b/lib/std/compress.zig
index 972031c182..f4db3fecd5 100644
--- a/lib/std/compress.zig
+++ b/lib/std/compress.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
pub const deflate = @import("compress/deflate.zig");
diff --git a/lib/std/compress/deflate.zig b/lib/std/compress/deflate.zig
index d7209981ce..b443c2971f 100644
--- a/lib/std/compress/deflate.zig
+++ b/lib/std/compress/deflate.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// Decompressor for DEFLATE data streams (RFC1951)
//
diff --git a/lib/std/compress/gzip.zig b/lib/std/compress/gzip.zig
index 6f17601949..497b07d905 100644
--- a/lib/std/compress/gzip.zig
+++ b/lib/std/compress/gzip.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// Decompressor for GZIP data streams (RFC1952)
diff --git a/lib/std/compress/zlib.zig b/lib/std/compress/zlib.zig
index 909bae4090..f0f4ca2ff4 100644
--- a/lib/std/compress/zlib.zig
+++ b/lib/std/compress/zlib.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// Decompressor for ZLIB data streams (RFC1950)
diff --git a/lib/std/comptime_string_map.zig b/lib/std/comptime_string_map.zig
index 6e8f190bc4..09ba4e5a3c 100644
--- a/lib/std/comptime_string_map.zig
+++ b/lib/std/comptime_string_map.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const mem = std.mem;
diff --git a/lib/std/crypto.zig b/lib/std/crypto.zig
index 42ded1f2ea..e00e331b46 100644
--- a/lib/std/crypto.zig
+++ b/lib/std/crypto.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
/// Authenticated Encryption with Associated Data
pub const aead = struct {
pub const aegis = struct {
@@ -110,7 +104,16 @@ pub const onetimeauth = struct {
///
/// Password hashing functions must be used whenever sensitive data has to be directly derived from a password.
pub const pwhash = struct {
+ pub const Encoding = enum {
+ phc,
+ crypt,
+ };
+ pub const KdfError = errors.Error || std.mem.Allocator.Error;
+ pub const HasherError = KdfError || @import("crypto/phc_encoding.zig").Error;
+ pub const Error = HasherError || error{AllocatorRequired};
+
pub const bcrypt = @import("crypto/bcrypt.zig");
+ pub const scrypt = @import("crypto/scrypt.zig");
pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2;
};
diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig
index 9b8cecb917..44a19362e4 100644
--- a/lib/std/crypto/25519/curve25519.zig
+++ b/lib/std/crypto/25519/curve25519.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const crypto = std.crypto;
diff --git a/lib/std/crypto/25519/ed25519.zig b/lib/std/crypto/25519/ed25519.zig
index 4940f0dee6..a6ac956183 100644
--- a/lib/std/crypto/25519/ed25519.zig
+++ b/lib/std/crypto/25519/ed25519.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const crypto = std.crypto;
const debug = std.debug;
diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig
index 15af616d60..7e58692e63 100644
--- a/lib/std/crypto/25519/edwards25519.zig
+++ b/lib/std/crypto/25519/edwards25519.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const crypto = std.crypto;
const debug = std.debug;
diff --git a/lib/std/crypto/25519/field.zig b/lib/std/crypto/25519/field.zig
index 1d67f0a902..277fb98d5c 100644
--- a/lib/std/crypto/25519/field.zig
+++ b/lib/std/crypto/25519/field.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const crypto = std.crypto;
const readIntLittle = std.mem.readIntLittle;
diff --git a/lib/std/crypto/25519/ristretto255.zig b/lib/std/crypto/25519/ristretto255.zig
index dea6193fca..e33bdb496d 100644
--- a/lib/std/crypto/25519/ristretto255.zig
+++ b/lib/std/crypto/25519/ristretto255.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const fmt = std.fmt;
diff --git a/lib/std/crypto/25519/scalar.zig b/lib/std/crypto/25519/scalar.zig
index bea054234e..9582a888f0 100644
--- a/lib/std/crypto/25519/scalar.zig
+++ b/lib/std/crypto/25519/scalar.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const mem = std.mem;
diff --git a/lib/std/crypto/25519/x25519.zig b/lib/std/crypto/25519/x25519.zig
index 5109fd7c2a..d935513ab6 100644
--- a/lib/std/crypto/25519/x25519.zig
+++ b/lib/std/crypto/25519/x25519.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const crypto = std.crypto;
const mem = std.mem;
diff --git a/lib/std/crypto/aegis.zig b/lib/std/crypto/aegis.zig
index 194b6de8f5..68062c537e 100644
--- a/lib/std/crypto/aegis.zig
+++ b/lib/std/crypto/aegis.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const mem = std.mem;
const assert = std.debug.assert;
diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig
index 7d6e0d1e84..18bae3978e 100644
--- a/lib/std/crypto/aes.zig
+++ b/lib/std/crypto/aes.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../std.zig");
const testing = std.testing;
const builtin = std.builtin;
diff --git a/lib/std/crypto/aes/aesni.zig b/lib/std/crypto/aes/aesni.zig
index 7fbbaac7e8..94c7f5efc6 100644
--- a/lib/std/crypto/aes/aesni.zig
+++ b/lib/std/crypto/aes/aesni.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const mem = std.mem;
const debug = std.debug;
diff --git a/lib/std/crypto/aes/armcrypto.zig b/lib/std/crypto/aes/armcrypto.zig
index 4d16b2f680..cee5b9bccb 100644
--- a/lib/std/crypto/aes/armcrypto.zig
+++ b/lib/std/crypto/aes/armcrypto.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const mem = std.mem;
const debug = std.debug;
diff --git a/lib/std/crypto/aes/soft.zig b/lib/std/crypto/aes/soft.zig
index 0d8a566793..bc9a994b95 100644
--- a/lib/std/crypto/aes/soft.zig
+++ b/lib/std/crypto/aes/soft.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Based on Go stdlib implementation
const std = @import("../../std.zig");
diff --git a/lib/std/crypto/aes_gcm.zig b/lib/std/crypto/aes_gcm.zig
index 492a1a5223..2d1cefaa31 100644
--- a/lib/std/crypto/aes_gcm.zig
+++ b/lib/std/crypto/aes_gcm.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const assert = std.debug.assert;
const builtin = std.builtin;
diff --git a/lib/std/crypto/aes_ocb.zig b/lib/std/crypto/aes_ocb.zig
index 6aaa7fc8cb..69c34afcda 100644
--- a/lib/std/crypto/aes_ocb.zig
+++ b/lib/std/crypto/aes_ocb.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const crypto = std.crypto;
const aes = crypto.core.aes;
diff --git a/lib/std/crypto/bcrypt.zig b/lib/std/crypto/bcrypt.zig
index 07c2142a97..d8c4d67453 100644
--- a/lib/std/crypto/bcrypt.zig
+++ b/lib/std/crypto/bcrypt.zig
@@ -1,26 +1,27 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const crypto = std.crypto;
+const debug = std.debug;
const fmt = std.fmt;
const math = std.math;
const mem = std.mem;
-const debug = std.debug;
+const pwhash = crypto.pwhash;
const testing = std.testing;
const utils = crypto.utils;
-const EncodingError = crypto.errors.EncodingError;
-const PasswordVerificationError = crypto.errors.PasswordVerificationError;
+
+const phc_format = @import("phc_encoding.zig");
+
+const KdfError = pwhash.KdfError;
+const HasherError = pwhash.HasherError;
+const EncodingError = phc_format.Error;
+const Error = pwhash.Error;
const salt_length: usize = 16;
const salt_str_length: usize = 22;
const ct_str_length: usize = 31;
const ct_length: usize = 24;
+const dk_length: usize = ct_length - 1;
-/// Length (in bytes) of a password hash
+/// Length (in bytes) of a password hash in crypt encoding
pub const hash_length: usize = 60;
const State = struct {
@@ -139,71 +140,15 @@ const State = struct {
}
};
-// bcrypt has its own variant of base64, with its own alphabet and no padding
-const Codec = struct {
- const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-
- fn encode(b64: []u8, bin: []const u8) void {
- var i: usize = 0;
- var j: usize = 0;
- while (i < bin.len) {
- var c1 = bin[i];
- i += 1;
- b64[j] = alphabet[c1 >> 2];
- j += 1;
- c1 = (c1 & 3) << 4;
- if (i >= bin.len) {
- b64[j] = alphabet[c1];
- j += 1;
- break;
- }
- var c2 = bin[i];
- i += 1;
- c1 |= (c2 >> 4) & 0x0f;
- b64[j] = alphabet[c1];
- j += 1;
- c1 = (c2 & 0x0f) << 2;
- if (i >= bin.len) {
- b64[j] = alphabet[c1];
- j += 1;
- break;
- }
- c2 = bin[i];
- i += 1;
- c1 |= (c2 >> 6) & 3;
- b64[j] = alphabet[c1];
- b64[j + 1] = alphabet[c2 & 0x3f];
- j += 2;
- }
- debug.assert(j == b64.len);
- }
-
- fn decode(bin: []u8, b64: []const u8) EncodingError!void {
- var i: usize = 0;
- var j: usize = 0;
- while (j < bin.len) {
- const c1 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i]) orelse return error.InvalidEncoding);
- const c2 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i + 1]) orelse return error.InvalidEncoding);
- bin[j] = (c1 << 2) | ((c2 & 0x30) >> 4);
- j += 1;
- if (j >= bin.len) {
- break;
- }
- const c3 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i + 2]) orelse return error.InvalidEncoding);
- bin[j] = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2);
- j += 1;
- if (j >= bin.len) {
- break;
- }
- const c4 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i + 3]) orelse return error.InvalidEncoding);
- bin[j] = ((c3 & 0x03) << 6) | c4;
- j += 1;
- i += 4;
- }
- }
+pub const Params = struct {
+ rounds_log: u6,
};
-fn strHashInternal(password: []const u8, rounds_log: u6, salt: [salt_length]u8) ![hash_length]u8 {
+pub fn bcrypt(
+ password: []const u8,
+ salt: [salt_length]u8,
+ params: Params,
+) [dk_length]u8 {
var state = State{};
var password_buf: [73]u8 = undefined;
const trimmed_len = math.min(password.len, password_buf.len - 1);
@@ -212,7 +157,7 @@ fn strHashInternal(password: []const u8, rounds_log: u6, salt: [salt_length]u8)
var passwordZ = password_buf[0 .. trimmed_len + 1];
state.expand(salt[0..], passwordZ);
- const rounds: u64 = @as(u64, 1) << rounds_log;
+ const rounds: u64 = @as(u64, 1) << params.rounds_log;
var k: u64 = 0;
while (k < rounds) : (k += 1) {
state.expand0(passwordZ);
@@ -230,19 +175,204 @@ fn strHashInternal(password: []const u8, rounds_log: u6, salt: [salt_length]u8)
for (cdata) |c, i| {
mem.writeIntBig(u32, ct[i * 4 ..][0..4], c);
}
-
- var salt_str: [salt_str_length]u8 = undefined;
- Codec.encode(salt_str[0..], salt[0..]);
-
- var ct_str: [ct_str_length]u8 = undefined;
- Codec.encode(ct_str[0..], ct[0 .. ct.len - 1]);
-
- var s_buf: [hash_length]u8 = undefined;
- const s = fmt.bufPrint(s_buf[0..], "$2b${d}{d}${s}{s}", .{ rounds_log / 10, rounds_log % 10, salt_str, ct_str }) catch unreachable;
- debug.assert(s.len == s_buf.len);
- return s_buf;
+ return ct[0..dk_length].*;
}
+const crypt_format = struct {
+ /// String prefix for bcrypt
+ pub const prefix = "$2";
+
+ // bcrypt has its own variant of base64, with its own alphabet and no padding
+ const Codec = struct {
+ const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+ fn encode(b64: []u8, bin: []const u8) void {
+ var i: usize = 0;
+ var j: usize = 0;
+ while (i < bin.len) {
+ var c1 = bin[i];
+ i += 1;
+ b64[j] = alphabet[c1 >> 2];
+ j += 1;
+ c1 = (c1 & 3) << 4;
+ if (i >= bin.len) {
+ b64[j] = alphabet[c1];
+ j += 1;
+ break;
+ }
+ var c2 = bin[i];
+ i += 1;
+ c1 |= (c2 >> 4) & 0x0f;
+ b64[j] = alphabet[c1];
+ j += 1;
+ c1 = (c2 & 0x0f) << 2;
+ if (i >= bin.len) {
+ b64[j] = alphabet[c1];
+ j += 1;
+ break;
+ }
+ c2 = bin[i];
+ i += 1;
+ c1 |= (c2 >> 6) & 3;
+ b64[j] = alphabet[c1];
+ b64[j + 1] = alphabet[c2 & 0x3f];
+ j += 2;
+ }
+ debug.assert(j == b64.len);
+ }
+
+ fn decode(bin: []u8, b64: []const u8) EncodingError!void {
+ var i: usize = 0;
+ var j: usize = 0;
+ while (j < bin.len) {
+ const c1 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i]) orelse
+ return EncodingError.InvalidEncoding);
+ const c2 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i + 1]) orelse
+ return EncodingError.InvalidEncoding);
+ bin[j] = (c1 << 2) | ((c2 & 0x30) >> 4);
+ j += 1;
+ if (j >= bin.len) {
+ break;
+ }
+ const c3 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i + 2]) orelse
+ return EncodingError.InvalidEncoding);
+ bin[j] = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2);
+ j += 1;
+ if (j >= bin.len) {
+ break;
+ }
+ const c4 = @intCast(u8, mem.indexOfScalar(u8, alphabet, b64[i + 3]) orelse
+ return EncodingError.InvalidEncoding);
+ bin[j] = ((c3 & 0x03) << 6) | c4;
+ j += 1;
+ i += 4;
+ }
+ }
+ };
+
+ fn strHashInternal(
+ password: []const u8,
+ salt: [salt_length]u8,
+ params: Params,
+ ) [hash_length]u8 {
+ var dk = bcrypt(password, salt, params);
+
+ var salt_str: [salt_str_length]u8 = undefined;
+ Codec.encode(salt_str[0..], salt[0..]);
+
+ var ct_str: [ct_str_length]u8 = undefined;
+ Codec.encode(ct_str[0..], dk[0..]);
+
+ var s_buf: [hash_length]u8 = undefined;
+ const s = fmt.bufPrint(
+ s_buf[0..],
+ "{s}b${d}{d}${s}{s}",
+ .{ prefix, params.rounds_log / 10, params.rounds_log % 10, salt_str, ct_str },
+ ) catch unreachable;
+ debug.assert(s.len == s_buf.len);
+ return s_buf;
+ }
+};
+
+/// Hash and verify passwords using the PHC format.
+const PhcFormatHasher = struct {
+ const alg_id = "bcrypt";
+ const BinValue = phc_format.BinValue;
+
+ const HashResult = struct {
+ alg_id: []const u8,
+ r: u6,
+ salt: BinValue(salt_length),
+ hash: BinValue(dk_length),
+ };
+
+ /// Return a non-deterministic hash of the password encoded as a PHC-format string
+ pub fn create(
+ password: []const u8,
+ params: Params,
+ buf: []u8,
+ ) HasherError![]const u8 {
+ var salt: [salt_length]u8 = undefined;
+ crypto.random.bytes(&salt);
+
+ const hash = bcrypt(password, salt, params);
+
+ return phc_format.serialize(HashResult{
+ .alg_id = alg_id,
+ .r = params.rounds_log,
+ .salt = try BinValue(salt_length).fromSlice(&salt),
+ .hash = try BinValue(dk_length).fromSlice(&hash),
+ }, buf);
+ }
+
+ /// Verify a password against a PHC-format encoded string
+ pub fn verify(
+ str: []const u8,
+ password: []const u8,
+ ) HasherError!void {
+ const hash_result = try phc_format.deserialize(HashResult, str);
+
+ if (!mem.eql(u8, hash_result.alg_id, alg_id)) return HasherError.PasswordVerificationFailed;
+ if (hash_result.salt.len != salt_length or hash_result.hash.len != dk_length)
+ return HasherError.InvalidEncoding;
+
+ const hash = bcrypt(password, hash_result.salt.buf, .{ .rounds_log = hash_result.r });
+ const expected_hash = hash_result.hash.constSlice();
+
+ if (!mem.eql(u8, &hash, expected_hash)) return HasherError.PasswordVerificationFailed;
+ }
+};
+
+/// Hash and verify passwords using the modular crypt format.
+const CryptFormatHasher = struct {
+ /// Length of a string returned by the create() function
+ pub const pwhash_str_length: usize = hash_length;
+
+ /// Return a non-deterministic hash of the password encoded into the modular crypt format
+ pub fn create(
+ password: []const u8,
+ params: Params,
+ buf: []u8,
+ ) HasherError![]const u8 {
+ if (buf.len < pwhash_str_length) return HasherError.NoSpaceLeft;
+
+ var salt: [salt_length]u8 = undefined;
+ crypto.random.bytes(&salt);
+
+ const hash = crypt_format.strHashInternal(password, salt, params);
+ mem.copy(u8, buf, &hash);
+
+ return buf[0..pwhash_str_length];
+ }
+
+ /// Verify a password against a string in modular crypt format
+ pub fn verify(
+ str: []const u8,
+ password: []const u8,
+ ) HasherError!void {
+ if (str.len != pwhash_str_length or str[3] != '$' or str[6] != '$')
+ return HasherError.InvalidEncoding;
+
+ const rounds_log_str = str[4..][0..2];
+ const rounds_log = fmt.parseInt(u6, rounds_log_str[0..], 10) catch
+ return HasherError.InvalidEncoding;
+
+ const salt_str = str[7..][0..salt_str_length];
+ var salt: [salt_length]u8 = undefined;
+ try crypt_format.Codec.decode(salt[0..], salt_str[0..]);
+
+ const wanted_s = crypt_format.strHashInternal(password, salt, .{ .rounds_log = rounds_log });
+ if (!mem.eql(u8, wanted_s[0..], str[0..])) return HasherError.PasswordVerificationFailed;
+ }
+};
+
+/// Options for hashing a password.
+pub const HashOptions = struct {
+ allocator: ?*mem.Allocator = null,
+ params: Params,
+ encoding: pwhash.Encoding,
+};
+
/// Compute a hash of a password using 2^rounds_log rounds of the bcrypt key stretching function.
/// bcrypt is a computationally expensive and cache-hard function, explicitly designed to slow down exhaustive searches.
///
@@ -251,24 +381,32 @@ fn strHashInternal(password: []const u8, rounds_log: u6, salt: [salt_length]u8)
/// IMPORTANT: by design, bcrypt silently truncates passwords to 72 bytes.
/// If this is an issue for your application, hash the password first using a function such as SHA-512,
/// and then use the resulting hash as the password parameter for bcrypt.
-pub fn strHash(password: []const u8, rounds_log: u6) ![hash_length]u8 {
- var salt: [salt_length]u8 = undefined;
- crypto.random.bytes(&salt);
- return strHashInternal(password, rounds_log, salt);
+pub fn strHash(
+ password: []const u8,
+ options: HashOptions,
+ out: []u8,
+) Error![]const u8 {
+ switch (options.encoding) {
+ .phc => return PhcFormatHasher.create(password, options.params, out),
+ .crypt => return CryptFormatHasher.create(password, options.params, out),
+ }
}
+/// Options for hash verification.
+pub const VerifyOptions = struct {
+ allocator: ?*mem.Allocator = null,
+};
+
/// Verify that a previously computed hash is valid for a given password.
-pub fn strVerify(h: [hash_length]u8, password: []const u8) (EncodingError || PasswordVerificationError)!void {
- if (!mem.eql(u8, "$2", h[0..2])) return error.InvalidEncoding;
- if (h[3] != '$' or h[6] != '$') return error.InvalidEncoding;
- const rounds_log_str = h[4..][0..2];
- const salt_str = h[7..][0..salt_str_length];
- var salt: [salt_length]u8 = undefined;
- try Codec.decode(salt[0..], salt_str[0..]);
- const rounds_log = fmt.parseInt(u6, rounds_log_str[0..], 10) catch return error.InvalidEncoding;
- const wanted_s = try strHashInternal(password, rounds_log, salt);
- if (!mem.eql(u8, wanted_s[0..], h[0..])) {
- return error.PasswordVerificationFailed;
+pub fn strVerify(
+ str: []const u8,
+ password: []const u8,
+ _: VerifyOptions,
+) Error!void {
+ if (mem.startsWith(u8, str, crypt_format.prefix)) {
+ return CryptFormatHasher.verify(str, password);
+ } else {
+ return PhcFormatHasher.verify(str, password);
}
}
@@ -276,20 +414,71 @@ test "bcrypt codec" {
var salt: [salt_length]u8 = undefined;
crypto.random.bytes(&salt);
var salt_str: [salt_str_length]u8 = undefined;
- Codec.encode(salt_str[0..], salt[0..]);
+ crypt_format.Codec.encode(salt_str[0..], salt[0..]);
var salt2: [salt_length]u8 = undefined;
- try Codec.decode(salt2[0..], salt_str[0..]);
+ try crypt_format.Codec.decode(salt2[0..], salt_str[0..]);
try testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
}
-test "bcrypt" {
- const s = try strHash("password", 5);
- try strVerify(s, "password");
- try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
+test "bcrypt crypt format" {
+ const hash_options = HashOptions{
+ .params = .{ .rounds_log = 5 },
+ .encoding = .crypt,
+ };
+ const verify_options = VerifyOptions{};
- const long_s = try strHash("password" ** 100, 5);
- try strVerify(long_s, "password" ** 100);
- try strVerify(long_s, "password" ** 101);
+ var buf: [hash_length]u8 = undefined;
+ const s = try strHash("password", hash_options, &buf);
- try strVerify("$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe".*, "The devil himself");
+ try testing.expect(mem.startsWith(u8, s, crypt_format.prefix));
+ try strVerify(s, "password", verify_options);
+ try testing.expectError(
+ error.PasswordVerificationFailed,
+ strVerify(s, "invalid password", verify_options),
+ );
+
+ var long_buf: [hash_length]u8 = undefined;
+ const long_s = try strHash("password" ** 100, hash_options, &long_buf);
+
+ try testing.expect(mem.startsWith(u8, long_s, crypt_format.prefix));
+ try strVerify(long_s, "password" ** 100, verify_options);
+ try strVerify(long_s, "password" ** 101, verify_options);
+
+ try strVerify(
+ "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe",
+ "The devil himself",
+ verify_options,
+ );
+}
+
+test "bcrypt phc format" {
+ const hash_options = HashOptions{
+ .params = .{ .rounds_log = 5 },
+ .encoding = .phc,
+ };
+ const verify_options = VerifyOptions{};
+ const prefix = "$bcrypt$";
+
+ var buf: [hash_length * 2]u8 = undefined;
+ const s = try strHash("password", hash_options, &buf);
+
+ try testing.expect(mem.startsWith(u8, s, prefix));
+ try strVerify(s, "password", verify_options);
+ try testing.expectError(
+ error.PasswordVerificationFailed,
+ strVerify(s, "invalid password", verify_options),
+ );
+
+ var long_buf: [hash_length * 2]u8 = undefined;
+ const long_s = try strHash("password" ** 100, hash_options, &long_buf);
+
+ try testing.expect(mem.startsWith(u8, long_s, prefix));
+ try strVerify(long_s, "password" ** 100, verify_options);
+ try strVerify(long_s, "password" ** 101, verify_options);
+
+ try strVerify(
+ "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc",
+ "The devil himself",
+ verify_options,
+ );
}
diff --git a/lib/std/crypto/benchmark.zig b/lib/std/crypto/benchmark.zig
index e8e50b95ea..7d55b95a3f 100644
--- a/lib/std/crypto/benchmark.zig
+++ b/lib/std/crypto/benchmark.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// zig run benchmark.zig --release-fast --zig-lib-dir ..
const std = @import("../std.zig");
@@ -300,6 +295,43 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 {
return throughput;
}
+const CryptoPwhash = struct {
+ hashFn: anytype,
+ params: anytype,
+ name: []const u8,
+};
+const bcrypt_params = bcrypt.Params{ .rounds_log = 5 };
+const pwhashes = [_]CryptoPwhash{
+ CryptoPwhash{ .hashFn = bcrypt.strHash, .params = bcrypt_params, .name = "bcrypt" },
+ CryptoPwhash{ .hashFn = scrypt.strHash, .params = scrypt.Params.interactive, .name = "scrypt" },
+};
+
+fn benchmarkPwhash(
+ comptime hashFn: anytype,
+ comptime params: anytype,
+ comptime count: comptime_int,
+) !u64 {
+ const password = "testpass" ** 2;
+ const opts = .{ .allocator = std.testing.allocator, .params = params, .encoding = .phc };
+ var buf: [256]u8 = undefined;
+
+ var timer = try Timer.start();
+ const start = timer.lap();
+ {
+ var i: usize = 0;
+ while (i < count) : (i += 1) {
+ _ = try hashFn(password, opts, &buf);
+ mem.doNotOptimizeAway(&buf);
+ }
+ }
+ const end = timer.read();
+
+ const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s;
+ const throughput = @floatToInt(u64, count / elapsed_s);
+
+ return throughput;
+}
+
fn usage() void {
std.debug.warn(
\\throughput_test [options]
@@ -418,4 +450,11 @@ pub fn main() !void {
try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
}
}
+
+ inline for (pwhashes) |H| {
+ if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
+ const throughput = try benchmarkPwhash(H.hashFn, H.params, mode(64));
+ try stdout.print("{s:>17}: {:10} ops/s\n", .{ H.name, throughput });
+ }
+ }
}
diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig
index e0b9eff5b9..e2107dda56 100644
--- a/lib/std/crypto/blake2.zig
+++ b/lib/std/crypto/blake2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
const math = std.math;
diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig
index 75aba06da0..6a2950645a 100644
--- a/lib/std/crypto/blake3.zig
+++ b/lib/std/crypto/blake3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Translated from BLAKE3 reference implementation.
// Source: https://github.com/BLAKE3-team/BLAKE3
diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig
index 592116ddd4..11496034a0 100644
--- a/lib/std/crypto/chacha20.zig
+++ b/lib/std/crypto/chacha20.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Based on public domain Supercop by Daniel J. Bernstein
const std = @import("../std.zig");
diff --git a/lib/std/crypto/ghash.zig b/lib/std/crypto/ghash.zig
index b9a7e48adc..704ed367f0 100644
--- a/lib/std/crypto/ghash.zig
+++ b/lib/std/crypto/ghash.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// Adapted from BearSSL's ctmul64 implementation originally written by Thomas Pornin
diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig
index 7aa67212e4..c234213704 100644
--- a/lib/std/crypto/gimli.zig
+++ b/lib/std/crypto/gimli.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Gimli is a 384-bit permutation designed to achieve high security with high
// performance across a broad range of platforms, including 64-bit Intel/AMD
// server CPUs, 64-bit and 32-bit ARM smartphone CPUs, 32-bit ARM
diff --git a/lib/std/crypto/hkdf.zig b/lib/std/crypto/hkdf.zig
index 81c541231d..8de3052a0b 100644
--- a/lib/std/crypto/hkdf.zig
+++ b/lib/std/crypto/hkdf.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../std.zig");
const assert = std.debug.assert;
const hmac = std.crypto.auth.hmac;
diff --git a/lib/std/crypto/hmac.zig b/lib/std/crypto/hmac.zig
index 12c4a53e0f..5ff37f8112 100644
--- a/lib/std/crypto/hmac.zig
+++ b/lib/std/crypto/hmac.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const crypto = std.crypto;
const debug = std.debug;
diff --git a/lib/std/crypto/md5.zig b/lib/std/crypto/md5.zig
index ef9907d18b..9306c222ed 100644
--- a/lib/std/crypto/md5.zig
+++ b/lib/std/crypto/md5.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
const math = std.math;
diff --git a/lib/std/crypto/modes.zig b/lib/std/crypto/modes.zig
index 8848334dae..d2df2ce15a 100644
--- a/lib/std/crypto/modes.zig
+++ b/lib/std/crypto/modes.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Based on Go stdlib implementation
const std = @import("../std.zig");
diff --git a/lib/std/crypto/pbkdf2.zig b/lib/std/crypto/pbkdf2.zig
index b3e2a32bf3..b8f03bceb7 100644
--- a/lib/std/crypto/pbkdf2.zig
+++ b/lib/std/crypto/pbkdf2.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const mem = std.mem;
const maxInt = std.math.maxInt;
diff --git a/lib/std/crypto/pcurves/p256.zig b/lib/std/crypto/pcurves/p256.zig
index dcc97bcbe5..02410a8859 100644
--- a/lib/std/crypto/pcurves/p256.zig
+++ b/lib/std/crypto/pcurves/p256.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const builtin = std.builtin;
const crypto = std.crypto;
diff --git a/lib/std/crypto/pcurves/p256/field.zig b/lib/std/crypto/pcurves/p256/field.zig
index 15de1fe43e..c36db58e87 100644
--- a/lib/std/crypto/pcurves/p256/field.zig
+++ b/lib/std/crypto/pcurves/p256/field.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const common = @import("../common.zig");
diff --git a/lib/std/crypto/pcurves/p256/scalar.zig b/lib/std/crypto/pcurves/p256/scalar.zig
index afdc3fb502..265300a7a6 100644
--- a/lib/std/crypto/pcurves/p256/scalar.zig
+++ b/lib/std/crypto/pcurves/p256/scalar.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const builtin = std.builtin;
const common = @import("../common.zig");
diff --git a/lib/std/crypto/pcurves/tests.zig b/lib/std/crypto/pcurves/tests.zig
index 6bd0ac43f2..0321d0574c 100644
--- a/lib/std/crypto/pcurves/tests.zig
+++ b/lib/std/crypto/pcurves/tests.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const fmt = std.fmt;
const testing = std.testing;
diff --git a/lib/std/crypto/phc_encoding.zig b/lib/std/crypto/phc_encoding.zig
new file mode 100644
index 0000000000..56fa76b5c0
--- /dev/null
+++ b/lib/std/crypto/phc_encoding.zig
@@ -0,0 +1,371 @@
+// https://github.com/P-H-C/phc-string-format
+
+const std = @import("std");
+const fmt = std.fmt;
+const io = std.io;
+const mem = std.mem;
+const meta = std.meta;
+
+const fields_delimiter = "$";
+const version_param_name = "v";
+const params_delimiter = ",";
+const kv_delimiter = "=";
+
+pub const Error = std.crypto.errors.EncodingError || error{NoSpaceLeft};
+
+const B64Decoder = std.base64.standard_no_pad.Decoder;
+const B64Encoder = std.base64.standard_no_pad.Encoder;
+
+/// A wrapped binary value whose maximum size is `max_len`.
+///
+/// This type must be used whenever a binary value is encoded in a PHC-formatted string.
+/// This includes `salt`, `hash`, and any other binary parameters such as keys.
+///
+/// Once initialized, the actual value can be read with the `constSlice()` function.
+pub fn BinValue(comptime max_len: usize) type {
+ return struct {
+ const Self = @This();
+ const capacity = max_len;
+ const max_encoded_length = B64Encoder.calcSize(max_len);
+
+ buf: [max_len]u8 = undefined,
+ len: usize = 0,
+
+ /// Wrap an existing byte slice
+ pub fn fromSlice(slice: []const u8) Error!Self {
+ if (slice.len > capacity) return Error.NoSpaceLeft;
+ var bin_value: Self = undefined;
+ mem.copy(u8, &bin_value.buf, slice);
+ bin_value.len = slice.len;
+ return bin_value;
+ }
+
+ /// Return the slice containing the actual value.
+ pub fn constSlice(self: Self) []const u8 {
+ return self.buf[0..self.len];
+ }
+
+ fn fromB64(self: *Self, str: []const u8) !void {
+ const len = B64Decoder.calcSizeForSlice(str) catch return Error.InvalidEncoding;
+ if (len > self.buf.len) return Error.NoSpaceLeft;
+ B64Decoder.decode(&self.buf, str) catch return Error.InvalidEncoding;
+ self.len = len;
+ }
+
+ fn toB64(self: Self, buf: []u8) ![]const u8 {
+ const value = self.constSlice();
+ const len = B64Encoder.calcSize(value.len);
+ if (len > buf.len) return Error.NoSpaceLeft;
+ return B64Encoder.encode(buf, value);
+ }
+ };
+}
+
+/// Deserialize a PHC-formatted string into a structure `HashResult`.
+///
+/// Required field in the `HashResult` structure:
+/// - `alg_id`: algorithm identifier
+/// Optional, special fields:
+/// - `alg_version`: algorithm version (unsigned integer)
+/// - `salt`: salt
+/// - `hash`: output of the hash function
+///
+/// Other fields will also be deserialized from the function parameters section.
+pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult {
+ var out = mem.zeroes(HashResult);
+ var it = mem.split(u8, str, fields_delimiter);
+ var set_fields: usize = 0;
+
+ while (true) {
+ // Read the algorithm identifier
+ if ((it.next() orelse return Error.InvalidEncoding).len != 0) return Error.InvalidEncoding;
+ out.alg_id = it.next() orelse return Error.InvalidEncoding;
+ set_fields += 1;
+
+ // Read the optional version number
+ var field = it.next() orelse break;
+ if (kvSplit(field)) |opt_version| {
+ if (mem.eql(u8, opt_version.key, version_param_name)) {
+ if (@hasField(HashResult, "alg_version")) {
+ const value_type_info = switch (@typeInfo(@TypeOf(out.alg_version))) {
+ .Optional => |opt| comptime @typeInfo(opt.child),
+ else => |t| t,
+ };
+ out.alg_version = fmt.parseUnsigned(
+ @Type(value_type_info),
+ opt_version.value,
+ 10,
+ ) catch return Error.InvalidEncoding;
+ set_fields += 1;
+ }
+ field = it.next() orelse break;
+ }
+ } else |_| {}
+
+ // Read optional parameters
+ var has_params = false;
+ var it_params = mem.split(u8, field, params_delimiter);
+ while (it_params.next()) |params| {
+ const param = kvSplit(params) catch break;
+ var found = false;
+ inline for (comptime meta.fields(HashResult)) |p| {
+ if (mem.eql(u8, p.name, param.key)) {
+ switch (@typeInfo(p.field_type)) {
+ .Int => @field(out, p.name) = fmt.parseUnsigned(
+ p.field_type,
+ param.value,
+ 10,
+ ) catch return Error.InvalidEncoding,
+ .Pointer => |ptr| {
+ if (!ptr.is_const) @compileError("Value slice must be constant");
+ @field(out, p.name) = param.value;
+ },
+ .Struct => try @field(out, p.name).fromB64(param.value),
+ else => std.debug.panic(
+ "Value for [{s}] must be an integer, a constant slice or a BinValue",
+ .{p.name},
+ ),
+ }
+ set_fields += 1;
+ found = true;
+ break;
+ }
+ }
+ if (!found) return Error.InvalidEncoding; // An unexpected parameter was found in the string
+ has_params = true;
+ }
+
+ // No separator between an empty parameters set and the salt
+ if (has_params) field = it.next() orelse break;
+
+ // Read an optional salt
+ if (@hasField(HashResult, "salt")) {
+ try out.salt.fromB64(field);
+ set_fields += 1;
+ } else {
+ return Error.InvalidEncoding;
+ }
+
+ // Read an optional hash
+ field = it.next() orelse break;
+ if (@hasField(HashResult, "hash")) {
+ try out.hash.fromB64(field);
+ set_fields += 1;
+ } else {
+ return Error.InvalidEncoding;
+ }
+ break;
+ }
+
+ // Check that all the required fields have been set, excluding optional values and parameters
+ // with default values
+ var expected_fields: usize = 0;
+ inline for (comptime meta.fields(HashResult)) |p| {
+ if (@typeInfo(p.field_type) != .Optional and p.default_value == null) {
+ expected_fields += 1;
+ }
+ }
+ if (set_fields < expected_fields) return Error.InvalidEncoding;
+
+ return out;
+}
+
+/// Serialize parameters into a PHC string.
+///
+/// Required field for `params`:
+/// - `alg_id`: algorithm identifier
+/// Optional, special fields:
+/// - `alg_version`: algorithm version (unsigned integer)
+/// - `salt`: salt
+/// - `hash`: output of the hash function
+///
+/// `params` can also include any additional parameters.
+pub fn serialize(params: anytype, str: []u8) Error![]const u8 {
+ var buf = io.fixedBufferStream(str);
+ try serializeTo(params, buf.writer());
+ return buf.getWritten();
+}
+
+/// Compute the number of bytes required to serialize `params`
+pub fn calcSize(params: anytype) usize {
+ var buf = io.countingWriter(io.null_writer);
+ serializeTo(params, buf.writer()) catch unreachable;
+ return @intCast(usize, buf.bytes_written);
+}
+
+fn serializeTo(params: anytype, out: anytype) !void {
+ const HashResult = @TypeOf(params);
+ try out.writeAll(fields_delimiter);
+ try out.writeAll(params.alg_id);
+
+ if (@hasField(HashResult, "alg_version")) {
+ if (@typeInfo(@TypeOf(params.alg_version)) == .Optional) {
+ if (params.alg_version) |alg_version| {
+ try out.print(
+ "{s}{s}{s}{}",
+ .{ fields_delimiter, version_param_name, kv_delimiter, alg_version },
+ );
+ }
+ } else {
+ try out.print(
+ "{s}{s}{s}{}",
+ .{ fields_delimiter, version_param_name, kv_delimiter, params.alg_version },
+ );
+ }
+ }
+
+ var has_params = false;
+ inline for (comptime meta.fields(HashResult)) |p| {
+ if (!(mem.eql(u8, p.name, "alg_id") or
+ mem.eql(u8, p.name, "alg_version") or
+ mem.eql(u8, p.name, "hash") or
+ mem.eql(u8, p.name, "salt")))
+ {
+ const value = @field(params, p.name);
+ try out.writeAll(if (has_params) params_delimiter else fields_delimiter);
+ if (@typeInfo(p.field_type) == .Struct) {
+ var buf: [@TypeOf(value).max_encoded_length]u8 = undefined;
+ try out.print("{s}{s}{s}", .{ p.name, kv_delimiter, try value.toB64(&buf) });
+ } else {
+ try out.print(
+ if (@typeInfo(@TypeOf(value)) == .Pointer) "{s}{s}{s}" else "{s}{s}{}",
+ .{ p.name, kv_delimiter, value },
+ );
+ }
+ has_params = true;
+ }
+ }
+
+ var has_salt = false;
+ if (@hasField(HashResult, "salt")) {
+ var buf: [@TypeOf(params.salt).max_encoded_length]u8 = undefined;
+ try out.print("{s}{s}", .{ fields_delimiter, try params.salt.toB64(&buf) });
+ has_salt = true;
+ }
+
+ if (@hasField(HashResult, "hash")) {
+ var buf: [@TypeOf(params.hash).max_encoded_length]u8 = undefined;
+ if (!has_salt) try out.writeAll(fields_delimiter);
+ try out.print("{s}{s}", .{ fields_delimiter, try params.hash.toB64(&buf) });
+ }
+}
+
+// Split a `key=value` string into `key` and `value`
+fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } {
+ var it = mem.split(u8, str, kv_delimiter);
+ const key = it.next() orelse return Error.InvalidEncoding;
+ const value = it.next() orelse return Error.InvalidEncoding;
+ const ret = .{ .key = key, .value = value };
+ return ret;
+}
+
+test "phc format - encoding/decoding" {
+ const Input = struct {
+ str: []const u8,
+ HashResult: type,
+ };
+ const inputs = [_]Input{
+ .{
+ .str = "$argon2id$v=19$key=a2V5,m=4096,t=0,p=1$X1NhbHQAAAAAAAAAAAAAAA$bWh++MKN1OiFHKgIWTLvIi1iHicmHH7+Fv3K88ifFfI",
+ .HashResult = struct {
+ alg_id: []const u8,
+ alg_version: u16,
+ key: BinValue(16),
+ m: usize,
+ t: u64,
+ p: u32,
+ salt: BinValue(16),
+ hash: BinValue(32),
+ },
+ },
+ .{
+ .str = "$scrypt$v=1$ln=15,r=8,p=1$c2FsdHNhbHQ$dGVzdHBhc3M",
+ .HashResult = struct {
+ alg_id: []const u8,
+ alg_version: ?u30,
+ ln: u6,
+ r: u30,
+ p: u30,
+ salt: BinValue(16),
+ hash: BinValue(16),
+ },
+ },
+ .{
+ .str = "$scrypt",
+ .HashResult = struct { alg_id: []const u8 },
+ },
+ .{ .str = "$scrypt$v=1", .HashResult = struct { alg_id: []const u8, alg_version: u16 } },
+ .{
+ .str = "$scrypt$ln=15,r=8,p=1",
+ .HashResult = struct { alg_id: []const u8, alg_version: ?u30, ln: u6, r: u30, p: u30 },
+ },
+ .{
+ .str = "$scrypt$c2FsdHNhbHQ",
+ .HashResult = struct { alg_id: []const u8, salt: BinValue(16) },
+ },
+ .{
+ .str = "$scrypt$v=1$ln=15,r=8,p=1$c2FsdHNhbHQ",
+ .HashResult = struct {
+ alg_id: []const u8,
+ alg_version: u16,
+ ln: u6,
+ r: u30,
+ p: u30,
+ salt: BinValue(16),
+ },
+ },
+ .{
+ .str = "$scrypt$v=1$ln=15,r=8,p=1",
+ .HashResult = struct { alg_id: []const u8, alg_version: ?u30, ln: u6, r: u30, p: u30 },
+ },
+ .{
+ .str = "$scrypt$v=1$c2FsdHNhbHQ$dGVzdHBhc3M",
+ .HashResult = struct {
+ alg_id: []const u8,
+ alg_version: u16,
+ salt: BinValue(16),
+ hash: BinValue(16),
+ },
+ },
+ .{
+ .str = "$scrypt$v=1$c2FsdHNhbHQ",
+ .HashResult = struct { alg_id: []const u8, alg_version: u16, salt: BinValue(16) },
+ },
+ .{
+ .str = "$scrypt$c2FsdHNhbHQ$dGVzdHBhc3M",
+ .HashResult = struct { alg_id: []const u8, salt: BinValue(16), hash: BinValue(16) },
+ },
+ };
+ inline for (inputs) |input| {
+ const v = try deserialize(input.HashResult, input.str);
+ var buf: [input.str.len]u8 = undefined;
+ const s1 = try serialize(v, &buf);
+ try std.testing.expectEqualSlices(u8, input.str, s1);
+ }
+}
+
+test "phc format - empty input string" {
+ const s = "";
+ const v = deserialize(struct { alg_id: []const u8 }, s);
+ try std.testing.expectError(Error.InvalidEncoding, v);
+}
+
+test "phc format - hash without salt" {
+ const s = "$scrypt";
+ const v = deserialize(struct { alg_id: []const u8, hash: BinValue(16) }, s);
+ try std.testing.expectError(Error.InvalidEncoding, v);
+}
+
+test "phc format - calcSize" {
+ const s = "$scrypt$v=1$ln=15,r=8,p=1$c2FsdHNhbHQ$dGVzdHBhc3M";
+ const v = try deserialize(struct {
+ alg_id: []const u8,
+ alg_version: u16,
+ ln: u6,
+ r: u30,
+ p: u30,
+ salt: BinValue(8),
+ hash: BinValue(8),
+ }, s);
+ try std.testing.expectEqual(calcSize(v), s.len);
+}
diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig
index e93afac859..4f16f66cd0 100644
--- a/lib/std/crypto/poly1305.zig
+++ b/lib/std/crypto/poly1305.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const utils = std.crypto.utils;
const mem = std.mem;
diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig
index 55e4db13f0..45dad75a8f 100644
--- a/lib/std/crypto/salsa20.zig
+++ b/lib/std/crypto/salsa20.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const crypto = std.crypto;
const debug = std.debug;
diff --git a/lib/std/crypto/scrypt.zig b/lib/std/crypto/scrypt.zig
new file mode 100644
index 0000000000..5dcba41531
--- /dev/null
+++ b/lib/std/crypto/scrypt.zig
@@ -0,0 +1,657 @@
+// https://tools.ietf.org/html/rfc7914
+// https://github.com/golang/crypto/blob/master/scrypt/scrypt.go
+
+const std = @import("std");
+const crypto = std.crypto;
+const fmt = std.fmt;
+const io = std.io;
+const math = std.math;
+const mem = std.mem;
+const meta = std.meta;
+const pwhash = crypto.pwhash;
+
+const phc_format = @import("phc_encoding.zig");
+
+const HmacSha256 = crypto.auth.hmac.sha2.HmacSha256;
+const KdfError = pwhash.KdfError;
+const HasherError = pwhash.HasherError;
+const EncodingError = phc_format.Error;
+const Error = pwhash.Error;
+
+const max_size = math.maxInt(usize);
+const max_int = max_size >> 1;
+const default_salt_len = 32;
+const default_hash_len = 32;
+const max_salt_len = 64;
+const max_hash_len = 64;
+
+fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
+ mem.copy(u32, dst, src[0 .. n * 16]);
+}
+
+fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
+ for (src[0 .. n * 16]) |v, i| {
+ dst[i] ^= v;
+ }
+}
+
+const QuarterRound = struct { a: usize, b: usize, c: usize, d: u6 };
+
+fn Rp(a: usize, b: usize, c: usize, d: u6) QuarterRound {
+ return QuarterRound{ .a = a, .b = b, .c = c, .d = d };
+}
+
+fn salsa8core(b: *align(16) [16]u32) void {
+ const arx_steps = comptime [_]QuarterRound{
+ Rp(4, 0, 12, 7), Rp(8, 4, 0, 9), Rp(12, 8, 4, 13), Rp(0, 12, 8, 18),
+ Rp(9, 5, 1, 7), Rp(13, 9, 5, 9), Rp(1, 13, 9, 13), Rp(5, 1, 13, 18),
+ Rp(14, 10, 6, 7), Rp(2, 14, 10, 9), Rp(6, 2, 14, 13), Rp(10, 6, 2, 18),
+ Rp(3, 15, 11, 7), Rp(7, 3, 15, 9), Rp(11, 7, 3, 13), Rp(15, 11, 7, 18),
+ Rp(1, 0, 3, 7), Rp(2, 1, 0, 9), Rp(3, 2, 1, 13), Rp(0, 3, 2, 18),
+ Rp(6, 5, 4, 7), Rp(7, 6, 5, 9), Rp(4, 7, 6, 13), Rp(5, 4, 7, 18),
+ Rp(11, 10, 9, 7), Rp(8, 11, 10, 9), Rp(9, 8, 11, 13), Rp(10, 9, 8, 18),
+ Rp(12, 15, 14, 7), Rp(13, 12, 15, 9), Rp(14, 13, 12, 13), Rp(15, 14, 13, 18),
+ };
+ var x = b.*;
+ var j: usize = 0;
+ while (j < 8) : (j += 2) {
+ inline for (arx_steps) |r| {
+ x[r.a] ^= math.rotl(u32, x[r.b] +% x[r.c], r.d);
+ }
+ }
+ j = 0;
+ while (j < 16) : (j += 1) {
+ b[j] +%= x[j];
+ }
+}
+
+fn salsaXor(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16) u32) void {
+ blockXor(tmp, in, 1);
+ salsa8core(tmp);
+ blockCopy(out, tmp, 1);
+}
+
+fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16) u32, r: u30) void {
+ blockCopy(tmp, in[(2 * r - 1) * 16 ..], 1);
+ var i: usize = 0;
+ while (i < 2 * r) : (i += 2) {
+ salsaXor(tmp, in[i * 16 ..], out[i * 8 ..]);
+ salsaXor(tmp, in[i * 16 + 16 ..], out[i * 8 + r * 16 ..]);
+ }
+}
+
+fn integerify(b: []align(16) const u32, r: u30) u64 {
+ const j = (2 * r - 1) * 16;
+ return @as(u64, b[j]) | @as(u64, b[j + 1]) << 32;
+}
+
+fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
+ var x = xy[0 .. 32 * r];
+ var y = xy[32 * r ..];
+
+ for (x) |*v1, j| {
+ v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]);
+ }
+
+ var tmp: [16]u32 align(16) = undefined;
+ var i: usize = 0;
+ while (i < n) : (i += 2) {
+ blockCopy(v[i * (32 * r) ..], x, 2 * r);
+ blockMix(&tmp, x, y, r);
+
+ blockCopy(v[(i + 1) * (32 * r) ..], y, 2 * r);
+ blockMix(&tmp, y, x, r);
+ }
+
+ i = 0;
+ while (i < n) : (i += 2) {
+ var j = @intCast(usize, integerify(x, r) & (n - 1));
+ blockXor(x, v[j * (32 * r) ..], 2 * r);
+ blockMix(&tmp, x, y, r);
+
+ j = @intCast(usize, integerify(y, r) & (n - 1));
+ blockXor(y, v[j * (32 * r) ..], 2 * r);
+ blockMix(&tmp, y, x, r);
+ }
+
+ for (x) |v1, j| {
+ mem.writeIntLittle(u32, b[4 * j ..][0..4], v1);
+ }
+}
+
+pub const Params = struct {
+ const Self = @This();
+
+ ln: u6,
+ r: u30,
+ p: u30,
+
+ /// Baseline parameters for interactive logins
+ pub const interactive = Self.fromLimits(524288, 16777216);
+
+ /// Baseline parameters for offline usage
+ pub const sensitive = Self.fromLimits(33554432, 1073741824);
+
+ /// Create parameters from ops and mem limits
+ pub fn fromLimits(ops_limit: u64, mem_limit: usize) Self {
+ const ops = math.max(32768, ops_limit);
+ const r: u30 = 8;
+ if (ops < mem_limit / 32) {
+ const max_n = ops / (r * 4);
+ return Self{ .r = r, .p = 1, .ln = @intCast(u6, math.log2(max_n)) };
+ } else {
+ const max_n = mem_limit / (@intCast(usize, r) * 128);
+ const ln = @intCast(u6, math.log2(max_n));
+ const max_rp = math.min(0x3fffffff, (ops / 4) / (@as(u64, 1) << ln));
+ return Self{ .r = r, .p = @intCast(u30, max_rp / @as(u64, r)), .ln = ln };
+ }
+ }
+};
+
+/// Apply scrypt to generate a key from a password.
+///
+/// scrypt is defined in RFC 7914.
+///
+/// allocator: *mem.Allocator.
+///
+/// derived_key: Slice of appropriate size for generated key. Generally 16 or 32 bytes in length.
+/// May be uninitialized. All bytes will be overwritten.
+/// Maximum size is `derived_key.len / 32 == 0xffff_ffff`.
+///
+/// password: Arbitrary sequence of bytes of any length.
+///
+/// salt: Arbitrary sequence of bytes of any length.
+///
+/// params: Params.
+pub fn kdf(
+ allocator: *mem.Allocator,
+ derived_key: []u8,
+ password: []const u8,
+ salt: []const u8,
+ params: Params,
+) KdfError!void {
+ if (derived_key.len == 0 or derived_key.len / 32 > 0xffff_ffff) return KdfError.OutputTooLong;
+ if (params.ln == 0 or params.r == 0 or params.p == 0) return KdfError.WeakParameters;
+
+ const n64 = @as(u64, 1) << params.ln;
+ if (n64 > max_size) return KdfError.WeakParameters;
+ const n = @intCast(usize, n64);
+ if (@as(u64, params.r) * @as(u64, params.p) >= 1 << 30 or
+ params.r > max_int / 128 / @as(u64, params.p) or
+ params.r > max_int / 256 or
+ n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters;
+
+ var xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);
+ defer allocator.free(xy);
+ var v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);
+ defer allocator.free(v);
+ var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r);
+ defer allocator.free(dk);
+
+ try pwhash.pbkdf2(dk, password, salt, 1, HmacSha256);
+ var i: u32 = 0;
+ while (i < params.p) : (i += 1) {
+ smix(dk[i * 128 * params.r ..], params.r, n, v, xy);
+ }
+ try pwhash.pbkdf2(derived_key, password, dk, 1, HmacSha256);
+}
+
+const crypt_format = struct {
+ /// String prefix for scrypt
+ pub const prefix = "$7$";
+
+ /// Standard type for a set of scrypt parameters, with the salt and hash.
+ pub fn HashResult(comptime crypt_max_hash_len: usize) type {
+ return struct {
+ ln: u6,
+ r: u30,
+ p: u30,
+ salt: []const u8,
+ hash: BinValue(crypt_max_hash_len),
+ };
+ }
+
+ const Codec = CustomB64Codec("./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".*);
+
+ /// A wrapped binary value whose maximum size is `max_len`.
+ ///
+ /// This type must be used whenever a binary value is encoded in a PHC-formatted string.
+ /// This includes `salt`, `hash`, and any other binary parameters such as keys.
+ ///
+ /// Once initialized, the actual value can be read with the `constSlice()` function.
+ pub fn BinValue(comptime max_len: usize) type {
+ return struct {
+ const Self = @This();
+ const capacity = max_len;
+ const max_encoded_length = Codec.encodedLen(max_len);
+
+ buf: [max_len]u8 = undefined,
+ len: usize = 0,
+
+ /// Wrap an existing byte slice
+ pub fn fromSlice(slice: []const u8) EncodingError!Self {
+ if (slice.len > capacity) return EncodingError.NoSpaceLeft;
+ var bin_value: Self = undefined;
+ mem.copy(u8, &bin_value.buf, slice);
+ bin_value.len = slice.len;
+ return bin_value;
+ }
+
+ /// Return the slice containing the actual value.
+ pub fn constSlice(self: Self) []const u8 {
+ return self.buf[0..self.len];
+ }
+
+ fn fromB64(self: *Self, str: []const u8) !void {
+ const len = Codec.decodedLen(str.len);
+ if (len > self.buf.len) return EncodingError.NoSpaceLeft;
+ try Codec.decode(self.buf[0..len], str);
+ self.len = len;
+ }
+
+ fn toB64(self: Self, buf: []u8) ![]const u8 {
+ const value = self.constSlice();
+ const len = Codec.encodedLen(value.len);
+ if (len > buf.len) return EncodingError.NoSpaceLeft;
+ var encoded = buf[0..len];
+ Codec.encode(encoded, value);
+ return encoded;
+ }
+ };
+ }
+
+ /// Expand binary data into a salt for the modular crypt format.
+ pub fn saltFromBin(comptime len: usize, salt: [len]u8) [Codec.encodedLen(len)]u8 {
+ var buf: [Codec.encodedLen(len)]u8 = undefined;
+ Codec.encode(&buf, &salt);
+ return buf;
+ }
+
+ /// Deserialize a string into a structure `T` (matching `HashResult`).
+ pub fn deserialize(comptime T: type, str: []const u8) EncodingError!T {
+ var out: T = undefined;
+
+ if (str.len < 16) return EncodingError.InvalidEncoding;
+ if (!mem.eql(u8, prefix, str[0..3])) return EncodingError.InvalidEncoding;
+ out.ln = try Codec.intDecode(u6, str[3..4]);
+ out.r = try Codec.intDecode(u30, str[4..9]);
+ out.p = try Codec.intDecode(u30, str[9..14]);
+
+ var it = mem.split(u8, str[14..], "$");
+
+ const salt = it.next() orelse return EncodingError.InvalidEncoding;
+ if (@hasField(T, "salt")) out.salt = salt;
+
+ const hash_str = it.next() orelse return EncodingError.InvalidEncoding;
+ if (@hasField(T, "hash")) try out.hash.fromB64(hash_str);
+
+ return out;
+ }
+
+ /// Serialize parameters into a string in modular crypt format.
+ pub fn serialize(params: anytype, str: []u8) EncodingError![]const u8 {
+ var buf = io.fixedBufferStream(str);
+ try serializeTo(params, buf.writer());
+ return buf.getWritten();
+ }
+
+ /// Compute the number of bytes required to serialize `params`
+ pub fn calcSize(params: anytype) usize {
+ var buf = io.countingWriter(io.null_writer);
+ serializeTo(params, buf.writer()) catch unreachable;
+ return @intCast(usize, buf.bytes_written);
+ }
+
+ fn serializeTo(params: anytype, out: anytype) !void {
+ var header: [14]u8 = undefined;
+ mem.copy(u8, header[0..3], prefix);
+ Codec.intEncode(header[3..4], params.ln);
+ Codec.intEncode(header[4..9], params.r);
+ Codec.intEncode(header[9..14], params.p);
+ try out.writeAll(&header);
+ try out.writeAll(params.salt);
+ try out.writeAll("$");
+ var buf: [@TypeOf(params.hash).max_encoded_length]u8 = undefined;
+ const hash_str = try params.hash.toB64(&buf);
+ try out.writeAll(hash_str);
+ }
+
+ /// Custom codec that maps 6 bits into 8 like regular Base64, but uses its own alphabet,
+ /// encodes bits in little-endian, and can also encode integers.
+ fn CustomB64Codec(comptime map: [64]u8) type {
+ return struct {
+ const map64 = map;
+
+ fn encodedLen(len: usize) usize {
+ return (len * 4 + 2) / 3;
+ }
+
+ fn decodedLen(len: usize) usize {
+ return len / 4 * 3 + (len % 4) * 3 / 4;
+ }
+
+ fn intEncode(dst: []u8, src: anytype) void {
+ var n = src;
+ for (dst) |*x| {
+ x.* = map64[@truncate(u6, n)];
+ n = math.shr(@TypeOf(src), n, 6);
+ }
+ }
+
+ fn intDecode(comptime T: type, src: *const [(meta.bitCount(T) + 5) / 6]u8) !T {
+ var v: T = 0;
+ for (src) |x, i| {
+ const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;
+ v |= @intCast(T, vi) << @intCast(math.Log2Int(T), i * 6);
+ }
+ return v;
+ }
+
+ fn decode(dst: []u8, src: []const u8) !void {
+ std.debug.assert(dst.len == decodedLen(src.len));
+ var i: usize = 0;
+ while (i < src.len / 4) : (i += 1) {
+ mem.writeIntSliceLittle(u24, dst[i * 3 ..], try intDecode(u24, src[i * 4 ..][0..4]));
+ }
+ const leftover = src[i * 4 ..];
+ var v: u24 = 0;
+ for (leftover) |_, j| {
+ v |= @as(u24, try intDecode(u6, leftover[j..][0..1])) << @intCast(u5, j * 6);
+ }
+ for (dst[i * 3 ..]) |*x, j| {
+ x.* = @truncate(u8, v >> @intCast(u5, j * 8));
+ }
+ }
+
+ fn encode(dst: []u8, src: []const u8) void {
+ std.debug.assert(dst.len == encodedLen(src.len));
+ var i: usize = 0;
+ while (i < src.len / 3) : (i += 1) {
+ intEncode(dst[i * 4 ..][0..4], mem.readIntSliceLittle(u24, src[i * 3 ..]));
+ }
+ const leftover = src[i * 3 ..];
+ var v: u24 = 0;
+ for (leftover) |x, j| {
+ v |= @as(u24, x) << @intCast(u5, j * 8);
+ }
+ intEncode(dst[i * 4 ..], v);
+ }
+ };
+ }
+};
+
+/// Hash and verify passwords using the PHC format.
+const PhcFormatHasher = struct {
+ const alg_id = "scrypt";
+ const BinValue = phc_format.BinValue;
+
+ const HashResult = struct {
+ alg_id: []const u8,
+ ln: u6,
+ r: u30,
+ p: u30,
+ salt: BinValue(max_salt_len),
+ hash: BinValue(max_hash_len),
+ };
+
+ /// Return a non-deterministic hash of the password encoded as a PHC-format string
+ pub fn create(
+ allocator: *mem.Allocator,
+ password: []const u8,
+ params: Params,
+ buf: []u8,
+ ) HasherError![]const u8 {
+ var salt: [default_salt_len]u8 = undefined;
+ crypto.random.bytes(&salt);
+
+ var hash: [default_hash_len]u8 = undefined;
+ try kdf(allocator, &hash, password, &salt, params);
+
+ return phc_format.serialize(HashResult{
+ .alg_id = alg_id,
+ .ln = params.ln,
+ .r = params.r,
+ .p = params.p,
+ .salt = try BinValue(max_salt_len).fromSlice(&salt),
+ .hash = try BinValue(max_hash_len).fromSlice(&hash),
+ }, buf);
+ }
+
+ /// Verify a password against a PHC-format encoded string
+ pub fn verify(
+ allocator: *mem.Allocator,
+ str: []const u8,
+ password: []const u8,
+ ) HasherError!void {
+ const hash_result = try phc_format.deserialize(HashResult, str);
+ if (!mem.eql(u8, hash_result.alg_id, alg_id)) return HasherError.PasswordVerificationFailed;
+ const params = Params{ .ln = hash_result.ln, .r = hash_result.r, .p = hash_result.p };
+ const expected_hash = hash_result.hash.constSlice();
+ var hash_buf: [max_hash_len]u8 = undefined;
+ if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
+ var hash = hash_buf[0..expected_hash.len];
+ try kdf(allocator, hash, password, hash_result.salt.constSlice(), params);
+ if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
+ }
+};
+
+/// Hash and verify passwords using the modular crypt format.
+const CryptFormatHasher = struct {
+ const BinValue = crypt_format.BinValue;
+ const HashResult = crypt_format.HashResult(max_hash_len);
+
+ /// Length of a string returned by the create() function
+ pub const pwhash_str_length: usize = 101;
+
+ /// Return a non-deterministic hash of the password encoded into the modular crypt format
+ pub fn create(
+ allocator: *mem.Allocator,
+ password: []const u8,
+ params: Params,
+ buf: []u8,
+ ) HasherError![]const u8 {
+ var salt_bin: [default_salt_len]u8 = undefined;
+ crypto.random.bytes(&salt_bin);
+ const salt = crypt_format.saltFromBin(salt_bin.len, salt_bin);
+
+ var hash: [default_hash_len]u8 = undefined;
+ try kdf(allocator, &hash, password, &salt, params);
+
+ return crypt_format.serialize(HashResult{
+ .ln = params.ln,
+ .r = params.r,
+ .p = params.p,
+ .salt = &salt,
+ .hash = try BinValue(max_hash_len).fromSlice(&hash),
+ }, buf);
+ }
+
+ /// Verify a password against a string in modular crypt format
+ pub fn verify(
+ allocator: *mem.Allocator,
+ str: []const u8,
+ password: []const u8,
+ ) HasherError!void {
+ const hash_result = try crypt_format.deserialize(HashResult, str);
+ const params = Params{ .ln = hash_result.ln, .r = hash_result.r, .p = hash_result.p };
+ const expected_hash = hash_result.hash.constSlice();
+ var hash_buf: [max_hash_len]u8 = undefined;
+ if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
+ var hash = hash_buf[0..expected_hash.len];
+ try kdf(allocator, hash, password, hash_result.salt, params);
+ if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
+ }
+};
+
+/// Options for hashing a password.
+pub const HashOptions = struct {
+ allocator: ?*mem.Allocator,
+ params: Params,
+ encoding: pwhash.Encoding,
+};
+
+/// Compute a hash of a password using the scrypt key derivation function.
+/// The function returns a string that includes all the parameters required for verification.
+pub fn strHash(
+ password: []const u8,
+ options: HashOptions,
+ out: []u8,
+) Error![]const u8 {
+ const allocator = options.allocator orelse return Error.AllocatorRequired;
+ switch (options.encoding) {
+ .phc => return PhcFormatHasher.create(allocator, password, options.params, out),
+ .crypt => return CryptFormatHasher.create(allocator, password, options.params, out),
+ }
+}
+
+/// Options for hash verification.
+pub const VerifyOptions = struct {
+ allocator: ?*mem.Allocator,
+};
+
+/// Verify that a previously computed hash is valid for a given password.
+pub fn strVerify(
+ str: []const u8,
+ password: []const u8,
+ options: VerifyOptions,
+) Error!void {
+ const allocator = options.allocator orelse return Error.AllocatorRequired;
+ if (mem.startsWith(u8, str, crypt_format.prefix)) {
+ return CryptFormatHasher.verify(allocator, str, password);
+ } else {
+ return PhcFormatHasher.verify(allocator, str, password);
+ }
+}
+
+test "scrypt kdf" {
+ const password = "testpass";
+ const salt = "saltsalt";
+
+ var dk: [32]u8 = undefined;
+ try kdf(std.testing.allocator, &dk, password, salt, .{ .ln = 15, .r = 8, .p = 1 });
+
+ const hex = "1e0f97c3f6609024022fbe698da29c2fe53ef1087a8e396dc6d5d2a041e886de";
+ var bytes: [hex.len / 2]u8 = undefined;
+ _ = try fmt.hexToBytes(&bytes, hex);
+
+ try std.testing.expectEqualSlices(u8, &bytes, &dk);
+}
+
+test "scrypt kdf rfc 1" {
+ const password = "";
+ const salt = "";
+
+ var dk: [64]u8 = undefined;
+ try kdf(std.testing.allocator, &dk, password, salt, .{ .ln = 4, .r = 1, .p = 1 });
+
+ const hex = "77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906";
+ var bytes: [hex.len / 2]u8 = undefined;
+ _ = try fmt.hexToBytes(&bytes, hex);
+
+ try std.testing.expectEqualSlices(u8, &bytes, &dk);
+}
+
+test "scrypt kdf rfc 2" {
+ const password = "password";
+ const salt = "NaCl";
+
+ var dk: [64]u8 = undefined;
+ try kdf(std.testing.allocator, &dk, password, salt, .{ .ln = 10, .r = 8, .p = 16 });
+
+ const hex = "fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640";
+ var bytes: [hex.len / 2]u8 = undefined;
+ _ = try fmt.hexToBytes(&bytes, hex);
+
+ try std.testing.expectEqualSlices(u8, &bytes, &dk);
+}
+
+test "scrypt kdf rfc 3" {
+ const password = "pleaseletmein";
+ const salt = "SodiumChloride";
+
+ var dk: [64]u8 = undefined;
+ try kdf(std.testing.allocator, &dk, password, salt, .{ .ln = 14, .r = 8, .p = 1 });
+
+ const hex = "7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887";
+ var bytes: [hex.len / 2]u8 = undefined;
+ _ = try fmt.hexToBytes(&bytes, hex);
+
+ try std.testing.expectEqualSlices(u8, &bytes, &dk);
+}
+
+test "scrypt kdf rfc 4" {
+ // skip slow test
+ if (true) {
+ return error.SkipZigTest;
+ }
+
+ const password = "pleaseletmein";
+ const salt = "SodiumChloride";
+
+ var dk: [64]u8 = undefined;
+ try kdf(std.testing.allocator, &dk, password, salt, .{ .ln = 20, .r = 8, .p = 1 });
+
+ const hex = "2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049e8a952fbcbf45c6fa77a41a4";
+ var bytes: [hex.len / 2]u8 = undefined;
+ _ = try fmt.hexToBytes(&bytes, hex);
+
+ try std.testing.expectEqualSlices(u8, &bytes, &dk);
+}
+
+test "scrypt password hashing (crypt format)" {
+ const str = "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5";
+ const password = "Y0!?iQa9M%5ekffW(`";
+ try CryptFormatHasher.verify(std.testing.allocator, str, password);
+
+ const params = Params.interactive;
+ var buf: [CryptFormatHasher.pwhash_str_length]u8 = undefined;
+ const str2 = try CryptFormatHasher.create(std.testing.allocator, password, params, &buf);
+ try CryptFormatHasher.verify(std.testing.allocator, str2, password);
+}
+
+test "scrypt strHash and strVerify" {
+ const alloc = std.testing.allocator;
+
+ const password = "testpass";
+ const verify_options = VerifyOptions{ .allocator = alloc };
+ var buf: [128]u8 = undefined;
+
+ const s = try strHash(
+ password,
+ HashOptions{ .allocator = alloc, .params = Params.interactive, .encoding = .crypt },
+ &buf,
+ );
+ try strVerify(s, password, verify_options);
+
+ const s1 = try strHash(
+ password,
+ HashOptions{ .allocator = alloc, .params = Params.interactive, .encoding = .phc },
+ &buf,
+ );
+ try strVerify(s1, password, verify_options);
+}
+
+test "scrypt unix-scrypt" {
+ const alloc = std.testing.allocator;
+
+ // https://gitlab.com/jas/scrypt-unix-crypt/blob/master/unix-scrypt.txt
+ {
+ const str = "$7$C6..../....SodiumChloride$kBGj9fHznVYFQMEn/qDCfrDevf9YDtcDdKvEqHJLV8D";
+ const password = "pleaseletmein";
+ try strVerify(str, password, .{ .allocator = alloc });
+ }
+ // one of the libsodium test vectors
+ {
+ const str = "$7$B6....1....75gBMAGwfFWZqBdyF3WdTQnWdUsuTiWjG1fF9c1jiSD$tc8RoB3.Em3/zNgMLWo2u00oGIoTyJv4fl3Fl8Tix72";
+ const password = "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg nrDFal+Jxl3,2`#^tFSu%v_+7iYse8-cCkNf!tD=KrW)";
+ try strVerify(str, password, .{ .allocator = alloc });
+ }
+}
+
+test "scrypt crypt format" {
+ const str = "$7$C6..../....SodiumChloride$kBGj9fHznVYFQMEn/qDCfrDevf9YDtcDdKvEqHJLV8D";
+ const params = try crypt_format.deserialize(crypt_format.HashResult(32), str);
+ var buf: [str.len]u8 = undefined;
+ const s1 = try crypt_format.serialize(params, &buf);
+ try std.testing.expectEqualStrings(s1, str);
+}
diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig
index e167a50710..b464fb03f5 100644
--- a/lib/std/crypto/sha1.zig
+++ b/lib/std/crypto/sha1.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
const math = std.math;
diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig
index eb0eccfa84..2d2a70c87f 100644
--- a/lib/std/crypto/sha2.zig
+++ b/lib/std/crypto/sha2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
const math = std.math;
diff --git a/lib/std/crypto/sha3.zig b/lib/std/crypto/sha3.zig
index a4637c7fd4..db8126d183 100644
--- a/lib/std/crypto/sha3.zig
+++ b/lib/std/crypto/sha3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
const math = std.math;
diff --git a/lib/std/crypto/siphash.zig b/lib/std/crypto/siphash.zig
index 3bed5d1086..c984e04490 100644
--- a/lib/std/crypto/siphash.zig
+++ b/lib/std/crypto/siphash.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// SipHash is a moderately fast pseudorandom function, returning a 64-bit or 128-bit tag for an arbitrary long input.
//
diff --git a/lib/std/crypto/test.zig b/lib/std/crypto/test.zig
index b517fbecb1..656fa89cfe 100644
--- a/lib/std/crypto/test.zig
+++ b/lib/std/crypto/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const testing = std.testing;
const fmt = std.fmt;
diff --git a/lib/std/crypto/tlcsprng.zig b/lib/std/crypto/tlcsprng.zig
index 15a356d3d3..46960cc090 100644
--- a/lib/std/crypto/tlcsprng.zig
+++ b/lib/std/crypto/tlcsprng.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Thread-local cryptographically secure pseudo-random number generator.
//! This file has public declarations that are intended to be used internally
//! by the standard library; this namespace is not intended to be exposed
diff --git a/lib/std/cstr.zig b/lib/std/cstr.zig
index da7c646dde..6de5672df3 100644
--- a/lib/std/cstr.zig
+++ b/lib/std/cstr.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const debug = std.debug;
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index c3ef9dec4c..13f8a4a837 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const math = std.math;
@@ -36,7 +31,7 @@ pub const LineInfo = struct {
file_name: []const u8,
allocator: ?*mem.Allocator,
- fn deinit(self: LineInfo) void {
+ pub fn deinit(self: LineInfo) void {
const allocator = self.allocator orelse return;
allocator.free(self.file_name);
}
@@ -47,7 +42,7 @@ pub const SymbolInfo = struct {
compile_unit_name: []const u8 = "???",
line_info: ?LineInfo = null,
- fn deinit(self: @This()) void {
+ pub fn deinit(self: @This()) void {
if (self.line_info) |li| {
li.deinit();
}
diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig
index eb22dba7c0..3a294c2dd3 100644
--- a/lib/std/dwarf.zig
+++ b/lib/std/dwarf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const debug = std.debug;
diff --git a/lib/std/dwarf_bits.zig b/lib/std/dwarf_bits.zig
index 99e268beb7..a40fa8a277 100644
--- a/lib/std/dwarf_bits.zig
+++ b/lib/std/dwarf_bits.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const TAG_padding = 0x00;
pub const TAG_array_type = 0x01;
pub const TAG_class_type = 0x02;
diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig
index d1750ef761..bd07003bad 100644
--- a/lib/std/dynamic_library.zig
+++ b/lib/std/dynamic_library.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = std.builtin;
const std = @import("std.zig");
diff --git a/lib/std/elf.zig b/lib/std/elf.zig
index 6c90dff929..69f04868e8 100644
--- a/lib/std/elf.zig
+++ b/lib/std/elf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const io = std.io;
const os = std.os;
diff --git a/lib/std/enums.zig b/lib/std/enums.zig
index 95c6fc7ec7..cfcc8e4f1d 100644
--- a/lib/std/enums.zig
+++ b/lib/std/enums.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! This module contains utilities and data structures for working with enums.
const std = @import("std.zig");
diff --git a/lib/std/event.zig b/lib/std/event.zig
index cd4af07d64..6e608b54f0 100644
--- a/lib/std/event.zig
+++ b/lib/std/event.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const Channel = @import("event/channel.zig").Channel;
pub const Future = @import("event/future.zig").Future;
pub const Group = @import("event/group.zig").Group;
diff --git a/lib/std/event/batch.zig b/lib/std/event/batch.zig
index af7f293cff..4165f88f48 100644
--- a/lib/std/event/batch.zig
+++ b/lib/std/event/batch.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const testing = std.testing;
diff --git a/lib/std/event/channel.zig b/lib/std/event/channel.zig
index 3880d6e286..915681d4a6 100644
--- a/lib/std/event/channel.zig
+++ b/lib/std/event/channel.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const assert = std.debug.assert;
diff --git a/lib/std/event/future.zig b/lib/std/event/future.zig
index 81326f3fb6..17a7c3050b 100644
--- a/lib/std/event/future.zig
+++ b/lib/std/event/future.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const testing = std.testing;
diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig
index 1d12689aff..dc200017a4 100644
--- a/lib/std/event/group.zig
+++ b/lib/std/event/group.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const Lock = std.event.Lock;
diff --git a/lib/std/event/lock.zig b/lib/std/event/lock.zig
index c7aeff1066..eea6a31455 100644
--- a/lib/std/event/lock.zig
+++ b/lib/std/event/lock.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const assert = std.debug.assert;
diff --git a/lib/std/event/locked.zig b/lib/std/event/locked.zig
index c9303274a9..e921803447 100644
--- a/lib/std/event/locked.zig
+++ b/lib/std/event/locked.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const Lock = std.event.Lock;
diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig
index 9c8550d459..50fb76ec9d 100644
--- a/lib/std/event/loop.zig
+++ b/lib/std/event/loop.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const root = @import("root");
diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig
index 3bd0c86035..43d41b860e 100644
--- a/lib/std/event/rwlock.zig
+++ b/lib/std/event/rwlock.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const assert = std.debug.assert;
diff --git a/lib/std/event/rwlocked.zig b/lib/std/event/rwlocked.zig
index 0272ca39c7..9a569e8f1f 100644
--- a/lib/std/event/rwlocked.zig
+++ b/lib/std/event/rwlocked.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const RwLock = std.event.RwLock;
diff --git a/lib/std/event/wait_group.zig b/lib/std/event/wait_group.zig
index dde01c61a3..2275a06d08 100644
--- a/lib/std/event/wait_group.zig
+++ b/lib/std/event/wait_group.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const Loop = std.event.Loop;
diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig
index 8377fd13b5..93ef50b861 100644
--- a/lib/std/fifo.zig
+++ b/lib/std/fifo.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// FIFO of fixed size items
// Usually used for e.g. byte buffers
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
index 5cbdc57832..dff9e893e3 100644
--- a/lib/std/fmt.zig
+++ b/lib/std/fmt.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const math = std.math;
const assert = std.debug.assert;
@@ -1757,6 +1752,7 @@ test "parseUnsigned" {
}
pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
+pub const ParseFloatError = @import("fmt/parse_float.zig").ParseFloatError;
pub const parseHexFloat = @import("fmt/parse_hex_float.zig").parseHexFloat;
test {
diff --git a/lib/std/fmt/errol.zig b/lib/std/fmt/errol.zig
index a4f46e7f13..e697b7d42f 100644
--- a/lib/std/fmt/errol.zig
+++ b/lib/std/fmt/errol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const enum3 = @import("errol/enum3.zig").enum3;
const enum3_data = @import("errol/enum3.zig").enum3_data;
diff --git a/lib/std/fmt/errol/enum3.zig b/lib/std/fmt/errol/enum3.zig
index db671b8d25..c27753483d 100644
--- a/lib/std/fmt/errol/enum3.zig
+++ b/lib/std/fmt/errol/enum3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const enum3 = [_]u64{
0x4e2e2785c3a2a20b,
0x240a28877a09a4e1,
diff --git a/lib/std/fmt/errol/lookup.zig b/lib/std/fmt/errol/lookup.zig
index 4499d3fdef..2fb6b167bb 100644
--- a/lib/std/fmt/errol/lookup.zig
+++ b/lib/std/fmt/errol/lookup.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const HP = struct {
val: f64,
off: f64,
diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig
index 6178398b17..585c23ed54 100644
--- a/lib/std/fmt/parse_float.zig
+++ b/lib/std/fmt/parse_float.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Adapted from https://github.com/grzegorz-kraszewski/stringtofloat.
// MIT License
@@ -349,7 +344,9 @@ fn caseInEql(a: []const u8, b: []const u8) bool {
return true;
}
-pub fn parseFloat(comptime T: type, s: []const u8) !T {
+pub const ParseFloatError = error{InvalidCharacter};
+
+pub fn parseFloat(comptime T: type, s: []const u8) ParseFloatError!T {
if (s.len == 0 or (s.len == 1 and (s[0] == '+' or s[0] == '-'))) {
return error.InvalidCharacter;
}
diff --git a/lib/std/fmt/parse_hex_float.zig b/lib/std/fmt/parse_hex_float.zig
index 042da60549..45a289fdd2 100644
--- a/lib/std/fmt/parse_hex_float.zig
+++ b/lib/std/fmt/parse_hex_float.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.const std = @import("std");
-//
// The rounding logic is inspired by LLVM's APFloat and Go's atofHex
// implementation.
diff --git a/lib/std/fs.zig b/lib/std/fs.zig
index 0d5db65011..1e02c0e805 100644
--- a/lib/std/fs.zig
+++ b/lib/std/fs.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const root = @import("root");
const builtin = std.builtin;
const std = @import("std.zig");
@@ -339,10 +334,10 @@ pub const Dir = struct {
if (rc == 0) return null;
if (rc < 0) {
switch (os.errno(rc)) {
- os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
- os.EFAULT => unreachable,
- os.ENOTDIR => unreachable,
- os.EINVAL => unreachable,
+ .BADF => unreachable, // Dir is invalid or was opened without iteration ability
+ .FAULT => unreachable,
+ .NOTDIR => unreachable,
+ .INVAL => unreachable,
else => |err| return os.unexpectedErrno(err),
}
}
@@ -385,11 +380,11 @@ pub const Dir = struct {
else
os.system.getdents(self.dir.fd, &self.buf, self.buf.len);
switch (os.errno(rc)) {
- 0 => {},
- os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
- os.EFAULT => unreachable,
- os.ENOTDIR => unreachable,
- os.EINVAL => unreachable,
+ .SUCCESS => {},
+ .BADF => unreachable, // Dir is invalid or was opened without iteration ability
+ .FAULT => unreachable,
+ .NOTDIR => unreachable,
+ .INVAL => unreachable,
else => |err| return os.unexpectedErrno(err),
}
if (rc == 0) return null;
@@ -457,10 +452,10 @@ pub const Dir = struct {
if (rc == 0) return null;
if (rc < 0) {
switch (os.errno(rc)) {
- os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
- os.EFAULT => unreachable,
- os.ENOTDIR => unreachable,
- os.EINVAL => unreachable,
+ .BADF => unreachable, // Dir is invalid or was opened without iteration ability
+ .FAULT => unreachable,
+ .NOTDIR => unreachable,
+ .INVAL => unreachable,
else => |err| return os.unexpectedErrno(err),
}
}
@@ -522,11 +517,11 @@ pub const Dir = struct {
if (self.index >= self.end_index) {
const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
switch (os.linux.getErrno(rc)) {
- 0 => {},
- os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
- os.EFAULT => unreachable,
- os.ENOTDIR => unreachable,
- os.EINVAL => unreachable,
+ .SUCCESS => {},
+ .BADF => unreachable, // Dir is invalid or was opened without iteration ability
+ .FAULT => unreachable,
+ .NOTDIR => unreachable,
+ .INVAL => unreachable,
else => |err| return os.unexpectedErrno(err),
}
if (rc == 0) return null;
@@ -655,12 +650,12 @@ pub const Dir = struct {
if (self.index >= self.end_index) {
var bufused: usize = undefined;
switch (w.fd_readdir(self.dir.fd, &self.buf, self.buf.len, self.cookie, &bufused)) {
- w.ESUCCESS => {},
- w.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
- w.EFAULT => unreachable,
- w.ENOTDIR => unreachable,
- w.EINVAL => unreachable,
- w.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => {},
+ .BADF => unreachable, // Dir is invalid or was opened without iteration ability
+ .FAULT => unreachable,
+ .NOTDIR => unreachable,
+ .INVAL => unreachable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return os.unexpectedErrno(err),
}
if (bufused == 0) return null;
@@ -795,22 +790,31 @@ pub const Dir = struct {
.kind = base.kind,
};
} else {
- self.stack.pop().iter.dir.close();
+ var item = self.stack.pop();
+ if (self.stack.items.len != 0) {
+ item.iter.dir.close();
+ }
}
}
return null;
}
pub fn deinit(self: *Walker) void {
- while (self.stack.popOrNull()) |*item| item.iter.dir.close();
+ while (self.stack.popOrNull()) |*item| {
+ if (self.stack.items.len != 0) {
+ item.iter.dir.close();
+ }
+ }
self.stack.deinit();
self.name_buffer.deinit();
}
};
/// Recursively iterates over a directory.
+ /// `self` must have been opened with `OpenDirOptions{.iterate = true}`.
/// Must call `Walker.deinit` when done.
/// The order of returned file system entries is undefined.
+ /// `self` will not be closed after walking it.
pub fn walk(self: Dir, allocator: *Allocator) !Walker {
var name_buffer = std.ArrayList(u8).init(allocator);
errdefer name_buffer.deinit();
@@ -2548,12 +2552,12 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
if (comptime std.Target.current.isDarwin()) {
const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
switch (os.errno(rc)) {
- 0 => return,
- os.EINVAL => unreachable,
- os.ENOMEM => return error.SystemResources,
+ .SUCCESS => return,
+ .INVAL => unreachable,
+ .NOMEM => return error.SystemResources,
// The source file is not a directory, symbolic link, or regular file.
// Try with the fallback path before giving up.
- os.ENOTSUP => {},
+ .OPNOTSUPP => {},
else => |err| return os.unexpectedErrno(err),
}
}
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig
index 147ecc7608..1dd5e8ba98 100644
--- a/lib/std/fs/file.zig
+++ b/lib/std/fs/file.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const os = std.os;
diff --git a/lib/std/fs/get_app_data_dir.zig b/lib/std/fs/get_app_data_dir.zig
index 41b8e7311d..fed1c85f39 100644
--- a/lib/std/fs/get_app_data_dir.zig
+++ b/lib/std/fs/get_app_data_dir.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const unicode = std.unicode;
diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig
index baaadcfe59..efc896e6b7 100644
--- a/lib/std/fs/path.zig
+++ b/lib/std/fs/path.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("../std.zig");
const debug = std.debug;
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
index 7cc43bbb36..0ce416454b 100644
--- a/lib/std/fs/test.zig
+++ b/lib/std/fs/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const testing = std.testing;
const builtin = std.builtin;
@@ -909,11 +904,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
test "walker" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
- var arena = ArenaAllocator.init(testing.allocator);
- defer arena.deinit();
- var allocator = &arena.allocator;
-
- var tmp = tmpDir(.{});
+ var tmp = tmpDir(.{ .iterate = true });
defer tmp.cleanup();
// iteration order of walker is undefined, so need lookup maps to check against
@@ -942,10 +933,7 @@ test "walker" {
try tmp.dir.makePath(kv.key);
}
- const tmp_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
- const tmp_dir = try fs.cwd().openDir(tmp_path, .{ .iterate = true });
-
- var walker = try tmp_dir.walk(testing.allocator);
+ var walker = try tmp.dir.walk(testing.allocator);
defer walker.deinit();
var num_walked: usize = 0;
diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig
index 378e4a7bac..ad354e226f 100644
--- a/lib/std/fs/wasi.zig
+++ b/lib/std/fs/wasi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const os = std.os;
const mem = std.mem;
@@ -121,13 +116,13 @@ pub const PreopenList = struct {
while (true) {
var buf: prestat_t = undefined;
switch (fd_prestat_get(fd, &buf)) {
- ESUCCESS => {},
- ENOTSUP => {
+ .SUCCESS => {},
+ .OPNOTSUPP => {
// not a preopen, so keep going
fd = try math.add(fd_t, fd, 1);
continue;
},
- EBADF => {
+ .BADF => {
// OK, no more fds available
break;
},
@@ -137,7 +132,7 @@ pub const PreopenList = struct {
const path_buf = try self.buffer.allocator.alloc(u8, preopen_len);
mem.set(u8, path_buf, 0);
switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) {
- ESUCCESS => {},
+ .SUCCESS => {},
else => |err| return os.unexpectedErrno(err),
}
const preopen = Preopen.new(fd, PreopenType{ .Dir = path_buf });
diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig
index 40867bb3b5..7777793b29 100644
--- a/lib/std/fs/watch.zig
+++ b/lib/std/fs/watch.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const event = std.event;
diff --git a/lib/std/hash.zig b/lib/std/hash.zig
index f5b94725e2..f96d331d0f 100644
--- a/lib/std/hash.zig
+++ b/lib/std/hash.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const adler = @import("hash/adler.zig");
pub const Adler32 = adler.Adler32;
diff --git a/lib/std/hash/adler.zig b/lib/std/hash/adler.zig
index 61408e82ee..78f52b539b 100644
--- a/lib/std/hash/adler.zig
+++ b/lib/std/hash/adler.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Adler32 checksum.
//
// https://tools.ietf.org/html/rfc1950#section-9
diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig
index 3375066c12..4f037349ba 100644
--- a/lib/std/hash/auto_hash.zig
+++ b/lib/std/hash/auto_hash.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
diff --git a/lib/std/hash/benchmark.zig b/lib/std/hash/benchmark.zig
index 5a86afa056..b4952a9260 100644
--- a/lib/std/hash/benchmark.zig
+++ b/lib/std/hash/benchmark.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// zig run benchmark.zig --release-fast --zig-lib-dir ..
const builtin = std.builtin;
diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig
index 8796eb0075..c6118c8cdc 100644
--- a/lib/std/hash/cityhash.zig
+++ b/lib/std/hash/cityhash.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig
index 597a0a4c75..0b7a9a7c51 100644
--- a/lib/std/hash/crc.zig
+++ b/lib/std/hash/crc.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// There are two implementations of CRC32 implemented with the following key characteristics:
//
// - Crc32WithPoly uses 8Kb of tables but is ~10x faster than the small method.
diff --git a/lib/std/hash/fnv.zig b/lib/std/hash/fnv.zig
index 7dadf5488f..3175f26820 100644
--- a/lib/std/hash/fnv.zig
+++ b/lib/std/hash/fnv.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// FNV1a - Fowler-Noll-Vo hash function
//
// FNV1a is a fast, non-cryptographic hash function with fairly good distribution properties.
diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig
index 2c6ec2bf16..adb150446d 100644
--- a/lib/std/hash/murmur.zig
+++ b/lib/std/hash/murmur.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
diff --git a/lib/std/hash/wyhash.zig b/lib/std/hash/wyhash.zig
index 83cd5e097c..05340592a9 100644
--- a/lib/std/hash/wyhash.zig
+++ b/lib/std/hash/wyhash.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const mem = std.mem;
diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig
index 77d2df2efe..5f5321dd56 100644
--- a/lib/std/hash_map.zig
+++ b/lib/std/hash_map.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const assert = debug.assert;
const autoHash = std.hash.autoHash;
diff --git a/lib/std/heap.zig b/lib/std/heap.zig
index 088d6b39bb..9032225b39 100644
--- a/lib/std/heap.zig
+++ b/lib/std/heap.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const root = @import("root");
const debug = std.debug;
diff --git a/lib/std/heap/arena_allocator.zig b/lib/std/heap/arena_allocator.zig
index 356d5c5d81..d61f66ce4a 100644
--- a/lib/std/heap/arena_allocator.zig
+++ b/lib/std/heap/arena_allocator.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const mem = std.mem;
diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig
index 006a41dae8..d51c349be2 100644
--- a/lib/std/heap/general_purpose_allocator.zig
+++ b/lib/std/heap/general_purpose_allocator.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//! # General Purpose Allocator
//!
//! ## Design Priorities
diff --git a/lib/std/heap/log_to_writer_allocator.zig b/lib/std/heap/log_to_writer_allocator.zig
index c2fd687e0c..cf9c4162a7 100644
--- a/lib/std/heap/log_to_writer_allocator.zig
+++ b/lib/std/heap/log_to_writer_allocator.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const Allocator = std.mem.Allocator;
diff --git a/lib/std/heap/logging_allocator.zig b/lib/std/heap/logging_allocator.zig
index 7baa857f00..5bd967b696 100644
--- a/lib/std/heap/logging_allocator.zig
+++ b/lib/std/heap/logging_allocator.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const Allocator = std.mem.Allocator;
diff --git a/lib/std/io.zig b/lib/std/io.zig
index 8bb9c4d2c0..4127a7b08b 100644
--- a/lib/std/io.zig
+++ b/lib/std/io.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const root = @import("root");
diff --git a/lib/std/io/bit_reader.zig b/lib/std/io/bit_reader.zig
index 9092c8a62d..cb123bacbf 100644
--- a/lib/std/io/bit_reader.zig
+++ b/lib/std/io/bit_reader.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const io = std.io;
diff --git a/lib/std/io/bit_writer.zig b/lib/std/io/bit_writer.zig
index daa0718a18..5236e4965a 100644
--- a/lib/std/io/bit_writer.zig
+++ b/lib/std/io/bit_writer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const io = std.io;
diff --git a/lib/std/io/buffered_atomic_file.zig b/lib/std/io/buffered_atomic_file.zig
index 1aed190a47..5b27ba78f1 100644
--- a/lib/std/io/buffered_atomic_file.zig
+++ b/lib/std/io/buffered_atomic_file.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
const fs = std.fs;
diff --git a/lib/std/io/buffered_reader.zig b/lib/std/io/buffered_reader.zig
index 16e6480037..b803e37602 100644
--- a/lib/std/io/buffered_reader.zig
+++ b/lib/std/io/buffered_reader.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const assert = std.debug.assert;
diff --git a/lib/std/io/buffered_writer.zig b/lib/std/io/buffered_writer.zig
index 056ff08987..77f556f2d2 100644
--- a/lib/std/io/buffered_writer.zig
+++ b/lib/std/io/buffered_writer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
diff --git a/lib/std/io/c_writer.zig b/lib/std/io/c_writer.zig
index 9f551b08fc..758df71165 100644
--- a/lib/std/io/c_writer.zig
+++ b/lib/std/io/c_writer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const io = std.io;
@@ -17,19 +12,19 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter {
fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
if (amt_written >= 0) return amt_written;
- switch (std.c._errno().*) {
- 0 => unreachable,
- os.EINVAL => unreachable,
- os.EFAULT => unreachable,
- os.EAGAIN => unreachable, // this is a blocking API
- os.EBADF => unreachable, // always a race condition
- os.EDESTADDRREQ => unreachable, // connect was never called
- os.EDQUOT => return error.DiskQuota,
- os.EFBIG => return error.FileTooBig,
- os.EIO => return error.InputOutput,
- os.ENOSPC => return error.NoSpaceLeft,
- os.EPERM => return error.AccessDenied,
- os.EPIPE => return error.BrokenPipe,
+ switch (@intToEnum(os.E, std.c._errno().*)) {
+ .SUCCESS => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable, // this is a blocking API
+ .BADF => unreachable, // always a race condition
+ .DESTADDRREQ => unreachable, // connect was never called
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
else => |err| return os.unexpectedErrno(err),
}
}
diff --git a/lib/std/io/change_detection_stream.zig b/lib/std/io/change_detection_stream.zig
index 57ef8a82bd..5ba2bb3c10 100644
--- a/lib/std/io/change_detection_stream.zig
+++ b/lib/std/io/change_detection_stream.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../std.zig");
const io = std.io;
const mem = std.mem;
diff --git a/lib/std/io/counting_reader.zig b/lib/std/io/counting_reader.zig
index 3b06555deb..54e8e6f531 100644
--- a/lib/std/io/counting_reader.zig
+++ b/lib/std/io/counting_reader.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const testing = std.testing;
diff --git a/lib/std/io/counting_writer.zig b/lib/std/io/counting_writer.zig
index 28eddc1303..ee86c2a9b1 100644
--- a/lib/std/io/counting_writer.zig
+++ b/lib/std/io/counting_writer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const testing = std.testing;
diff --git a/lib/std/io/find_byte_writer.zig b/lib/std/io/find_byte_writer.zig
index db45114d3e..cb7efac2d9 100644
--- a/lib/std/io/find_byte_writer.zig
+++ b/lib/std/io/find_byte_writer.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../std.zig");
const io = std.io;
const assert = std.debug.assert;
diff --git a/lib/std/io/fixed_buffer_stream.zig b/lib/std/io/fixed_buffer_stream.zig
index 8eb7c62a65..3623ef1989 100644
--- a/lib/std/io/fixed_buffer_stream.zig
+++ b/lib/std/io/fixed_buffer_stream.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const testing = std.testing;
diff --git a/lib/std/io/limited_reader.zig b/lib/std/io/limited_reader.zig
index 1647d5aac3..aa00af0d09 100644
--- a/lib/std/io/limited_reader.zig
+++ b/lib/std/io/limited_reader.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const assert = std.debug.assert;
diff --git a/lib/std/io/multi_writer.zig b/lib/std/io/multi_writer.zig
index 9676212bbd..ae683848d0 100644
--- a/lib/std/io/multi_writer.zig
+++ b/lib/std/io/multi_writer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const testing = std.testing;
diff --git a/lib/std/io/peek_stream.zig b/lib/std/io/peek_stream.zig
index f3b8ba6645..c77052f975 100644
--- a/lib/std/io/peek_stream.zig
+++ b/lib/std/io/peek_stream.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
const mem = std.mem;
diff --git a/lib/std/io/reader.zig b/lib/std/io/reader.zig
index 920b82e420..3e8eb8ec24 100644
--- a/lib/std/io/reader.zig
+++ b/lib/std/io/reader.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const math = std.math;
@@ -143,6 +138,23 @@ pub fn Reader(
return array_list.toOwnedSlice();
}
+ /// Reads from the stream until specified byte is found. If the buffer is not
+ /// large enough to hold the entire contents, `error.StreamTooLong` is returned.
+ /// Returns a slice of the stream data, with ptr equal to `buf.ptr`. The
+ /// delimiter byte is not included in the returned slice.
+ pub fn readUntilDelimiter(self: Self, buf: []u8, delimiter: u8) ![]u8 {
+ var index: usize = 0;
+ while (true) {
+ const byte = try self.readByte();
+
+ if (byte == delimiter) return buf[0..index];
+ if (index >= buf.len) return error.StreamTooLong;
+
+ buf[index] = byte;
+ index += 1;
+ }
+ }
+
/// Allocates enough memory to read until `delimiter` or end-of-stream.
/// If the allocated memory would be greater than `max_size`, returns
/// `error.StreamTooLong`. If end-of-stream is found, returns the rest
diff --git a/lib/std/io/seekable_stream.zig b/lib/std/io/seekable_stream.zig
index 4ba39fff42..1aa653dbe5 100644
--- a/lib/std/io/seekable_stream.zig
+++ b/lib/std/io/seekable_stream.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub fn SeekableStream(
diff --git a/lib/std/io/stream_source.zig b/lib/std/io/stream_source.zig
index 1496c031bc..06903b2977 100644
--- a/lib/std/io/stream_source.zig
+++ b/lib/std/io/stream_source.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const io = std.io;
diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig
index c04da72230..f5cdbc2792 100644
--- a/lib/std/io/test.zig
+++ b/lib/std/io/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = @import("builtin");
const io = std.io;
diff --git a/lib/std/io/writer.zig b/lib/std/io/writer.zig
index 6f9386b8de..4f809dcca5 100644
--- a/lib/std/io/writer.zig
+++ b/lib/std/io/writer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = std.builtin;
diff --git a/lib/std/json.zig b/lib/std/json.zig
index 7aac61681d..ce9ed9af7d 100644
--- a/lib/std/json.zig
+++ b/lib/std/json.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// JSON parser conforming to RFC8259.
//
// https://tools.ietf.org/html/rfc8259
@@ -1468,7 +1463,9 @@ pub const ParseOptions = struct {
allow_trailing_data: bool = false,
};
-fn skipValue(tokens: *TokenStream) !void {
+const SkipValueError = error{UnexpectedJsonDepth} || TokenStream.Error;
+
+fn skipValue(tokens: *TokenStream) SkipValueError!void {
const original_depth = tokens.stackUsed();
// Return an error if no value is found
@@ -1530,7 +1527,84 @@ test "skipValue" {
}
}
-fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: ParseOptions) !T {
+fn ParseInternalError(comptime T: type) type {
+ // `inferred_types` is used to avoid infinite recursion for recursive type definitions.
+ const inferred_types = [_]type{};
+ return ParseInternalErrorImpl(T, &inferred_types);
+}
+
+fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const type) type {
+ for (inferred_types) |ty| {
+ if (T == ty) return error{};
+ }
+
+ switch (@typeInfo(T)) {
+ .Bool => return error{UnexpectedToken},
+ .Float, .ComptimeFloat => return error{UnexpectedToken} || std.fmt.ParseFloatError,
+ .Int, .ComptimeInt => {
+ return error{ UnexpectedToken, InvalidNumber, Overflow } ||
+ std.fmt.ParseIntError || std.fmt.ParseFloatError;
+ },
+ .Optional => |optionalInfo| {
+ return ParseInternalErrorImpl(optionalInfo.child, inferred_types ++ [_]type{T});
+ },
+ .Enum => return error{ UnexpectedToken, InvalidEnumTag } || std.fmt.ParseIntError ||
+ std.meta.IntToEnumError || std.meta.IntToEnumError,
+ .Union => |unionInfo| {
+ if (unionInfo.tag_type) |_| {
+ var errors = error{NoUnionMembersMatched};
+ for (unionInfo.fields) |u_field| {
+ errors = errors || ParseInternalErrorImpl(u_field.field_type, inferred_types ++ [_]type{T});
+ }
+ return errors;
+ } else {
+ @compileError("Unable to parse into untagged union '" ++ @typeName(T) ++ "'");
+ }
+ },
+ .Struct => |structInfo| {
+ var errors = error{
+ DuplicateJSONField,
+ UnexpectedEndOfJson,
+ UnexpectedToken,
+ UnexpectedValue,
+ UnknownField,
+ MissingField,
+ } || SkipValueError || TokenStream.Error;
+ for (structInfo.fields) |field| {
+ errors = errors || ParseInternalErrorImpl(field.field_type, inferred_types ++ [_]type{T});
+ }
+ return errors;
+ },
+ .Array => |arrayInfo| {
+ return error{ UnexpectedEndOfJson, UnexpectedToken } || TokenStream.Error ||
+ UnescapeValidStringError ||
+ ParseInternalErrorImpl(arrayInfo.child, inferred_types ++ [_]type{T});
+ },
+ .Pointer => |ptrInfo| {
+ var errors = error{AllocatorRequired} || std.mem.Allocator.Error;
+ switch (ptrInfo.size) {
+ .One => {
+ return errors || ParseInternalErrorImpl(ptrInfo.child, inferred_types ++ [_]type{T});
+ },
+ .Slice => {
+ return errors || error{ UnexpectedEndOfJson, UnexpectedToken } ||
+ ParseInternalErrorImpl(ptrInfo.child, inferred_types ++ [_]type{T}) ||
+ UnescapeValidStringError || TokenStream.Error;
+ },
+ else => @compileError("Unable to parse into type '" ++ @typeName(T) ++ "'"),
+ }
+ },
+ else => return error{},
+ }
+ unreachable;
+}
+
+fn parseInternal(
+ comptime T: type,
+ token: Token,
+ tokens: *TokenStream,
+ options: ParseOptions,
+) ParseInternalError(T)!T {
switch (@typeInfo(T)) {
.Bool => {
return switch (token) {
@@ -1794,7 +1868,11 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
unreachable;
}
-pub fn parse(comptime T: type, tokens: *TokenStream, options: ParseOptions) !T {
+pub fn ParseError(comptime T: type) type {
+ return ParseInternalError(T) || error{UnexpectedEndOfJson} || TokenStream.Error;
+}
+
+pub fn parse(comptime T: type, tokens: *TokenStream, options: ParseOptions) ParseError(T)!T {
const token = (try tokens.next()) orelse return error.UnexpectedEndOfJson;
const r = try parseInternal(T, token, tokens, options);
errdefer parseFree(T, r, options);
@@ -2181,6 +2259,45 @@ test "parse into struct ignoring unknown fields" {
try testing.expectEqualSlices(u8, "zig", r.language);
}
+const ParseIntoRecursiveUnionDefinitionValue = union(enum) {
+ integer: i64,
+ array: []const ParseIntoRecursiveUnionDefinitionValue,
+};
+
+test "parse into recursive union definition" {
+ const T = struct {
+ values: ParseIntoRecursiveUnionDefinitionValue,
+ };
+ const ops = ParseOptions{ .allocator = testing.allocator };
+
+ const r = try parse(T, &std.json.TokenStream.init("{\"values\":[58]}"), ops);
+ defer parseFree(T, r, ops);
+
+ try testing.expectEqual(@as(i64, 58), r.values.array[0].integer);
+}
+
+const ParseIntoDoubleRecursiveUnionValueFirst = union(enum) {
+ integer: i64,
+ array: []const ParseIntoDoubleRecursiveUnionValueSecond,
+};
+
+const ParseIntoDoubleRecursiveUnionValueSecond = union(enum) {
+ boolean: bool,
+ array: []const ParseIntoDoubleRecursiveUnionValueFirst,
+};
+
+test "parse into double recursive union definition" {
+ const T = struct {
+ values: ParseIntoDoubleRecursiveUnionValueFirst,
+ };
+ const ops = ParseOptions{ .allocator = testing.allocator };
+
+ const r = try parse(T, &std.json.TokenStream.init("{\"values\":[[58]]}"), ops);
+ defer parseFree(T, r, ops);
+
+ try testing.expectEqual(@as(i64, 58), r.values.array[0].array[0].integer);
+}
+
/// A non-stream JSON parser which constructs a tree of Value's.
pub const Parser = struct {
allocator: *Allocator,
@@ -2418,10 +2535,12 @@ pub const Parser = struct {
}
};
+pub const UnescapeValidStringError = error{InvalidUnicodeHexSymbol};
+
/// Unescape a JSON string
/// Only to be used on strings already validated by the parser
/// (note the unreachable statements and lack of bounds checking)
-pub fn unescapeValidString(output: []u8, input: []const u8) !void {
+pub fn unescapeValidString(output: []u8, input: []const u8) UnescapeValidStringError!void {
var inIndex: usize = 0;
var outIndex: usize = 0;
diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig
index 027f6acaca..c13d6b8417 100644
--- a/lib/std/json/test.zig
+++ b/lib/std/json/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// RFC 8529 conformance tests.
//
// Tests are taken from https://github.com/nst/JSONTestSuite
diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig
index c9169be755..61da6ec49b 100644
--- a/lib/std/json/write_stream.zig
+++ b/lib/std/json/write_stream.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
diff --git a/lib/std/leb128.zig b/lib/std/leb128.zig
index 6535c867f8..c908b56f69 100644
--- a/lib/std/leb128.zig
+++ b/lib/std/leb128.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const testing = std.testing;
diff --git a/lib/std/linked_list.zig b/lib/std/linked_list.zig
index 7bab3e2188..5039e16583 100644
--- a/lib/std/linked_list.zig
+++ b/lib/std/linked_list.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const debug = std.debug;
const assert = debug.assert;
diff --git a/lib/std/log.zig b/lib/std/log.zig
index a20648626e..02c209c680 100644
--- a/lib/std/log.zig
+++ b/lib/std/log.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! std.log is a standardized interface for logging which allows for the logging
//! of programs and libraries using this interface to be formatted and filtered
//! by the implementer of the root.log function.
@@ -100,6 +94,23 @@ pub const Level = enum {
info,
/// Debug: messages only useful for debugging.
debug,
+
+ /// Returns a string literal of the given level in full text form.
+ pub fn asText(comptime self: Level) switch (self) {
+ .emerg => @TypeOf("emergency"),
+ .crit => @TypeOf("critical"),
+ .err => @TypeOf("error"),
+ .warn => @TypeOf("warning"),
+ else => @TypeOf(@tagName(self)),
+ } {
+ return switch (self) {
+ .emerg => "emergency",
+ .crit => "critical",
+ .err => "error",
+ .warn => "warning",
+ else => @tagName(self),
+ };
+ }
};
/// The default log level is based on build mode.
@@ -145,30 +156,34 @@ fn log(
if (@typeInfo(@TypeOf(root.log)) != .Fn)
@compileError("Expected root.log to be a function");
root.log(message_level, scope, format, args);
- } else if (std.Target.current.os.tag == .freestanding) {
- // On freestanding one must provide a log function; we do not have
- // any I/O configured.
- return;
} else {
- const level_txt = switch (message_level) {
- .emerg => "emergency",
- .alert => "alert",
- .crit => "critical",
- .err => "error",
- .warn => "warning",
- .notice => "notice",
- .info => "info",
- .debug => "debug",
- };
- const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
- const stderr = std.io.getStdErr().writer();
- const held = std.debug.getStderrMutex().acquire();
- defer held.release();
- nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
+ defaultLog(message_level, scope, format, args);
}
}
}
+/// The default implementation for root.log. root.log may forward log messages
+/// to this function.
+pub fn defaultLog(
+ comptime message_level: Level,
+ comptime scope: @Type(.EnumLiteral),
+ comptime format: []const u8,
+ args: anytype,
+) void {
+ if (std.Target.current.os.tag == .freestanding) {
+ // On freestanding one must provide a log function; we do not have
+ // any I/O configured.
+ return;
+ }
+
+ const level_txt = comptime message_level.asText();
+ const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
+ const stderr = std.io.getStdErr().writer();
+ const held = std.debug.getStderrMutex().acquire();
+ defer held.release();
+ nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
+}
+
/// Returns a scoped logging namespace that logs all messages using the scope
/// provided here.
pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
diff --git a/lib/std/macho.zig b/lib/std/macho.zig
index 14be755a70..3c41b65522 100644
--- a/lib/std/macho.zig
+++ b/lib/std/macho.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const mach_header = extern struct {
magic: u32,
cputype: cpu_type_t,
diff --git a/lib/std/math.zig b/lib/std/math.zig
index 9f92e2e82b..01cd68e0ed 100644
--- a/lib/std/math.zig
+++ b/lib/std/math.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const assert = std.debug.assert;
const mem = std.mem;
@@ -111,11 +106,11 @@ pub const inf = @import("math/inf.zig").inf;
/// the specified tolerance.
///
/// The `tolerance` parameter is the absolute tolerance used when determining if
-/// the two numbers are close enough, a good value for this parameter is a small
+/// the two numbers are close enough; a good value for this parameter is a small
/// multiple of `epsilon(T)`.
///
-/// Note that this function is recommended for for comparing small numbers
-/// around zero, using `approxEqRel` is suggested otherwise.
+/// Note that this function is recommended for comparing small numbers
+/// around zero; using `approxEqRel` is suggested otherwise.
///
/// NaN values are never considered equal to any value.
pub fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool {
@@ -138,7 +133,7 @@ pub fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool {
/// than zero.
///
/// The `tolerance` parameter is the relative tolerance used when determining if
-/// the two numbers are close enough, a good value for this parameter is usually
+/// the two numbers are close enough; a good value for this parameter is usually
/// `sqrt(epsilon(T))`, meaning that the two numbers are considered equal if at
/// least half of the digits are equal.
///
diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig
index 5e3a289691..b90ba9c78e 100644
--- a/lib/std/math/acos.zig
+++ b/lib/std/math/acos.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/acosh.zig b/lib/std/math/acosh.zig
index 5e596a7bb0..e42f4fd5d3 100644
--- a/lib/std/math/acosh.zig
+++ b/lib/std/math/acosh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/asin.zig b/lib/std/math/asin.zig
index 16560a12cd..0849fac72e 100644
--- a/lib/std/math/asin.zig
+++ b/lib/std/math/asin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/asinh.zig b/lib/std/math/asinh.zig
index 2855a73eb8..71f7533b89 100644
--- a/lib/std/math/asinh.zig
+++ b/lib/std/math/asinh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/atan.zig b/lib/std/math/atan.zig
index bbfaa22b13..c67e6fe8e0 100644
--- a/lib/std/math/atan.zig
+++ b/lib/std/math/atan.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/atan2.zig b/lib/std/math/atan2.zig
index 21f6b95b8b..d440d65e04 100644
--- a/lib/std/math/atan2.zig
+++ b/lib/std/math/atan2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/atanh.zig b/lib/std/math/atanh.zig
index 68824cea7a..2c27234cd2 100644
--- a/lib/std/math/atanh.zig
+++ b/lib/std/math/atanh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/big.zig b/lib/std/math/big.zig
index 8ae214c666..8c0f7f5e1e 100644
--- a/lib/std/math/big.zig
+++ b/lib/std/math/big.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig
index cbae123189..e289520e57 100644
--- a/lib/std/math/big/int.zig
+++ b/lib/std/math/big/int.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const math = std.math;
const Limb = std.math.big.Limb;
diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig
index f4b294245a..757f994f7e 100644
--- a/lib/std/math/big/int_test.zig
+++ b/lib/std/math/big/int_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const mem = std.mem;
const testing = std.testing;
diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig
index 8b7c2d45d6..64f444eeca 100644
--- a/lib/std/math/big/rational.zig
+++ b/lib/std/math/big/rational.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const debug = std.debug;
const math = std.math;
diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig
index 504657894d..1ff1818e8d 100644
--- a/lib/std/math/cbrt.zig
+++ b/lib/std/math/cbrt.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig
index 77d3218c24..fbac256166 100644
--- a/lib/std/math/ceil.zig
+++ b/lib/std/math/ceil.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig
index 7d37fcca5b..3ae880f7c0 100644
--- a/lib/std/math/complex.zig
+++ b/lib/std/math/complex.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/abs.zig b/lib/std/math/complex/abs.zig
index 6890d15f8a..8716360535 100644
--- a/lib/std/math/complex/abs.zig
+++ b/lib/std/math/complex/abs.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/acos.zig b/lib/std/math/complex/acos.zig
index 3d02ad6358..12aec799e6 100644
--- a/lib/std/math/complex/acos.zig
+++ b/lib/std/math/complex/acos.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/acosh.zig b/lib/std/math/complex/acosh.zig
index c239936d47..6f20e4dda2 100644
--- a/lib/std/math/complex/acosh.zig
+++ b/lib/std/math/complex/acosh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/arg.zig b/lib/std/math/complex/arg.zig
index 8a79daa073..b2e960ae3e 100644
--- a/lib/std/math/complex/arg.zig
+++ b/lib/std/math/complex/arg.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/asin.zig b/lib/std/math/complex/asin.zig
index f2c377df56..e4b97c693d 100644
--- a/lib/std/math/complex/asin.zig
+++ b/lib/std/math/complex/asin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/asinh.zig b/lib/std/math/complex/asinh.zig
index b1083c81bf..bd1b8ee016 100644
--- a/lib/std/math/complex/asinh.zig
+++ b/lib/std/math/complex/asinh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig
index 4550edd965..484b41edf5 100644
--- a/lib/std/math/complex/atan.zig
+++ b/lib/std/math/complex/atan.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex/atanh.zig b/lib/std/math/complex/atanh.zig
index 41232570b5..01ddf7a902 100644
--- a/lib/std/math/complex/atanh.zig
+++ b/lib/std/math/complex/atanh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/conj.zig b/lib/std/math/complex/conj.zig
index ea4ba7356c..7427e44caa 100644
--- a/lib/std/math/complex/conj.zig
+++ b/lib/std/math/complex/conj.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/cos.zig b/lib/std/math/complex/cos.zig
index 0760485bb0..1c470c44c1 100644
--- a/lib/std/math/complex/cos.zig
+++ b/lib/std/math/complex/cos.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/cosh.zig b/lib/std/math/complex/cosh.zig
index 2a3673d4d1..46f7a714a2 100644
--- a/lib/std/math/complex/cosh.zig
+++ b/lib/std/math/complex/cosh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex/exp.zig b/lib/std/math/complex/exp.zig
index 80fa837ab0..f2ae28d3fd 100644
--- a/lib/std/math/complex/exp.zig
+++ b/lib/std/math/complex/exp.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex/ldexp.zig b/lib/std/math/complex/ldexp.zig
index c0a6c7a934..db710a0438 100644
--- a/lib/std/math/complex/ldexp.zig
+++ b/lib/std/math/complex/ldexp.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex/log.zig b/lib/std/math/complex/log.zig
index e59870d556..90c51058cf 100644
--- a/lib/std/math/complex/log.zig
+++ b/lib/std/math/complex/log.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/pow.zig b/lib/std/math/complex/pow.zig
index 092c8c2422..36c6796431 100644
--- a/lib/std/math/complex/pow.zig
+++ b/lib/std/math/complex/pow.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/proj.zig b/lib/std/math/complex/proj.zig
index 8527be2293..1e4b13f0df 100644
--- a/lib/std/math/complex/proj.zig
+++ b/lib/std/math/complex/proj.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/sin.zig b/lib/std/math/complex/sin.zig
index 39b5f584ac..7fa3fcf923 100644
--- a/lib/std/math/complex/sin.zig
+++ b/lib/std/math/complex/sin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/sinh.zig b/lib/std/math/complex/sinh.zig
index 05d1d11bd2..ed344999ee 100644
--- a/lib/std/math/complex/sinh.zig
+++ b/lib/std/math/complex/sinh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig
index 07fed152fa..4f16e631b8 100644
--- a/lib/std/math/complex/sqrt.zig
+++ b/lib/std/math/complex/sqrt.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/complex/tan.zig b/lib/std/math/complex/tan.zig
index 0ee34dfcc2..9e1025f74f 100644
--- a/lib/std/math/complex/tan.zig
+++ b/lib/std/math/complex/tan.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig
index 51dbc0fa90..0960c66679 100644
--- a/lib/std/math/complex/tanh.zig
+++ b/lib/std/math/complex/tanh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/copysign.zig b/lib/std/math/copysign.zig
index 47065fedad..72057c190d 100644
--- a/lib/std/math/copysign.zig
+++ b/lib/std/math/copysign.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/cos.zig b/lib/std/math/cos.zig
index 8033b46692..fad524fc88 100644
--- a/lib/std/math/cos.zig
+++ b/lib/std/math/cos.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from go, which is licensed under a BSD-3 license.
// https://golang.org/LICENSE
//
diff --git a/lib/std/math/cosh.zig b/lib/std/math/cosh.zig
index f252aea805..c71e82ea1c 100644
--- a/lib/std/math/cosh.zig
+++ b/lib/std/math/cosh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/epsilon.zig b/lib/std/math/epsilon.zig
index 61758f1ee0..de0297ee63 100644
--- a/lib/std/math/epsilon.zig
+++ b/lib/std/math/epsilon.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const math = @import("../math.zig");
/// Returns the machine epsilon for type T.
diff --git a/lib/std/math/exp.zig b/lib/std/math/exp.zig
index 43da387e46..384c4efab4 100644
--- a/lib/std/math/exp.zig
+++ b/lib/std/math/exp.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/exp2.zig b/lib/std/math/exp2.zig
index e01c997dd7..502a305854 100644
--- a/lib/std/math/exp2.zig
+++ b/lib/std/math/exp2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/expm1.zig b/lib/std/math/expm1.zig
index ebc76165ba..5911edf36f 100644
--- a/lib/std/math/expm1.zig
+++ b/lib/std/math/expm1.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/expo2.zig b/lib/std/math/expo2.zig
index b88d4c2236..f404570fb6 100644
--- a/lib/std/math/expo2.zig
+++ b/lib/std/math/expo2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/fabs.zig b/lib/std/math/fabs.zig
index 0b3c800b12..1221db2390 100644
--- a/lib/std/math/fabs.zig
+++ b/lib/std/math/fabs.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig
index e4855bc071..c5ddb9e144 100644
--- a/lib/std/math/floor.zig
+++ b/lib/std/math/floor.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/fma.zig b/lib/std/math/fma.zig
index 0bc3271e36..ea6e15538f 100644
--- a/lib/std/math/fma.zig
+++ b/lib/std/math/fma.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/frexp.zig b/lib/std/math/frexp.zig
index 4f3a03b0bc..f0d0c57af5 100644
--- a/lib/std/math/frexp.zig
+++ b/lib/std/math/frexp.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/hypot.zig b/lib/std/math/hypot.zig
index 4c2c6f1d8a..e47a191892 100644
--- a/lib/std/math/hypot.zig
+++ b/lib/std/math/hypot.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig
index deafeda7ce..e8fc56d1f8 100644
--- a/lib/std/math/ilogb.zig
+++ b/lib/std/math/ilogb.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/inf.zig b/lib/std/math/inf.zig
index 5011193e95..86ff245533 100644
--- a/lib/std/math/inf.zig
+++ b/lib/std/math/inf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
diff --git a/lib/std/math/isfinite.zig b/lib/std/math/isfinite.zig
index 68aec258b0..762fb39991 100644
--- a/lib/std/math/isfinite.zig
+++ b/lib/std/math/isfinite.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
diff --git a/lib/std/math/isinf.zig b/lib/std/math/isinf.zig
index 792e6b38f3..cadaa8d937 100644
--- a/lib/std/math/isinf.zig
+++ b/lib/std/math/isinf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
diff --git a/lib/std/math/isnan.zig b/lib/std/math/isnan.zig
index cf598322e5..f28eb9ce8d 100644
--- a/lib/std/math/isnan.zig
+++ b/lib/std/math/isnan.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
diff --git a/lib/std/math/isnormal.zig b/lib/std/math/isnormal.zig
index f3942d121c..0430e1367a 100644
--- a/lib/std/math/isnormal.zig
+++ b/lib/std/math/isnormal.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig
index f85571fe34..d2a5ae807e 100644
--- a/lib/std/math/ln.zig
+++ b/lib/std/math/ln.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig
index bf170aa95b..cab652c620 100644
--- a/lib/std/math/log.zig
+++ b/lib/std/math/log.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig
index 56e4afbab6..19602fb4a2 100644
--- a/lib/std/math/log10.zig
+++ b/lib/std/math/log10.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/log1p.zig b/lib/std/math/log1p.zig
index f844332818..e186b2795a 100644
--- a/lib/std/math/log1p.zig
+++ b/lib/std/math/log1p.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig
index 1a42404fea..fca941c49a 100644
--- a/lib/std/math/log2.zig
+++ b/lib/std/math/log2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/modf.zig b/lib/std/math/modf.zig
index 2a8cf00bbb..d12c497729 100644
--- a/lib/std/math/modf.zig
+++ b/lib/std/math/modf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/nan.zig b/lib/std/math/nan.zig
index 98051b155a..5a01a5b3bd 100644
--- a/lib/std/math/nan.zig
+++ b/lib/std/math/nan.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const math = @import("../math.zig");
/// Returns the nan representation for type T.
diff --git a/lib/std/math/pow.zig b/lib/std/math/pow.zig
index 732d716dff..040abf9a44 100644
--- a/lib/std/math/pow.zig
+++ b/lib/std/math/pow.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from go, which is licensed under a BSD-3 license.
// https://golang.org/LICENSE
//
diff --git a/lib/std/math/powi.zig b/lib/std/math/powi.zig
index ff7f44f483..6c4b3a65f4 100644
--- a/lib/std/math/powi.zig
+++ b/lib/std/math/powi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Based on Rust, which is licensed under the MIT license.
// https://github.com/rust-lang/rust/blob/360432f1e8794de58cd94f34c9c17ad65871e5b5/LICENSE-MIT
//
diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig
index 863752a3f5..7e1ee1ebd1 100644
--- a/lib/std/math/round.zig
+++ b/lib/std/math/round.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/scalbn.zig b/lib/std/math/scalbn.zig
index bdf382a303..30494c820a 100644
--- a/lib/std/math/scalbn.zig
+++ b/lib/std/math/scalbn.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig
index a1f2f127d4..056add5ae6 100644
--- a/lib/std/math/signbit.zig
+++ b/lib/std/math/signbit.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
diff --git a/lib/std/math/sin.zig b/lib/std/math/sin.zig
index 83cccfe8bf..4754e9502b 100644
--- a/lib/std/math/sin.zig
+++ b/lib/std/math/sin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from go, which is licensed under a BSD-3 license.
// https://golang.org/LICENSE
//
diff --git a/lib/std/math/sinh.zig b/lib/std/math/sinh.zig
index 5a38e83ba9..5ec47fa3b5 100644
--- a/lib/std/math/sinh.zig
+++ b/lib/std/math/sinh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig
index 5cd224aaaa..d54063dcf6 100644
--- a/lib/std/math/sqrt.zig
+++ b/lib/std/math/sqrt.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
diff --git a/lib/std/math/tan.zig b/lib/std/math/tan.zig
index 7fedf301c4..d2c5009fb6 100644
--- a/lib/std/math/tan.zig
+++ b/lib/std/math/tan.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from go, which is licensed under a BSD-3 license.
// https://golang.org/LICENSE
//
diff --git a/lib/std/math/tanh.zig b/lib/std/math/tanh.zig
index 8f269db021..dcde79a925 100644
--- a/lib/std/math/tanh.zig
+++ b/lib/std/math/tanh.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/math/trunc.zig b/lib/std/math/trunc.zig
index 0d83dc608d..eab9a8b0c7 100644
--- a/lib/std/math/trunc.zig
+++ b/lib/std/math/trunc.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
index a0e87f26a5..57d5a38311 100644
--- a/lib/std/mem.zig
+++ b/lib/std/mem.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const debug = std.debug;
const assert = debug.assert;
diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig
index 1e13ed97b7..9ea7aeb90e 100644
--- a/lib/std/mem/Allocator.zig
+++ b/lib/std/mem/Allocator.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//! The standard memory allocation interface.
const std = @import("../std.zig");
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index 03fb4f80f1..a1bfacf597 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const debug = std.debug;
diff --git a/lib/std/meta/trailer_flags.zig b/lib/std/meta/trailer_flags.zig
index 595f6917d9..516a65cfac 100644
--- a/lib/std/meta/trailer_flags.zig
+++ b/lib/std/meta/trailer_flags.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const meta = std.meta;
const testing = std.testing;
diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig
index 26330aebc4..d1590141a1 100644
--- a/lib/std/meta/trait.zig
+++ b/lib/std/meta/trait.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const mem = std.mem;
diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig
index 9707c0634a..693937b399 100644
--- a/lib/std/multi_array_list.zig
+++ b/lib/std/multi_array_list.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const assert = std.debug.assert;
const meta = std.meta;
diff --git a/lib/std/net.zig b/lib/std/net.zig
index fea033dc9c..c7411d9ecc 100644
--- a/lib/std/net.zig
+++ b/lib/std/net.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = @import("builtin");
const assert = std.debug.assert;
diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig
index 589efbf53e..2e63fc9329 100644
--- a/lib/std/net/test.zig
+++ b/lib/std/net/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const builtin = std.builtin;
const net = std.net;
diff --git a/lib/std/once.zig b/lib/std/once.zig
index a557f4aac9..638d3b1066 100644
--- a/lib/std/once.zig
+++ b/lib/std/once.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const testing = std.testing;
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 5735539366..294784c2bd 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// This file contains thin wrappers around OS-specific APIs, with these
// specific goals in mind:
// * Convert "errno"-style error codes into Zig errors.
@@ -116,13 +111,13 @@ pub fn close(fd: fd_t) void {
if (comptime std.Target.current.isDarwin()) {
// This avoids the EINTR problem.
switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {
- EBADF => unreachable, // Always a race condition.
+ .BADF => unreachable, // Always a race condition.
else => return,
}
}
switch (errno(system.close(fd))) {
- EBADF => unreachable, // Always a race condition.
- EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
+ .BADF => unreachable, // Always a race condition.
+ .INTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
else => return,
}
}
@@ -159,11 +154,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
};
switch (res.err) {
- 0 => buf = buf[res.num_read..],
- EINVAL => unreachable,
- EFAULT => unreachable,
- EINTR => continue,
- ENOSYS => return getRandomBytesDevURandom(buf),
+ .SUCCESS => buf = buf[res.num_read..],
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .INTR => continue,
+ .NOSYS => return getRandomBytesDevURandom(buf),
else => return unexpectedErrno(res.err),
}
}
@@ -175,7 +170,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
return;
},
.wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) {
- 0 => return,
+ .SUCCESS => return,
else => |err| return unexpectedErrno(err),
},
else => return getRandomBytesDevURandom(buffer),
@@ -238,7 +233,7 @@ pub const RaiseError = UnexpectedError;
pub fn raise(sig: u8) RaiseError!void {
if (builtin.link_libc) {
switch (errno(system.raise(sig))) {
- 0 => return,
+ .SUCCESS => return,
else => |err| return unexpectedErrno(err),
}
}
@@ -255,7 +250,7 @@ pub fn raise(sig: u8) RaiseError!void {
_ = linux.sigprocmask(SIG_SETMASK, &set, null);
switch (errno(rc)) {
- 0 => return,
+ .SUCCESS => return,
else => |err| return unexpectedErrno(err),
}
}
@@ -267,10 +262,10 @@ pub const KillError = error{PermissionDenied} || UnexpectedError;
pub fn kill(pid: pid_t, sig: u8) KillError!void {
switch (errno(system.kill(pid, sig))) {
- 0 => return,
- EINVAL => unreachable, // invalid signal
- EPERM => return error.PermissionDenied,
- ESRCH => unreachable, // always a race condition
+ .SUCCESS => return,
+ .INVAL => unreachable, // invalid signal
+ .PERM => return error.PermissionDenied,
+ .SRCH => unreachable, // always a race condition
else => |err| return unexpectedErrno(err),
}
}
@@ -342,19 +337,19 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
var nread: usize = undefined;
switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) {
- wasi.ESUCCESS => return nread,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.
- wasi.EIO => return error.InputOutput,
- wasi.EISDIR => return error.IsDir,
- wasi.ENOBUFS => return error.SystemResources,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ECONNRESET => return error.ConnectionResetByPeer,
- wasi.ETIMEDOUT => return error.ConnectionTimedOut,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nread,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForReading, // Can be a race condition.
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .TIMEDOUT => return error.ConnectionTimedOut,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -370,18 +365,18 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
while (true) {
const rc = system.read(fd, buf.ptr, adjusted_len);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForReading, // Can be a race condition.
- EIO => return error.InputOutput,
- EISDIR => return error.IsDir,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- ECONNRESET => return error.ConnectionResetByPeer,
- ETIMEDOUT => return error.ConnectionTimedOut,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForReading, // Can be a race condition.
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .TIMEDOUT => return error.ConnectionTimedOut,
else => |err| return unexpectedErrno(err),
}
}
@@ -407,17 +402,17 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var nread: usize = undefined;
switch (wasi.fd_read(fd, iov.ptr, iov.len, &nread)) {
- wasi.ESUCCESS => return nread,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable, // currently not support in WASI
- wasi.EBADF => return error.NotOpenForReading, // can be a race condition
- wasi.EIO => return error.InputOutput,
- wasi.EISDIR => return error.IsDir,
- wasi.ENOBUFS => return error.SystemResources,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nread,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable, // currently not support in WASI
+ .BADF => return error.NotOpenForReading, // can be a race condition
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -426,16 +421,16 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
// TODO handle the case when iov_len is too large and get rid of this @intCast
const rc = system.readv(fd, iov.ptr, iov_count);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForReading, // can be a race condition
- EIO => return error.InputOutput,
- EISDIR => return error.IsDir,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForReading, // can be a race condition
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -469,21 +464,21 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
var nread: usize = undefined;
switch (wasi.fd_pread(fd, &iovs, iovs.len, offset, &nread)) {
- wasi.ESUCCESS => return nread,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.
- wasi.EIO => return error.InputOutput,
- wasi.EISDIR => return error.IsDir,
- wasi.ENOBUFS => return error.SystemResources,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ECONNRESET => return error.ConnectionResetByPeer,
- wasi.ENXIO => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nread,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForReading, // Can be a race condition.
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -505,20 +500,20 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
while (true) {
const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForReading, // Can be a race condition.
- EIO => return error.InputOutput,
- EISDIR => return error.IsDir,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- ECONNRESET => return error.ConnectionResetByPeer,
- ENXIO => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForReading, // Can be a race condition.
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -558,15 +553,15 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
}
if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
switch (wasi.fd_filestat_set_size(fd, length)) {
- wasi.ESUCCESS => return,
- wasi.EINTR => unreachable,
- wasi.EFBIG => return error.FileTooBig,
- wasi.EIO => return error.InputOutput,
- wasi.EPERM => return error.AccessDenied,
- wasi.ETXTBSY => return error.FileBusy,
- wasi.EBADF => unreachable, // Handle not open for writing
- wasi.EINVAL => unreachable, // Handle not open for writing
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .INTR => unreachable,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .PERM => return error.AccessDenied,
+ .TXTBSY => return error.FileBusy,
+ .BADF => unreachable, // Handle not open for writing
+ .INVAL => unreachable, // Handle not open for writing
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -579,14 +574,14 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
const ilen = @bitCast(i64, length); // the OS treats this as unsigned
switch (errno(ftruncate_sym(fd, ilen))) {
- 0 => return,
- EINTR => continue,
- EFBIG => return error.FileTooBig,
- EIO => return error.InputOutput,
- EPERM => return error.AccessDenied,
- ETXTBSY => return error.FileBusy,
- EBADF => unreachable, // Handle not open for writing
- EINVAL => unreachable, // Handle not open for writing
+ .SUCCESS => return,
+ .INTR => continue,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .PERM => return error.AccessDenied,
+ .TXTBSY => return error.FileBusy,
+ .BADF => unreachable, // Handle not open for writing
+ .INVAL => unreachable, // Handle not open for writing
else => |err| return unexpectedErrno(err),
}
}
@@ -620,20 +615,20 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var nread: usize = undefined;
switch (wasi.fd_pread(fd, iov.ptr, iov.len, offset, &nread)) {
- wasi.ESUCCESS => return nread,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForReading, // can be a race condition
- wasi.EIO => return error.InputOutput,
- wasi.EISDIR => return error.IsDir,
- wasi.ENOBUFS => return error.SystemResources,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENXIO => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nread,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForReading, // can be a race condition
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -649,19 +644,19 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
while (true) {
const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);
switch (errno(rc)) {
- 0 => return @bitCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForReading, // can be a race condition
- EIO => return error.InputOutput,
- EISDIR => return error.IsDir,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- ENXIO => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
+ .SUCCESS => return @bitCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForReading, // can be a race condition
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -723,20 +718,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
}};
var nwritten: usize = undefined;
switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) {
- wasi.ESUCCESS => return nwritten,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
- wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EFBIG => return error.FileTooBig,
- wasi.EIO => return error.InputOutput,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.EPERM => return error.AccessDenied,
- wasi.EPIPE => return error.BrokenPipe,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nwritten,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForWriting, // can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -751,20 +746,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
while (true) {
const rc = system.write(fd, bytes.ptr, adjusted_len);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForWriting, // can be a race condition.
- EDESTADDRREQ => unreachable, // `connect` was never called.
- EDQUOT => return error.DiskQuota,
- EFBIG => return error.FileTooBig,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EPERM => return error.AccessDenied,
- EPIPE => return error.BrokenPipe,
- ECONNRESET => return error.ConnectionResetByPeer,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForWriting, // can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .CONNRESET => return error.ConnectionResetByPeer,
else => |err| return unexpectedErrno(err),
}
}
@@ -787,7 +782,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
/// On Windows, if the application has a global event loop enabled, I/O Completion Ports are
/// used to perform the I/O. `error.WouldBlock` is not possible on Windows.
///
-/// If `iov.len` is larger than will fit in a `u31`, a partial write will occur.
+/// If `iov.len` is larger than `IOV_MAX`, a partial write will occur.
pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
if (std.Target.current.os.tag == .windows) {
// TODO improve this to use WriteFileScatter
@@ -798,42 +793,42 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var nwritten: usize = undefined;
switch (wasi.fd_write(fd, iov.ptr, iov.len, &nwritten)) {
- wasi.ESUCCESS => return nwritten,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
- wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EFBIG => return error.FileTooBig,
- wasi.EIO => return error.InputOutput,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.EPERM => return error.AccessDenied,
- wasi.EPIPE => return error.BrokenPipe,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nwritten,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForWriting, // can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
- const iov_count = math.cast(u31, iov.len) catch math.maxInt(u31);
+ const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);
while (true) {
const rc = system.writev(fd, iov.ptr, iov_count);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForWriting, // Can be a race condition.
- EDESTADDRREQ => unreachable, // `connect` was never called.
- EDQUOT => return error.DiskQuota,
- EFBIG => return error.FileTooBig,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EPERM => return error.AccessDenied,
- EPIPE => return error.BrokenPipe,
- ECONNRESET => return error.ConnectionResetByPeer,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForWriting, // Can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .CONNRESET => return error.ConnectionResetByPeer,
else => |err| return unexpectedErrno(err),
}
}
@@ -875,23 +870,23 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
var nwritten: usize = undefined;
switch (wasi.fd_pwrite(fd, &ciovs, ciovs.len, offset, &nwritten)) {
- wasi.ESUCCESS => return nwritten,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
- wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EFBIG => return error.FileTooBig,
- wasi.EIO => return error.InputOutput,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.EPERM => return error.AccessDenied,
- wasi.EPIPE => return error.BrokenPipe,
- wasi.ENXIO => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nwritten,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForWriting, // can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -913,22 +908,22 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
while (true) {
const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForWriting, // Can be a race condition.
- EDESTADDRREQ => unreachable, // `connect` was never called.
- EDQUOT => return error.DiskQuota,
- EFBIG => return error.FileTooBig,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EPERM => return error.AccessDenied,
- EPIPE => return error.BrokenPipe,
- ENXIO => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForWriting, // Can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -954,7 +949,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
/// * Darwin
/// * Windows
///
-/// If `iov.len` is larger than will fit in a `u31`, a partial write will occur.
+/// If `iov.len` is larger than `IOV_MAX`, a partial write will occur.
pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usize {
const have_pwrite_but_not_pwritev = switch (std.Target.current.os.tag) {
.windows, .macos, .ios, .watchos, .tvos, .haiku => true,
@@ -971,23 +966,23 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var nwritten: usize = undefined;
switch (wasi.fd_pwrite(fd, iov.ptr, iov.len, offset, &nwritten)) {
- wasi.ESUCCESS => return nwritten,
- wasi.EINTR => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EFAULT => unreachable,
- wasi.EAGAIN => unreachable,
- wasi.EBADF => return error.NotOpenForWriting, // Can be a race condition.
- wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EFBIG => return error.FileTooBig,
- wasi.EIO => return error.InputOutput,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.EPERM => return error.AccessDenied,
- wasi.EPIPE => return error.BrokenPipe,
- wasi.ENXIO => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return nwritten,
+ .INTR => unreachable,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => unreachable,
+ .BADF => return error.NotOpenForWriting, // Can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -997,27 +992,27 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
else
system.pwritev;
- const iov_count = math.cast(u31, iov.len) catch math.maxInt(u31);
+ const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
while (true) {
const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EAGAIN => return error.WouldBlock,
- EBADF => return error.NotOpenForWriting, // Can be a race condition.
- EDESTADDRREQ => unreachable, // `connect` was never called.
- EDQUOT => return error.DiskQuota,
- EFBIG => return error.FileTooBig,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EPERM => return error.AccessDenied,
- EPIPE => return error.BrokenPipe,
- ENXIO => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .AGAIN => return error.WouldBlock,
+ .BADF => return error.NotOpenForWriting, // Can be a race condition.
+ .DESTADDRREQ => unreachable, // `connect` was never called.
+ .DQUOT => return error.DiskQuota,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .PIPE => return error.BrokenPipe,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -1098,27 +1093,27 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t
while (true) {
const rc = open_sym(file_path, flags, perm);
switch (errno(rc)) {
- 0 => return @intCast(fd_t, rc),
- EINTR => continue,
+ .SUCCESS => return @intCast(fd_t, rc),
+ .INTR => continue,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EACCES => return error.AccessDenied,
- EFBIG => return error.FileTooBig,
- EOVERFLOW => return error.FileTooBig,
- EISDIR => return error.IsDir,
- ELOOP => return error.SymLinkLoop,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENODEV => return error.NoDevice,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- ENOTDIR => return error.NotDir,
- EPERM => return error.AccessDenied,
- EEXIST => return error.PathAlreadyExists,
- EBUSY => return error.DeviceBusy,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ACCES => return error.AccessDenied,
+ .FBIG => return error.FileTooBig,
+ .OVERFLOW => return error.FileTooBig,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NODEV => return error.NoDevice,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .PERM => return error.AccessDenied,
+ .EXIST => return error.PathAlreadyExists,
+ .BUSY => return error.DeviceBusy,
else => |err| return unexpectedErrno(err),
}
}
@@ -1193,28 +1188,28 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags
while (true) {
var fd: fd_t = undefined;
switch (wasi.path_open(dir_fd, lookup_flags, file_path.ptr, file_path.len, oflags, base, inheriting, fdflags, &fd)) {
- wasi.ESUCCESS => return fd,
- wasi.EINTR => continue,
+ .SUCCESS => return fd,
+ .INTR => continue,
- wasi.EFAULT => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EACCES => return error.AccessDenied,
- wasi.EFBIG => return error.FileTooBig,
- wasi.EOVERFLOW => return error.FileTooBig,
- wasi.EISDIR => return error.IsDir,
- wasi.ELOOP => return error.SymLinkLoop,
- wasi.EMFILE => return error.ProcessFdQuotaExceeded,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENFILE => return error.SystemFdQuotaExceeded,
- wasi.ENODEV => return error.NoDevice,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.ENOTDIR => return error.NotDir,
- wasi.EPERM => return error.AccessDenied,
- wasi.EEXIST => return error.PathAlreadyExists,
- wasi.EBUSY => return error.DeviceBusy,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ACCES => return error.AccessDenied,
+ .FBIG => return error.FileTooBig,
+ .OVERFLOW => return error.FileTooBig,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NODEV => return error.NoDevice,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .PERM => return error.AccessDenied,
+ .EXIST => return error.PathAlreadyExists,
+ .BUSY => return error.DeviceBusy,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -1239,30 +1234,30 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
while (true) {
const rc = openat_sym(dir_fd, file_path, flags, mode);
switch (errno(rc)) {
- 0 => return @intCast(fd_t, rc),
- EINTR => continue,
+ .SUCCESS => return @intCast(fd_t, rc),
+ .INTR => continue,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EBADF => unreachable,
- EACCES => return error.AccessDenied,
- EFBIG => return error.FileTooBig,
- EOVERFLOW => return error.FileTooBig,
- EISDIR => return error.IsDir,
- ELOOP => return error.SymLinkLoop,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENODEV => return error.NoDevice,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- ENOTDIR => return error.NotDir,
- EPERM => return error.AccessDenied,
- EEXIST => return error.PathAlreadyExists,
- EBUSY => return error.DeviceBusy,
- EOPNOTSUPP => return error.FileLocksNotSupported,
- EWOULDBLOCK => return error.WouldBlock,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .BADF => unreachable,
+ .ACCES => return error.AccessDenied,
+ .FBIG => return error.FileTooBig,
+ .OVERFLOW => return error.FileTooBig,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NODEV => return error.NoDevice,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .PERM => return error.AccessDenied,
+ .EXIST => return error.PathAlreadyExists,
+ .BUSY => return error.DeviceBusy,
+ .OPNOTSUPP => return error.FileLocksNotSupported,
+ .AGAIN => return error.WouldBlock,
else => |err| return unexpectedErrno(err),
}
}
@@ -1286,9 +1281,9 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)
pub fn dup(old_fd: fd_t) !fd_t {
const rc = system.dup(old_fd);
return switch (errno(rc)) {
- 0 => return @intCast(fd_t, rc),
- EMFILE => error.ProcessFdQuotaExceeded,
- EBADF => unreachable, // invalid file descriptor
+ .SUCCESS => return @intCast(fd_t, rc),
+ .MFILE => error.ProcessFdQuotaExceeded,
+ .BADF => unreachable, // invalid file descriptor
else => |err| return unexpectedErrno(err),
};
}
@@ -1296,11 +1291,11 @@ pub fn dup(old_fd: fd_t) !fd_t {
pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
while (true) {
switch (errno(system.dup2(old_fd, new_fd))) {
- 0 => return,
- EBUSY, EINTR => continue,
- EMFILE => return error.ProcessFdQuotaExceeded,
- EINVAL => unreachable, // invalid parameters passed to dup2
- EBADF => unreachable, // invalid file descriptor
+ .SUCCESS => return,
+ .BUSY, .INTR => continue,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .INVAL => unreachable, // invalid parameters passed to dup2
+ .BADF => unreachable, // invalid file descriptor
else => |err| return unexpectedErrno(err),
}
}
@@ -1331,23 +1326,23 @@ pub fn execveZ(
envp: [*:null]const ?[*:0]const u8,
) ExecveError {
switch (errno(system.execve(path, child_argv, envp))) {
- 0 => unreachable,
- EFAULT => unreachable,
- E2BIG => return error.SystemResources,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENOMEM => return error.SystemResources,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EINVAL => return error.InvalidExe,
- ENOEXEC => return error.InvalidExe,
- EIO => return error.FileSystem,
- ELOOP => return error.FileSystem,
- EISDIR => return error.IsDir,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ETXTBSY => return error.FileBusy,
+ .SUCCESS => unreachable,
+ .FAULT => unreachable,
+ .@"2BIG" => return error.SystemResources,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOMEM => return error.SystemResources,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .INVAL => return error.InvalidExe,
+ .NOEXEC => return error.InvalidExe,
+ .IO => return error.FileSystem,
+ .LOOP => return error.FileSystem,
+ .ISDIR => return error.IsDir,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .TXTBSY => return error.FileBusy,
else => |err| return unexpectedErrno(err),
}
}
@@ -1543,16 +1538,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
}
const err = if (builtin.link_libc) blk: {
- break :blk if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;
+ const c_err = if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;
+ break :blk @intToEnum(E, c_err);
} else blk: {
break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
};
switch (err) {
- 0 => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),
- EFAULT => unreachable,
- EINVAL => unreachable,
- ENOENT => return error.CurrentWorkingDirectoryUnlinked,
- ERANGE => return error.NameTooLong,
+ .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .NOENT => return error.CurrentWorkingDirectoryUnlinked,
+ .RANGE => return error.NameTooLong,
else => return unexpectedErrno(err),
}
}
@@ -1601,21 +1597,21 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
@compileError("symlink is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");
}
switch (errno(system.symlink(target_path, sym_link_path))) {
- 0 => return,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EDQUOT => return error.DiskQuota,
- EEXIST => return error.PathAlreadyExists,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -1644,22 +1640,22 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
/// See also `symlinkat`.
pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {
- wasi.ESUCCESS => {},
- wasi.EFAULT => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EACCES => return error.AccessDenied,
- wasi.EPERM => return error.AccessDenied,
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EEXIST => return error.PathAlreadyExists,
- wasi.EIO => return error.FileSystem,
- wasi.ELOOP => return error.SymLinkLoop,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOTDIR => return error.NotDir,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.EROFS => return error.ReadOnlyFileSystem,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => {},
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -1671,21 +1667,21 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:
@compileError("symlinkat is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");
}
switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) {
- 0 => return,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EDQUOT => return error.DiskQuota,
- EEXIST => return error.PathAlreadyExists,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -1707,22 +1703,22 @@ pub const LinkError = UnexpectedError || error{
pub fn linkZ(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) LinkError!void {
switch (errno(system.link(oldpath, newpath, flags))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EDQUOT => return error.DiskQuota,
- EEXIST => return error.PathAlreadyExists,
- EFAULT => unreachable,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- EMLINK => return error.LinkQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- EPERM => return error.AccessDenied,
- EROFS => return error.ReadOnlyFileSystem,
- EXDEV => return error.NotSameFileSystem,
- EINVAL => unreachable,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .FAULT => unreachable,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .PERM => return error.AccessDenied,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .XDEV => return error.NotSameFileSystem,
+ .INVAL => unreachable,
else => |err| return unexpectedErrno(err),
}
}
@@ -1743,23 +1739,23 @@ pub fn linkatZ(
flags: i32,
) LinkatError!void {
switch (errno(system.linkat(olddir, oldpath, newdir, newpath, flags))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EDQUOT => return error.DiskQuota,
- EEXIST => return error.PathAlreadyExists,
- EFAULT => unreachable,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- EMLINK => return error.LinkQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- ENOTDIR => return error.NotDir,
- EPERM => return error.AccessDenied,
- EROFS => return error.ReadOnlyFileSystem,
- EXDEV => return error.NotSameFileSystem,
- EINVAL => unreachable,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .FAULT => unreachable,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .PERM => return error.AccessDenied,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .XDEV => return error.NotSameFileSystem,
+ .INVAL => unreachable,
else => |err| return unexpectedErrno(err),
}
}
@@ -1822,20 +1818,20 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
return unlinkW(file_path_w.span());
}
switch (errno(system.unlink(file_path))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EBUSY => return error.FileBusy,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EIO => return error.FileSystem,
- EISDIR => return error.IsDir,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ENOMEM => return error.SystemResources,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .IO => return error.FileSystem,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -1875,24 +1871,24 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro
else
wasi.path_unlink_file(dirfd, file_path.ptr, file_path.len);
switch (res) {
- wasi.ESUCCESS => return,
- wasi.EACCES => return error.AccessDenied,
- wasi.EPERM => return error.AccessDenied,
- wasi.EBUSY => return error.FileBusy,
- wasi.EFAULT => unreachable,
- wasi.EIO => return error.FileSystem,
- wasi.EISDIR => return error.IsDir,
- wasi.ELOOP => return error.SymLinkLoop,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOTDIR => return error.NotDir,
- wasi.ENOMEM => return error.SystemResources,
- wasi.EROFS => return error.ReadOnlyFileSystem,
- wasi.ENOTEMPTY => return error.DirNotEmpty,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .FAULT => unreachable,
+ .IO => return error.FileSystem,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .NOTEMPTY => return error.DirNotEmpty,
+ .NOTCAPABLE => return error.AccessDenied,
- wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component
- wasi.EBADF => unreachable, // always a race condition
+ .INVAL => unreachable, // invalid flags, or pathname has . as last component
+ .BADF => unreachable, // always a race condition
else => |err| return unexpectedErrno(err),
}
@@ -1905,23 +1901,23 @@ pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatEr
return unlinkatW(dirfd, file_path_w.span(), flags);
}
switch (errno(system.unlinkat(dirfd, file_path_c, flags))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EBUSY => return error.FileBusy,
- EFAULT => unreachable,
- EIO => return error.FileSystem,
- EISDIR => return error.IsDir,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ENOMEM => return error.SystemResources,
- EROFS => return error.ReadOnlyFileSystem,
- ENOTEMPTY => return error.DirNotEmpty,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .FAULT => unreachable,
+ .IO => return error.FileSystem,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .NOTEMPTY => return error.DirNotEmpty,
- EINVAL => unreachable, // invalid flags, or pathname has . as last component
- EBADF => unreachable, // always a race condition
+ .INVAL => unreachable, // invalid flags, or pathname has . as last component
+ .BADF => unreachable, // always a race condition
else => |err| return unexpectedErrno(err),
}
@@ -1982,25 +1978,25 @@ pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!voi
return renameW(old_path_w.span().ptr, new_path_w.span().ptr);
}
switch (errno(system.rename(old_path, new_path))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EBUSY => return error.FileBusy,
- EDQUOT => return error.DiskQuota,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EISDIR => return error.IsDir,
- ELOOP => return error.SymLinkLoop,
- EMLINK => return error.LinkQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- EEXIST => return error.PathAlreadyExists,
- ENOTEMPTY => return error.PathAlreadyExists,
- EROFS => return error.ReadOnlyFileSystem,
- EXDEV => return error.RenameAcrossMountPoints,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .DQUOT => return error.DiskQuota,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .EXIST => return error.PathAlreadyExists,
+ .NOTEMPTY => return error.PathAlreadyExists,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .XDEV => return error.RenameAcrossMountPoints,
else => |err| return unexpectedErrno(err),
}
}
@@ -2036,26 +2032,26 @@ pub fn renameat(
/// See also `renameat`.
pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void {
switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) {
- wasi.ESUCCESS => return,
- wasi.EACCES => return error.AccessDenied,
- wasi.EPERM => return error.AccessDenied,
- wasi.EBUSY => return error.FileBusy,
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EFAULT => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EISDIR => return error.IsDir,
- wasi.ELOOP => return error.SymLinkLoop,
- wasi.EMLINK => return error.LinkQuotaExceeded,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOTDIR => return error.NotDir,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.EEXIST => return error.PathAlreadyExists,
- wasi.ENOTEMPTY => return error.PathAlreadyExists,
- wasi.EROFS => return error.ReadOnlyFileSystem,
- wasi.EXDEV => return error.RenameAcrossMountPoints,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .DQUOT => return error.DiskQuota,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .EXIST => return error.PathAlreadyExists,
+ .NOTEMPTY => return error.PathAlreadyExists,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .XDEV => return error.RenameAcrossMountPoints,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -2074,25 +2070,25 @@ pub fn renameatZ(
}
switch (errno(system.renameat(old_dir_fd, old_path, new_dir_fd, new_path))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EBUSY => return error.FileBusy,
- EDQUOT => return error.DiskQuota,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EISDIR => return error.IsDir,
- ELOOP => return error.SymLinkLoop,
- EMLINK => return error.LinkQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- EEXIST => return error.PathAlreadyExists,
- ENOTEMPTY => return error.PathAlreadyExists,
- EROFS => return error.ReadOnlyFileSystem,
- EXDEV => return error.RenameAcrossMountPoints,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .DQUOT => return error.DiskQuota,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ISDIR => return error.IsDir,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .EXIST => return error.PathAlreadyExists,
+ .NOTEMPTY => return error.PathAlreadyExists,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .XDEV => return error.RenameAcrossMountPoints,
else => |err| return unexpectedErrno(err),
}
}
@@ -2172,22 +2168,22 @@ pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
_ = mode;
switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
- wasi.ESUCCESS => return,
- wasi.EACCES => return error.AccessDenied,
- wasi.EBADF => unreachable,
- wasi.EPERM => return error.AccessDenied,
- wasi.EDQUOT => return error.DiskQuota,
- wasi.EEXIST => return error.PathAlreadyExists,
- wasi.EFAULT => unreachable,
- wasi.ELOOP => return error.SymLinkLoop,
- wasi.EMLINK => return error.LinkQuotaExceeded,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENOSPC => return error.NoSpaceLeft,
- wasi.ENOTDIR => return error.NotDir,
- wasi.EROFS => return error.ReadOnlyFileSystem,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .BADF => unreachable,
+ .PERM => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .FAULT => unreachable,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -2198,21 +2194,21 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr
return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
}
switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EBADF => unreachable,
- EPERM => return error.AccessDenied,
- EDQUOT => return error.DiskQuota,
- EEXIST => return error.PathAlreadyExists,
- EFAULT => unreachable,
- ELOOP => return error.SymLinkLoop,
- EMLINK => return error.LinkQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- ENOTDIR => return error.NotDir,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .BADF => unreachable,
+ .PERM => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .FAULT => unreachable,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -2274,20 +2270,20 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
return mkdirW(dir_path_w.span(), mode);
}
switch (errno(system.mkdir(dir_path, mode))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EDQUOT => return error.DiskQuota,
- EEXIST => return error.PathAlreadyExists,
- EFAULT => unreachable,
- ELOOP => return error.SymLinkLoop,
- EMLINK => return error.LinkQuotaExceeded,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.NoSpaceLeft,
- ENOTDIR => return error.NotDir,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .DQUOT => return error.DiskQuota,
+ .EXIST => return error.PathAlreadyExists,
+ .FAULT => unreachable,
+ .LOOP => return error.SymLinkLoop,
+ .MLINK => return error.LinkQuotaExceeded,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.NoSpaceLeft,
+ .NOTDIR => return error.NotDir,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -2346,20 +2342,20 @@ pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
return rmdirW(dir_path_w.span());
}
switch (errno(system.rmdir(dir_path))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EBUSY => return error.FileBusy,
- EFAULT => unreachable,
- EINVAL => unreachable,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOTDIR => return error.NotDir,
- EEXIST => return error.DirNotEmpty,
- ENOTEMPTY => return error.DirNotEmpty,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .BUSY => return error.FileBusy,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOTDIR => return error.NotDir,
+ .EXIST => return error.DirNotEmpty,
+ .NOTEMPTY => return error.DirNotEmpty,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -2413,15 +2409,15 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
return chdirW(utf16_dir_path[0..len]);
}
switch (errno(system.chdir(dir_path))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EFAULT => unreachable,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOTDIR => return error.NotDir,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .FAULT => unreachable,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOTDIR => return error.NotDir,
else => |err| return unexpectedErrno(err),
}
}
@@ -2443,12 +2439,12 @@ pub const FchdirError = error{
pub fn fchdir(dirfd: fd_t) FchdirError!void {
while (true) {
switch (errno(system.fchdir(dirfd))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EBADF => unreachable,
- ENOTDIR => return error.NotDir,
- EINTR => continue,
- EIO => return error.FileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .BADF => unreachable,
+ .NOTDIR => return error.NotDir,
+ .INTR => continue,
+ .IO => return error.FileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -2501,16 +2497,16 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
}
const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);
switch (errno(rc)) {
- 0 => return out_buffer[0..@bitCast(usize, rc)],
- EACCES => return error.AccessDenied,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOTDIR => return error.NotDir,
+ .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
+ .ACCES => return error.AccessDenied,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOTDIR => return error.NotDir,
else => |err| return unexpectedErrno(err),
}
}
@@ -2537,17 +2533,17 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
var bufused: usize = undefined;
switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) {
- wasi.ESUCCESS => return out_buffer[0..bufused],
- wasi.EACCES => return error.AccessDenied,
- wasi.EFAULT => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EIO => return error.FileSystem,
- wasi.ELOOP => return error.SymLinkLoop,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOMEM => return error.SystemResources,
- wasi.ENOTDIR => return error.NotDir,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return out_buffer[0..bufused],
+ .ACCES => return error.AccessDenied,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOTDIR => return error.NotDir,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -2567,16 +2563,16 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
}
const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);
switch (errno(rc)) {
- 0 => return out_buffer[0..@bitCast(usize, rc)],
- EACCES => return error.AccessDenied,
- EFAULT => unreachable,
- EINVAL => unreachable,
- EIO => return error.FileSystem,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOTDIR => return error.NotDir,
+ .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
+ .ACCES => return error.AccessDenied,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .IO => return error.FileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOTDIR => return error.NotDir,
else => |err| return unexpectedErrno(err),
}
}
@@ -2590,58 +2586,58 @@ pub const SetIdError = error{ResourceLimitReached} || SetEidError;
pub fn setuid(uid: uid_t) SetIdError!void {
switch (errno(system.setuid(uid))) {
- 0 => return,
- EAGAIN => return error.ResourceLimitReached,
- EINVAL => return error.InvalidUserId,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .AGAIN => return error.ResourceLimitReached,
+ .INVAL => return error.InvalidUserId,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
pub fn seteuid(uid: uid_t) SetEidError!void {
switch (errno(system.seteuid(uid))) {
- 0 => return,
- EINVAL => return error.InvalidUserId,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .INVAL => return error.InvalidUserId,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void {
switch (errno(system.setreuid(ruid, euid))) {
- 0 => return,
- EAGAIN => return error.ResourceLimitReached,
- EINVAL => return error.InvalidUserId,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .AGAIN => return error.ResourceLimitReached,
+ .INVAL => return error.InvalidUserId,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
pub fn setgid(gid: gid_t) SetIdError!void {
switch (errno(system.setgid(gid))) {
- 0 => return,
- EAGAIN => return error.ResourceLimitReached,
- EINVAL => return error.InvalidUserId,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .AGAIN => return error.ResourceLimitReached,
+ .INVAL => return error.InvalidUserId,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
pub fn setegid(uid: uid_t) SetEidError!void {
switch (errno(system.setegid(uid))) {
- 0 => return,
- EINVAL => return error.InvalidUserId,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .INVAL => return error.InvalidUserId,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void {
switch (errno(system.setregid(rgid, egid))) {
- 0 => return,
- EAGAIN => return error.ResourceLimitReached,
- EINVAL => return error.InvalidUserId,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .AGAIN => return error.ResourceLimitReached,
+ .INVAL => return error.InvalidUserId,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -2680,9 +2676,10 @@ pub fn isatty(handle: fd_t) bool {
while (true) {
var wsz: linux.winsize = undefined;
const fd = @bitCast(usize, @as(isize, handle));
- switch (linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz))) {
- 0 => return true,
- EINTR => continue,
+ const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz));
+ switch (linux.getErrno(rc)) {
+ .SUCCESS => return true,
+ .INTR => continue,
else => return false,
}
}
@@ -2777,22 +2774,22 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
socket_type;
const rc = system.socket(domain, filtered_sock_type, protocol);
switch (errno(rc)) {
- 0 => {
+ .SUCCESS => {
const fd = @intCast(fd_t, rc);
if (!have_sock_flags) {
try setSockFlags(fd, socket_type);
}
return fd;
},
- EACCES => return error.PermissionDenied,
- EAFNOSUPPORT => return error.AddressFamilyNotSupported,
- EINVAL => return error.ProtocolFamilyNotAvailable,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- EPROTONOSUPPORT => return error.ProtocolNotSupported,
- EPROTOTYPE => return error.SocketTypeNotSupported,
+ .ACCES => return error.PermissionDenied,
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
+ .INVAL => return error.ProtocolFamilyNotAvailable,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .PROTONOSUPPORT => return error.ProtocolNotSupported,
+ .PROTOTYPE => return error.SocketTypeNotSupported,
else => |err| return unexpectedErrno(err),
}
}
@@ -2840,12 +2837,12 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
.both => SHUT_RDWR,
});
switch (errno(rc)) {
- 0 => return,
- EBADF => unreachable,
- EINVAL => unreachable,
- ENOTCONN => return error.SocketNotConnected,
- ENOTSOCK => unreachable,
- ENOBUFS => return error.SystemResources,
+ .SUCCESS => return,
+ .BADF => unreachable,
+ .INVAL => unreachable,
+ .NOTCONN => return error.SocketNotConnected,
+ .NOTSOCK => unreachable,
+ .NOBUFS => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -2924,20 +2921,20 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
} else {
const rc = system.bind(sock, addr, len);
switch (errno(rc)) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EADDRINUSE => return error.AddressInUse,
- EBADF => unreachable, // always a race condition if this error is returned
- EINVAL => unreachable, // invalid parameters
- ENOTSOCK => unreachable, // invalid `sockfd`
- EADDRNOTAVAIL => return error.AddressNotAvailable,
- EFAULT => unreachable, // invalid `addr` pointer
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOTDIR => return error.NotDir,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .ADDRINUSE => return error.AddressInUse,
+ .BADF => unreachable, // always a race condition if this error is returned
+ .INVAL => unreachable, // invalid parameters
+ .NOTSOCK => unreachable, // invalid `sockfd`
+ .ADDRNOTAVAIL => return error.AddressNotAvailable,
+ .FAULT => unreachable, // invalid `addr` pointer
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOTDIR => return error.NotDir,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -2993,11 +2990,11 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void {
} else {
const rc = system.listen(sock, backlog);
switch (errno(rc)) {
- 0 => return,
- EADDRINUSE => return error.AddressInUse,
- EBADF => unreachable,
- ENOTSOCK => return error.FileDescriptorNotASocket,
- EOPNOTSUPP => return error.OperationNotSupported,
+ .SUCCESS => return,
+ .ADDRINUSE => return error.AddressInUse,
+ .BADF => unreachable,
+ .NOTSOCK => return error.FileDescriptorNotASocket,
+ .OPNOTSUPP => return error.OperationNotSupported,
else => |err| return unexpectedErrno(err),
}
}
@@ -3099,23 +3096,23 @@ pub fn accept(
}
} else {
switch (errno(rc)) {
- 0 => {
+ .SUCCESS => {
break @intCast(socket_t, rc);
},
- EINTR => continue,
- EAGAIN => return error.WouldBlock,
- EBADF => unreachable, // always a race condition
- ECONNABORTED => return error.ConnectionAborted,
- EFAULT => unreachable,
- EINVAL => return error.SocketNotListening,
- ENOTSOCK => unreachable,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- EOPNOTSUPP => unreachable,
- EPROTO => return error.ProtocolFailure,
- EPERM => return error.BlockedByFirewall,
+ .INTR => continue,
+ .AGAIN => return error.WouldBlock,
+ .BADF => unreachable, // always a race condition
+ .CONNABORTED => return error.ConnectionAborted,
+ .FAULT => unreachable,
+ .INVAL => return error.SocketNotListening,
+ .NOTSOCK => unreachable,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .OPNOTSUPP => unreachable,
+ .PROTO => return error.ProtocolFailure,
+ .PERM => return error.BlockedByFirewall,
else => |err| return unexpectedErrno(err),
}
}
@@ -3144,13 +3141,13 @@ pub const EpollCreateError = error{
pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
const rc = system.epoll_create1(flags);
switch (errno(rc)) {
- 0 => return @intCast(i32, rc),
+ .SUCCESS => return @intCast(i32, rc),
else => |err| return unexpectedErrno(err),
- EINVAL => unreachable,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENOMEM => return error.SystemResources,
+ .INVAL => unreachable,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOMEM => return error.SystemResources,
}
}
@@ -3183,17 +3180,17 @@ pub const EpollCtlError = error{
pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
const rc = system.epoll_ctl(epfd, op, fd, event);
switch (errno(rc)) {
- 0 => return,
+ .SUCCESS => return,
else => |err| return unexpectedErrno(err),
- EBADF => unreachable, // always a race condition if this happens
- EEXIST => return error.FileDescriptorAlreadyPresentInSet,
- EINVAL => unreachable,
- ELOOP => return error.OperationCausesCircularLoop,
- ENOENT => return error.FileDescriptorNotRegistered,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.UserResourceLimitReached,
- EPERM => return error.FileDescriptorIncompatibleWithEpoll,
+ .BADF => unreachable, // always a race condition if this happens
+ .EXIST => return error.FileDescriptorAlreadyPresentInSet,
+ .INVAL => unreachable,
+ .LOOP => return error.OperationCausesCircularLoop,
+ .NOENT => return error.FileDescriptorNotRegistered,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.UserResourceLimitReached,
+ .PERM => return error.FileDescriptorIncompatibleWithEpoll,
}
}
@@ -3205,11 +3202,11 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {
// TODO get rid of the @intCast
const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EBADF => unreachable,
- EFAULT => unreachable,
- EINVAL => unreachable,
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .BADF => unreachable,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
else => unreachable,
}
}
@@ -3224,14 +3221,14 @@ pub const EventFdError = error{
pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
const rc = system.eventfd(initval, flags);
switch (errno(rc)) {
- 0 => return @intCast(i32, rc),
+ .SUCCESS => return @intCast(i32, rc),
else => |err| return unexpectedErrno(err),
- EINVAL => unreachable, // invalid parameters
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENODEV => return error.SystemResources,
- ENOMEM => return error.SystemResources,
+ .INVAL => unreachable, // invalid parameters
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NODEV => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
}
}
@@ -3265,14 +3262,14 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
} else {
const rc = system.getsockname(sock, addr, addrlen);
switch (errno(rc)) {
- 0 => return,
+ .SUCCESS => return,
else => |err| return unexpectedErrno(err),
- EBADF => unreachable, // always a race condition
- EFAULT => unreachable,
- EINVAL => unreachable, // invalid parameters
- ENOTSOCK => return error.FileDescriptorNotASocket,
- ENOBUFS => return error.SystemResources,
+ .BADF => unreachable, // always a race condition
+ .FAULT => unreachable,
+ .INVAL => unreachable, // invalid parameters
+ .NOTSOCK => return error.FileDescriptorNotASocket,
+ .NOBUFS => return error.SystemResources,
}
}
}
@@ -3294,14 +3291,14 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
} else {
const rc = system.getpeername(sock, addr, addrlen);
switch (errno(rc)) {
- 0 => return,
+ .SUCCESS => return,
else => |err| return unexpectedErrno(err),
- EBADF => unreachable, // always a race condition
- EFAULT => unreachable,
- EINVAL => unreachable, // invalid parameters
- ENOTSOCK => return error.FileDescriptorNotASocket,
- ENOBUFS => return error.SystemResources,
+ .BADF => unreachable, // always a race condition
+ .FAULT => unreachable,
+ .INVAL => unreachable, // invalid parameters
+ .NOTSOCK => return error.FileDescriptorNotASocket,
+ .NOBUFS => return error.SystemResources,
}
}
}
@@ -3384,61 +3381,61 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
while (true) {
switch (errno(system.connect(sock, sock_addr, len))) {
- 0 => return,
- EACCES => return error.PermissionDenied,
- EPERM => return error.PermissionDenied,
- EADDRINUSE => return error.AddressInUse,
- EADDRNOTAVAIL => return error.AddressNotAvailable,
- EAFNOSUPPORT => return error.AddressFamilyNotSupported,
- EAGAIN, EINPROGRESS => return error.WouldBlock,
- EALREADY => return error.ConnectionPending,
- EBADF => unreachable, // sockfd is not a valid open file descriptor.
- ECONNREFUSED => return error.ConnectionRefused,
- ECONNRESET => return error.ConnectionResetByPeer,
- EFAULT => unreachable, // The socket structure address is outside the user's address space.
- EINTR => continue,
- EISCONN => unreachable, // The socket is already connected.
- ENETUNREACH => return error.NetworkUnreachable,
- ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
- ETIMEDOUT => return error.ConnectionTimedOut,
- ENOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
+ .SUCCESS => return,
+ .ACCES => return error.PermissionDenied,
+ .PERM => return error.PermissionDenied,
+ .ADDRINUSE => return error.AddressInUse,
+ .ADDRNOTAVAIL => return error.AddressNotAvailable,
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
+ .AGAIN, .INPROGRESS => return error.WouldBlock,
+ .ALREADY => return error.ConnectionPending,
+ .BADF => unreachable, // sockfd is not a valid open file descriptor.
+ .CONNREFUSED => return error.ConnectionRefused,
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .FAULT => unreachable, // The socket structure address is outside the user's address space.
+ .INTR => continue,
+ .ISCONN => unreachable, // The socket is already connected.
+ .NETUNREACH => return error.NetworkUnreachable,
+ .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
+ .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
+ .TIMEDOUT => return error.ConnectionTimedOut,
+ .NOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
else => |err| return unexpectedErrno(err),
}
}
}
pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
- var err_code: u32 = undefined;
+ var err_code: i32 = undefined;
var size: u32 = @sizeOf(u32);
const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);
assert(size == 4);
switch (errno(rc)) {
- 0 => switch (err_code) {
- 0 => return,
- EACCES => return error.PermissionDenied,
- EPERM => return error.PermissionDenied,
- EADDRINUSE => return error.AddressInUse,
- EADDRNOTAVAIL => return error.AddressNotAvailable,
- EAFNOSUPPORT => return error.AddressFamilyNotSupported,
- EAGAIN => return error.SystemResources,
- EALREADY => return error.ConnectionPending,
- EBADF => unreachable, // sockfd is not a valid open file descriptor.
- ECONNREFUSED => return error.ConnectionRefused,
- EFAULT => unreachable, // The socket structure address is outside the user's address space.
- EISCONN => unreachable, // The socket is already connected.
- ENETUNREACH => return error.NetworkUnreachable,
- ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
- ETIMEDOUT => return error.ConnectionTimedOut,
- ECONNRESET => return error.ConnectionResetByPeer,
+ .SUCCESS => switch (@intToEnum(E, err_code)) {
+ .SUCCESS => return,
+ .ACCES => return error.PermissionDenied,
+ .PERM => return error.PermissionDenied,
+ .ADDRINUSE => return error.AddressInUse,
+ .ADDRNOTAVAIL => return error.AddressNotAvailable,
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
+ .AGAIN => return error.SystemResources,
+ .ALREADY => return error.ConnectionPending,
+ .BADF => unreachable, // sockfd is not a valid open file descriptor.
+ .CONNREFUSED => return error.ConnectionRefused,
+ .FAULT => unreachable, // The socket structure address is outside the user's address space.
+ .ISCONN => unreachable, // The socket is already connected.
+ .NETUNREACH => return error.NetworkUnreachable,
+ .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
+ .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
+ .TIMEDOUT => return error.ConnectionTimedOut,
+ .CONNRESET => return error.ConnectionResetByPeer,
else => |err| return unexpectedErrno(err),
},
- EBADF => unreachable, // The argument sockfd is not a valid file descriptor.
- EFAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
- EINVAL => unreachable,
- ENOPROTOOPT => unreachable, // The option is unknown at the level indicated.
- ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
+ .BADF => unreachable, // The argument sockfd is not a valid file descriptor.
+ .FAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
+ .INVAL => unreachable,
+ .NOPROTOOPT => unreachable, // The option is unknown at the level indicated.
+ .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
else => |err| return unexpectedErrno(err),
}
}
@@ -3454,13 +3451,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
while (true) {
const rc = system.waitpid(pid, &status, if (builtin.link_libc) @intCast(c_int, flags) else flags);
switch (errno(rc)) {
- 0 => return .{
+ .SUCCESS => return .{
.pid = @intCast(pid_t, rc),
.status = @bitCast(u32, status),
},
- EINTR => continue,
- ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
- EINVAL => unreachable, // Invalid flags.
+ .INTR => continue,
+ .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
+ .INVAL => unreachable, // Invalid flags.
else => unreachable,
}
}
@@ -3484,12 +3481,12 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var stat: wasi.filestat_t = undefined;
switch (wasi.fd_filestat_get(fd, &stat)) {
- wasi.ESUCCESS => return Stat.fromFilestat(stat),
- wasi.EINVAL => unreachable,
- wasi.EBADF => unreachable, // Always a race condition.
- wasi.ENOMEM => return error.SystemResources,
- wasi.EACCES => return error.AccessDenied,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return Stat.fromFilestat(stat),
+ .INVAL => unreachable,
+ .BADF => unreachable, // Always a race condition.
+ .NOMEM => return error.SystemResources,
+ .ACCES => return error.AccessDenied,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3504,11 +3501,11 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
var stat = mem.zeroes(Stat);
switch (errno(fstat_sym(fd, &stat))) {
- 0 => return stat,
- EINVAL => unreachable,
- EBADF => unreachable, // Always a race condition.
- ENOMEM => return error.SystemResources,
- EACCES => return error.AccessDenied,
+ .SUCCESS => return stat,
+ .INVAL => unreachable,
+ .BADF => unreachable, // Always a race condition.
+ .NOMEM => return error.SystemResources,
+ .ACCES => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3536,16 +3533,16 @@ pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
var stat: wasi.filestat_t = undefined;
switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
- wasi.ESUCCESS => return Stat.fromFilestat(stat),
- wasi.EINVAL => unreachable,
- wasi.EBADF => unreachable, // Always a race condition.
- wasi.ENOMEM => return error.SystemResources,
- wasi.EACCES => return error.AccessDenied,
- wasi.EFAULT => unreachable,
- wasi.ENAMETOOLONG => return error.NameTooLong,
- wasi.ENOENT => return error.FileNotFound,
- wasi.ENOTDIR => return error.FileNotFound,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return Stat.fromFilestat(stat),
+ .INVAL => unreachable,
+ .BADF => unreachable, // Always a race condition.
+ .NOMEM => return error.SystemResources,
+ .ACCES => return error.AccessDenied,
+ .FAULT => unreachable,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.FileNotFound,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3560,17 +3557,17 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
var stat = mem.zeroes(Stat);
switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {
- 0 => return stat,
- EINVAL => unreachable,
- EBADF => unreachable, // Always a race condition.
- ENOMEM => return error.SystemResources,
- EACCES => return error.AccessDenied,
- EPERM => return error.AccessDenied,
- EFAULT => unreachable,
- ENAMETOOLONG => return error.NameTooLong,
- ELOOP => return error.SymLinkLoop,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.FileNotFound,
+ .SUCCESS => return stat,
+ .INVAL => unreachable,
+ .BADF => unreachable, // Always a race condition.
+ .NOMEM => return error.SystemResources,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.AccessDenied,
+ .FAULT => unreachable,
+ .NAMETOOLONG => return error.NameTooLong,
+ .LOOP => return error.SymLinkLoop,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.FileNotFound,
else => |err| return unexpectedErrno(err),
}
}
@@ -3586,9 +3583,9 @@ pub const KQueueError = error{
pub fn kqueue() KQueueError!i32 {
const rc = system.kqueue();
switch (errno(rc)) {
- 0 => return @intCast(i32, rc),
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENFILE => return error.SystemFdQuotaExceeded,
+ .SUCCESS => return @intCast(i32, rc),
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
else => |err| return unexpectedErrno(err),
}
}
@@ -3627,15 +3624,15 @@ pub fn kevent(
timeout,
);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EACCES => return error.AccessDenied,
- EFAULT => unreachable,
- EBADF => unreachable, // Always a race condition.
- EINTR => continue,
- EINVAL => unreachable,
- ENOENT => return error.EventNotFound,
- ENOMEM => return error.SystemResources,
- ESRCH => return error.ProcessNotFound,
+ .SUCCESS => return @intCast(usize, rc),
+ .ACCES => return error.AccessDenied,
+ .FAULT => unreachable,
+ .BADF => unreachable, // Always a race condition.
+ .INTR => continue,
+ .INVAL => unreachable,
+ .NOENT => return error.EventNotFound,
+ .NOMEM => return error.SystemResources,
+ .SRCH => return error.ProcessNotFound,
else => unreachable,
}
}
@@ -3651,11 +3648,11 @@ pub const INotifyInitError = error{
pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
const rc = system.inotify_init1(flags);
switch (errno(rc)) {
- 0 => return @intCast(i32, rc),
- EINVAL => unreachable,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return @intCast(i32, rc),
+ .INVAL => unreachable,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -3681,16 +3678,16 @@ pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add
pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
switch (errno(rc)) {
- 0 => return @intCast(i32, rc),
- EACCES => return error.AccessDenied,
- EBADF => unreachable,
- EFAULT => unreachable,
- EINVAL => unreachable,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOMEM => return error.SystemResources,
- ENOSPC => return error.UserResourceLimitReached,
- ENOTDIR => return error.NotDir,
+ .SUCCESS => return @intCast(i32, rc),
+ .ACCES => return error.AccessDenied,
+ .BADF => unreachable,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ .NOSPC => return error.UserResourceLimitReached,
+ .NOTDIR => return error.NotDir,
else => |err| return unexpectedErrno(err),
}
}
@@ -3698,9 +3695,9 @@ pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) I
/// remove an existing watch from an inotify instance
pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void {
switch (errno(system.inotify_rm_watch(inotify_fd, wd))) {
- 0 => return,
- EBADF => unreachable,
- EINVAL => unreachable,
+ .SUCCESS => return,
+ .BADF => unreachable,
+ .INVAL => unreachable,
else => unreachable,
}
}
@@ -3723,10 +3720,10 @@ pub const MProtectError = error{
pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {
assert(mem.isAligned(memory.len, mem.page_size));
switch (errno(system.mprotect(memory.ptr, memory.len, protection))) {
- 0 => return,
- EINVAL => unreachable,
- EACCES => return error.AccessDenied,
- ENOMEM => return error.OutOfMemory,
+ .SUCCESS => return,
+ .INVAL => unreachable,
+ .ACCES => return error.AccessDenied,
+ .NOMEM => return error.OutOfMemory,
else => |err| return unexpectedErrno(err),
}
}
@@ -3736,9 +3733,9 @@ pub const ForkError = error{SystemResources} || UnexpectedError;
pub fn fork() ForkError!pid_t {
const rc = system.fork();
switch (errno(rc)) {
- 0 => return @intCast(pid_t, rc),
- EAGAIN => return error.SystemResources,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return @intCast(pid_t, rc),
+ .AGAIN => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -3782,22 +3779,23 @@ pub fn mmap(
const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
const err = if (builtin.link_libc) blk: {
if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
- break :blk system._errno().*;
+ break :blk @intToEnum(E, system._errno().*);
} else blk: {
const err = errno(rc);
- if (err == 0) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length];
+ if (err == .SUCCESS) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length];
break :blk err;
};
switch (err) {
- ETXTBSY => return error.AccessDenied,
- EACCES => return error.AccessDenied,
- EPERM => return error.PermissionDenied,
- EAGAIN => return error.LockedMemoryLimitExceeded,
- EBADF => unreachable, // Always a race condition.
- EOVERFLOW => unreachable, // The number of pages used for length + offset would overflow.
- ENODEV => return error.MemoryMappingNotSupported,
- EINVAL => unreachable, // Invalid parameters to mmap()
- ENOMEM => return error.OutOfMemory,
+ .SUCCESS => unreachable,
+ .TXTBSY => return error.AccessDenied,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.PermissionDenied,
+ .AGAIN => return error.LockedMemoryLimitExceeded,
+ .BADF => unreachable, // Always a race condition.
+ .OVERFLOW => unreachable, // The number of pages used for length + offset would overflow.
+ .NODEV => return error.MemoryMappingNotSupported,
+ .INVAL => unreachable, // Invalid parameters to mmap()
+ .NOMEM => return error.OutOfMemory,
else => return unexpectedErrno(err),
}
}
@@ -3810,9 +3808,9 @@ pub fn mmap(
/// * The Windows function, VirtualFree, has this restriction.
pub fn munmap(memory: []align(mem.page_size) const u8) void {
switch (errno(system.munmap(memory.ptr, memory.len))) {
- 0 => return,
- EINVAL => unreachable, // Invalid parameters.
- ENOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.
+ .SUCCESS => return,
+ .INVAL => unreachable, // Invalid parameters.
+ .NOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.
else => unreachable,
}
}
@@ -3854,18 +3852,18 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
return;
}
switch (errno(system.access(path, mode))) {
- 0 => return,
- EACCES => return error.PermissionDenied,
- EROFS => return error.ReadOnlyFileSystem,
- ELOOP => return error.SymLinkLoop,
- ETXTBSY => return error.FileBusy,
- ENOTDIR => return error.FileNotFound,
- ENOENT => return error.FileNotFound,
- ENAMETOOLONG => return error.NameTooLong,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EIO => return error.InputOutput,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return,
+ .ACCES => return error.PermissionDenied,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .TXTBSY => return error.FileBusy,
+ .NOTDIR => return error.FileNotFound,
+ .NOENT => return error.FileNotFound,
+ .NAMETOOLONG => return error.NameTooLong,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .IO => return error.InputOutput,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -3905,18 +3903,18 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
return faccessatW(dirfd, path_w.span().ptr, mode, flags);
}
switch (errno(system.faccessat(dirfd, path, mode, flags))) {
- 0 => return,
- EACCES => return error.PermissionDenied,
- EROFS => return error.ReadOnlyFileSystem,
- ELOOP => return error.SymLinkLoop,
- ETXTBSY => return error.FileBusy,
- ENOTDIR => return error.FileNotFound,
- ENOENT => return error.FileNotFound,
- ENAMETOOLONG => return error.NameTooLong,
- EINVAL => unreachable,
- EFAULT => unreachable,
- EIO => return error.InputOutput,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return,
+ .ACCES => return error.PermissionDenied,
+ .ROFS => return error.ReadOnlyFileSystem,
+ .LOOP => return error.SymLinkLoop,
+ .TXTBSY => return error.FileBusy,
+ .NOTDIR => return error.FileNotFound,
+ .NOENT => return error.FileNotFound,
+ .NAMETOOLONG => return error.NameTooLong,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .IO => return error.InputOutput,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -3972,11 +3970,11 @@ pub const PipeError = error{
pub fn pipe() PipeError![2]fd_t {
var fds: [2]fd_t = undefined;
switch (errno(system.pipe(&fds))) {
- 0 => return fds,
- EINVAL => unreachable, // Invalid parameters to pipe()
- EFAULT => unreachable, // Invalid fds pointer
- ENFILE => return error.SystemFdQuotaExceeded,
- EMFILE => return error.ProcessFdQuotaExceeded,
+ .SUCCESS => return fds,
+ .INVAL => unreachable, // Invalid parameters to pipe()
+ .FAULT => unreachable, // Invalid fds pointer
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .MFILE => return error.ProcessFdQuotaExceeded,
else => |err| return unexpectedErrno(err),
}
}
@@ -3985,11 +3983,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
if (@hasDecl(system, "pipe2")) {
var fds: [2]fd_t = undefined;
switch (errno(system.pipe2(&fds, flags))) {
- 0 => return fds,
- EINVAL => unreachable, // Invalid flags
- EFAULT => unreachable, // Invalid fds pointer
- ENFILE => return error.SystemFdQuotaExceeded,
- EMFILE => return error.ProcessFdQuotaExceeded,
+ .SUCCESS => return fds,
+ .INVAL => unreachable, // Invalid flags
+ .FAULT => unreachable, // Invalid fds pointer
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .MFILE => return error.ProcessFdQuotaExceeded,
else => |err| return unexpectedErrno(err),
}
}
@@ -4008,9 +4006,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
if (flags & O_CLOEXEC != 0) {
for (fds) |fd| {
switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) {
- 0 => {},
- EINVAL => unreachable, // Invalid flags
- EBADF => unreachable, // Always a race condition
+ .SUCCESS => {},
+ .INVAL => unreachable, // Invalid flags
+ .BADF => unreachable, // Always a race condition
else => |err| return unexpectedErrno(err),
}
}
@@ -4021,9 +4019,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
if (new_flags != 0) {
for (fds) |fd| {
switch (errno(system.fcntl(fd, F_SETFL, new_flags))) {
- 0 => {},
- EINVAL => unreachable, // Invalid flags
- EBADF => unreachable, // Always a race condition
+ .SUCCESS => {},
+ .INVAL => unreachable, // Invalid flags
+ .BADF => unreachable, // Always a race condition
else => |err| return unexpectedErrno(err),
}
}
@@ -4055,11 +4053,11 @@ pub fn sysctl(
const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong;
switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) {
- 0 => return,
- EFAULT => unreachable,
- EPERM => return error.PermissionDenied,
- ENOMEM => return error.SystemResources,
- ENOENT => return error.UnknownName,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .PERM => return error.PermissionDenied,
+ .NOMEM => return error.SystemResources,
+ .NOENT => return error.UnknownName,
else => |err| return unexpectedErrno(err),
}
}
@@ -4081,19 +4079,19 @@ pub fn sysctlbynameZ(
}
switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {
- 0 => return,
- EFAULT => unreachable,
- EPERM => return error.PermissionDenied,
- ENOMEM => return error.SystemResources,
- ENOENT => return error.UnknownName,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .PERM => return error.PermissionDenied,
+ .NOMEM => return error.SystemResources,
+ .NOENT => return error.UnknownName,
else => |err| return unexpectedErrno(err),
}
}
pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
switch (errno(system.gettimeofday(tv, tz))) {
- 0 => return,
- EINVAL => unreachable,
+ .SUCCESS => return,
+ .INVAL => unreachable,
else => unreachable,
}
}
@@ -4111,12 +4109,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
var result: u64 = undefined;
switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {
- 0 => return,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4126,13 +4124,13 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var new_offset: wasi.filesize_t = undefined;
switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) {
- wasi.ESUCCESS => return,
- wasi.EBADF => unreachable, // always a race condition
- wasi.EINVAL => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.ENXIO => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4144,12 +4142,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) {
- 0 => return,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4159,12 +4157,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
var result: u64 = undefined;
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {
- 0 => return,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4174,13 +4172,13 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var new_offset: wasi.filesize_t = undefined;
switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) {
- wasi.ESUCCESS => return,
- wasi.EBADF => unreachable, // always a race condition
- wasi.EINVAL => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.ENXIO => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4191,12 +4189,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) {
- 0 => return,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4206,12 +4204,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
var result: u64 = undefined;
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {
- 0 => return,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4221,13 +4219,13 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var new_offset: wasi.filesize_t = undefined;
switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) {
- wasi.ESUCCESS => return,
- wasi.EBADF => unreachable, // always a race condition
- wasi.EINVAL => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.ENXIO => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4238,12 +4236,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
switch (errno(lseek_sym(fd, ioffset, SEEK_END))) {
- 0 => return,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4253,12 +4251,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
var result: u64 = undefined;
switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {
- 0 => return result,
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return result,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4268,13 +4266,13 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var new_offset: wasi.filesize_t = undefined;
switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) {
- wasi.ESUCCESS => return new_offset,
- wasi.EBADF => unreachable, // always a race condition
- wasi.EINVAL => return error.Unseekable,
- wasi.EOVERFLOW => return error.Unseekable,
- wasi.ESPIPE => return error.Unseekable,
- wasi.ENXIO => return error.Unseekable,
- wasi.ENOTCAPABLE => return error.AccessDenied,
+ .SUCCESS => return new_offset,
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
+ .NOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4285,12 +4283,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
const rc = lseek_sym(fd, 0, SEEK_CUR);
switch (errno(rc)) {
- 0 => return @bitCast(u64, rc),
- EBADF => unreachable, // always a race condition
- EINVAL => return error.Unseekable,
- EOVERFLOW => return error.Unseekable,
- ESPIPE => return error.Unseekable,
- ENXIO => return error.Unseekable,
+ .SUCCESS => return @bitCast(u64, rc),
+ .BADF => unreachable, // always a race condition
+ .INVAL => return error.Unseekable,
+ .OVERFLOW => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
+ .NXIO => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}
@@ -4306,15 +4304,15 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
while (true) {
const rc = system.fcntl(fd, cmd, arg);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EINTR => continue,
- EACCES => return error.Locked,
- EBADF => unreachable,
- EBUSY => return error.FileBusy,
- EINVAL => unreachable, // invalid parameters
- EPERM => return error.PermissionDenied,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENOTDIR => unreachable, // invalid parameter
+ .SUCCESS => return @intCast(usize, rc),
+ .INTR => continue,
+ .ACCES => return error.Locked,
+ .BADF => unreachable,
+ .BUSY => return error.FileBusy,
+ .INVAL => unreachable, // invalid parameters
+ .PERM => return error.PermissionDenied,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NOTDIR => unreachable, // invalid parameter
else => |err| return unexpectedErrno(err),
}
}
@@ -4381,12 +4379,12 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {
while (true) {
const rc = system.flock(fd, operation);
switch (errno(rc)) {
- 0 => return,
- EBADF => unreachable,
- EINTR => continue,
- EINVAL => unreachable, // invalid parameters
- ENOLCK => return error.SystemResources,
- EWOULDBLOCK => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
+ .SUCCESS => return,
+ .BADF => unreachable,
+ .INTR => continue,
+ .INVAL => unreachable, // invalid parameters
+ .NOLCK => return error.SystemResources,
+ .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
else => |err| return unexpectedErrno(err),
}
}
@@ -4456,17 +4454,18 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
return getFdPath(fd, out_buffer);
}
- const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) {
- EINVAL => unreachable,
- EBADF => unreachable,
- EFAULT => unreachable,
- EACCES => return error.AccessDenied,
- ENOENT => return error.FileNotFound,
- ENOTSUP => return error.NotSupported,
- ENOTDIR => return error.NotDir,
- ENAMETOOLONG => return error.NameTooLong,
- ELOOP => return error.SymLinkLoop,
- EIO => return error.InputOutput,
+ const result_path = std.c.realpath(pathname, out_buffer) orelse switch (@intToEnum(E, std.c._errno().*)) {
+ .SUCCESS => unreachable,
+ .INVAL => unreachable,
+ .BADF => unreachable,
+ .FAULT => unreachable,
+ .ACCES => return error.AccessDenied,
+ .NOENT => return error.FileNotFound,
+ .OPNOTSUPP => return error.NotSupported,
+ .NOTDIR => return error.NotDir,
+ .NAMETOOLONG => return error.NameTooLong,
+ .LOOP => return error.SymLinkLoop,
+ .IO => return error.InputOutput,
else => |err| return unexpectedErrno(err),
};
return mem.spanZ(result_path);
@@ -4528,8 +4527,8 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
// the path to the file descriptor.
@memset(out_buffer, 0, MAX_PATH_BYTES);
switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) {
- 0 => {},
- EBADF => return error.FileNotFound,
+ .SUCCESS => {},
+ .BADF => return error.FileNotFound,
// TODO man pages for fcntl on macOS don't really tell you what
// errno values to expect when command is F_GETPATH...
else => |err| return unexpectedErrno(err),
@@ -4562,13 +4561,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
var rem: timespec = undefined;
while (true) {
switch (errno(system.nanosleep(&req, &rem))) {
- EFAULT => unreachable,
- EINVAL => {
+ .FAULT => unreachable,
+ .INVAL => {
// Sometimes Darwin returns EINVAL for no reason.
// We treat it as a spurious wakeup.
return;
},
- EINTR => {
+ .INTR => {
req = rem;
continue;
},
@@ -4668,13 +4667,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
var ts: timestamp_t = undefined;
switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {
- 0 => {
+ .SUCCESS => {
tp.* = .{
.tv_sec = @intCast(i64, ts / std.time.ns_per_s),
.tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
};
},
- EINVAL => return error.UnsupportedClock,
+ .INVAL => return error.UnsupportedClock,
else => |err| return unexpectedErrno(err),
}
return;
@@ -4698,9 +4697,9 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
}
switch (errno(system.clock_gettime(clk_id, tp))) {
- 0 => return,
- EFAULT => unreachable,
- EINVAL => return error.UnsupportedClock,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .INVAL => return error.UnsupportedClock,
else => |err| return unexpectedErrno(err),
}
}
@@ -4709,20 +4708,20 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
var ts: timestamp_t = undefined;
switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {
- 0 => res.* = .{
+ .SUCCESS => res.* = .{
.tv_sec = @intCast(i64, ts / std.time.ns_per_s),
.tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
},
- EINVAL => return error.UnsupportedClock,
+ .INVAL => return error.UnsupportedClock,
else => |err| return unexpectedErrno(err),
}
return;
}
switch (errno(system.clock_getres(clk_id, res))) {
- 0 => return,
- EFAULT => unreachable,
- EINVAL => return error.UnsupportedClock,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .INVAL => return error.UnsupportedClock,
else => |err| return unexpectedErrno(err),
}
}
@@ -4732,11 +4731,11 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
var set: cpu_set_t = undefined;
switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
- 0 => return set,
- EFAULT => unreachable,
- EINVAL => unreachable,
- ESRCH => unreachable,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return set,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .SRCH => unreachable,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4768,13 +4767,9 @@ pub const UnexpectedError = error{
/// Call this when you made a syscall or something that sets errno
/// and you get an unexpected error.
-pub fn unexpectedErrno(err: anytype) UnexpectedError {
- if (@typeInfo(@TypeOf(err)) != .Int) {
- @compileError("err is expected to be an integer");
- }
-
+pub fn unexpectedErrno(err: E) UnexpectedError {
if (unexpected_error_tracing) {
- std.debug.warn("unexpected errno: {d}\n", .{err});
+ std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)});
std.debug.dumpCurrentStackTrace(null);
}
return error.Unexpected;
@@ -4790,11 +4785,11 @@ pub const SigaltstackError = error{
pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
switch (errno(system.sigaltstack(ss, old_ss))) {
- 0 => return,
- EFAULT => unreachable,
- EINVAL => unreachable,
- ENOMEM => return error.SizeTooSmall,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .NOMEM => return error.SizeTooSmall,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4802,9 +4797,9 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
/// Examine and change a signal action.
pub fn sigaction(sig: u6, act: ?*const Sigaction, oact: ?*Sigaction) void {
switch (errno(system.sigaction(sig, act, oact))) {
- 0 => return,
- EFAULT => unreachable,
- EINVAL => unreachable,
+ .SUCCESS => return,
+ .FAULT => unreachable,
+ .INVAL => unreachable,
else => unreachable,
}
}
@@ -4841,25 +4836,25 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {
const atim = times[0].toTimestamp();
const mtim = times[1].toTimestamp();
switch (wasi.fd_filestat_set_times(fd, atim, mtim, wasi.FILESTAT_SET_ATIM | wasi.FILESTAT_SET_MTIM)) {
- wasi.ESUCCESS => return,
- wasi.EACCES => return error.AccessDenied,
- wasi.EPERM => return error.PermissionDenied,
- wasi.EBADF => unreachable, // always a race condition
- wasi.EFAULT => unreachable,
- wasi.EINVAL => unreachable,
- wasi.EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.PermissionDenied,
+ .BADF => unreachable, // always a race condition
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
switch (errno(system.futimens(fd, times))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EPERM => return error.PermissionDenied,
- EBADF => unreachable, // always a race condition
- EFAULT => unreachable,
- EINVAL => unreachable,
- EROFS => return error.ReadOnlyFileSystem,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .PERM => return error.PermissionDenied,
+ .BADF => unreachable, // always a race condition
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .ROFS => return error.ReadOnlyFileSystem,
else => |err| return unexpectedErrno(err),
}
}
@@ -4869,10 +4864,10 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
if (builtin.link_libc) {
switch (errno(system.gethostname(name_buffer, name_buffer.len))) {
- 0 => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),
- EFAULT => unreachable,
- ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),
+ .FAULT => unreachable,
+ .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -4889,8 +4884,8 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
pub fn uname() utsname {
var uts: utsname = undefined;
switch (errno(system.uname(&uts))) {
- 0 => return uts,
- EFAULT => unreachable,
+ .SUCCESS => return uts,
+ .FAULT => unreachable,
else => unreachable,
}
}
@@ -5049,33 +5044,33 @@ pub fn sendmsg(
}
} else {
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
+ .SUCCESS => return @intCast(usize, rc),
- EACCES => return error.AccessDenied,
- EAGAIN => return error.WouldBlock,
- EALREADY => return error.FastOpenAlreadyInProgress,
- EBADF => unreachable, // always a race condition
- ECONNRESET => return error.ConnectionResetByPeer,
- EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
- EFAULT => unreachable, // An invalid user space address was specified for an argument.
- EINTR => continue,
- EINVAL => unreachable, // Invalid argument passed.
- EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
- EMSGSIZE => return error.MessageTooBig,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
- EPIPE => return error.BrokenPipe,
- EAFNOSUPPORT => return error.AddressFamilyNotSupported,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- EHOSTUNREACH => return error.NetworkUnreachable,
- ENETUNREACH => return error.NetworkUnreachable,
- ENOTCONN => return error.SocketNotConnected,
- ENETDOWN => return error.NetworkSubsystemFailed,
+ .ACCES => return error.AccessDenied,
+ .AGAIN => return error.WouldBlock,
+ .ALREADY => return error.FastOpenAlreadyInProgress,
+ .BADF => unreachable, // always a race condition
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
+ .FAULT => unreachable, // An invalid user space address was specified for an argument.
+ .INTR => continue,
+ .INVAL => unreachable, // Invalid argument passed.
+ .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
+ .MSGSIZE => return error.MessageTooBig,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
+ .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
+ .PIPE => return error.BrokenPipe,
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .HOSTUNREACH => return error.NetworkUnreachable,
+ .NETUNREACH => return error.NetworkUnreachable,
+ .NOTCONN => return error.SocketNotConnected,
+ .NETDOWN => return error.NetworkSubsystemFailed,
else => |err| return unexpectedErrno(err),
}
}
@@ -5149,33 +5144,33 @@ pub fn sendto(
}
} else {
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
+ .SUCCESS => return @intCast(usize, rc),
- EACCES => return error.AccessDenied,
- EAGAIN => return error.WouldBlock,
- EALREADY => return error.FastOpenAlreadyInProgress,
- EBADF => unreachable, // always a race condition
- ECONNRESET => return error.ConnectionResetByPeer,
- EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
- EFAULT => unreachable, // An invalid user space address was specified for an argument.
- EINTR => continue,
- EINVAL => unreachable, // Invalid argument passed.
- EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
- EMSGSIZE => return error.MessageTooBig,
- ENOBUFS => return error.SystemResources,
- ENOMEM => return error.SystemResources,
- ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
- EPIPE => return error.BrokenPipe,
- EAFNOSUPPORT => return error.AddressFamilyNotSupported,
- ELOOP => return error.SymLinkLoop,
- ENAMETOOLONG => return error.NameTooLong,
- ENOENT => return error.FileNotFound,
- ENOTDIR => return error.NotDir,
- EHOSTUNREACH => return error.NetworkUnreachable,
- ENETUNREACH => return error.NetworkUnreachable,
- ENOTCONN => return error.SocketNotConnected,
- ENETDOWN => return error.NetworkSubsystemFailed,
+ .ACCES => return error.AccessDenied,
+ .AGAIN => return error.WouldBlock,
+ .ALREADY => return error.FastOpenAlreadyInProgress,
+ .BADF => unreachable, // always a race condition
+ .CONNRESET => return error.ConnectionResetByPeer,
+ .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
+ .FAULT => unreachable, // An invalid user space address was specified for an argument.
+ .INTR => continue,
+ .INVAL => unreachable, // Invalid argument passed.
+ .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
+ .MSGSIZE => return error.MessageTooBig,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
+ .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
+ .PIPE => return error.BrokenPipe,
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.NotDir,
+ .HOSTUNREACH => return error.NetworkUnreachable,
+ .NETUNREACH => return error.NetworkUnreachable,
+ .NOTCONN => return error.SocketNotConnected,
+ .NETDOWN => return error.NetworkSubsystemFailed,
else => |err| return unexpectedErrno(err),
}
}
@@ -5312,7 +5307,7 @@ pub fn sendfile(
var offset: off_t = @bitCast(off_t, in_offset);
const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
switch (errno(rc)) {
- 0 => {
+ .SUCCESS => {
const amt = @bitCast(usize, rc);
total_written += amt;
if (in_len == 0 and amt == 0) {
@@ -5325,12 +5320,12 @@ pub fn sendfile(
}
},
- EBADF => unreachable, // Always a race condition.
- EFAULT => unreachable, // Segmentation fault.
- EOVERFLOW => unreachable, // We avoid passing too large of a `count`.
- ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
+ .BADF => unreachable, // Always a race condition.
+ .FAULT => unreachable, // Segmentation fault.
+ .OVERFLOW => unreachable, // We avoid passing too large of a `count`.
+ .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
- EINVAL, ENOSYS => {
+ .INVAL, .NOSYS => {
// EINVAL could be any of the following situations:
// * Descriptor is not valid or locked
// * an mmap(2)-like operation is not available for in_fd
@@ -5340,17 +5335,17 @@ pub fn sendfile(
// manually, the same as ENOSYS.
break :sf;
},
- EAGAIN => if (std.event.Loop.instance) |loop| {
+ .AGAIN => if (std.event.Loop.instance) |loop| {
loop.waitUntilFdWritable(out_fd);
continue;
} else {
return error.WouldBlock;
},
- EIO => return error.InputOutput,
- EPIPE => return error.BrokenPipe,
- ENOMEM => return error.SystemResources,
- ENXIO => return error.Unseekable,
- ESPIPE => return error.Unseekable,
+ .IO => return error.InputOutput,
+ .PIPE => return error.BrokenPipe,
+ .NOMEM => return error.SystemResources,
+ .NXIO => return error.Unseekable,
+ .SPIPE => return error.Unseekable,
else => |err| {
unexpectedErrno(err) catch {};
break :sf;
@@ -5392,13 +5387,13 @@ pub fn sendfile(
const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));
const amt = @bitCast(usize, sbytes);
switch (err) {
- 0 => return amt,
+ .SUCCESS => return amt,
- EBADF => unreachable, // Always a race condition.
- EFAULT => unreachable, // Segmentation fault.
- ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
+ .BADF => unreachable, // Always a race condition.
+ .FAULT => unreachable, // Segmentation fault.
+ .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
- EINVAL, EOPNOTSUPP, ENOTSOCK, ENOSYS => {
+ .INVAL, .OPNOTSUPP, .NOTSOCK, .NOSYS => {
// EINVAL could be any of the following situations:
// * The fd argument is not a regular file.
// * The s argument is not a SOCK_STREAM type socket.
@@ -5408,9 +5403,9 @@ pub fn sendfile(
break :sf;
},
- EINTR => if (amt != 0) return amt else continue,
+ .INTR => if (amt != 0) return amt else continue,
- EAGAIN => if (amt != 0) {
+ .AGAIN => if (amt != 0) {
return amt;
} else if (std.event.Loop.instance) |loop| {
loop.waitUntilFdWritable(out_fd);
@@ -5419,7 +5414,7 @@ pub fn sendfile(
return error.WouldBlock;
},
- EBUSY => if (amt != 0) {
+ .BUSY => if (amt != 0) {
return amt;
} else if (std.event.Loop.instance) |loop| {
loop.waitUntilFdReadable(in_fd);
@@ -5428,9 +5423,9 @@ pub fn sendfile(
return error.WouldBlock;
},
- EIO => return error.InputOutput,
- ENOBUFS => return error.SystemResources,
- EPIPE => return error.BrokenPipe,
+ .IO => return error.InputOutput,
+ .NOBUFS => return error.SystemResources,
+ .PIPE => return error.BrokenPipe,
else => {
unexpectedErrno(err) catch {};
@@ -5471,18 +5466,18 @@ pub fn sendfile(
const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));
const amt = @bitCast(usize, sbytes);
switch (err) {
- 0 => return amt,
+ .SUCCESS => return amt,
- EBADF => unreachable, // Always a race condition.
- EFAULT => unreachable, // Segmentation fault.
- EINVAL => unreachable,
- ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
+ .BADF => unreachable, // Always a race condition.
+ .FAULT => unreachable, // Segmentation fault.
+ .INVAL => unreachable,
+ .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
- ENOTSUP, ENOTSOCK, ENOSYS => break :sf,
+ .OPNOTSUPP, .NOTSOCK, .NOSYS => break :sf,
- EINTR => if (amt != 0) return amt else continue,
+ .INTR => if (amt != 0) return amt else continue,
- EAGAIN => if (amt != 0) {
+ .AGAIN => if (amt != 0) {
return amt;
} else if (std.event.Loop.instance) |loop| {
loop.waitUntilFdWritable(out_fd);
@@ -5491,8 +5486,8 @@ pub fn sendfile(
return error.WouldBlock;
},
- EIO => return error.InputOutput,
- EPIPE => return error.BrokenPipe,
+ .IO => return error.InputOutput,
+ .PIPE => return error.BrokenPipe,
else => {
unexpectedErrno(err) catch {};
@@ -5595,22 +5590,22 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
switch (system.getErrno(rc)) {
- 0 => return @intCast(usize, rc),
- EBADF => return error.FilesOpenedWithWrongFlags,
- EFBIG => return error.FileTooBig,
- EIO => return error.InputOutput,
- EISDIR => return error.IsDir,
- ENOMEM => return error.OutOfMemory,
- ENOSPC => return error.NoSpaceLeft,
- EOVERFLOW => return error.Unseekable,
- EPERM => return error.PermissionDenied,
- ETXTBSY => return error.FileBusy,
+ .SUCCESS => return @intCast(usize, rc),
+ .BADF => return error.FilesOpenedWithWrongFlags,
+ .FBIG => return error.FileTooBig,
+ .IO => return error.InputOutput,
+ .ISDIR => return error.IsDir,
+ .NOMEM => return error.OutOfMemory,
+ .NOSPC => return error.NoSpaceLeft,
+ .OVERFLOW => return error.Unseekable,
+ .PERM => return error.PermissionDenied,
+ .TXTBSY => return error.FileBusy,
// these may not be regular files, try fallback
- EINVAL => {},
+ .INVAL => {},
// support for cross-filesystem copy added in Linux 5.3, use fallback
- EXDEV => {},
+ .XDEV => {},
// syscall added in Linux 4.5, use fallback
- ENOSYS => {
+ .NOSYS => {
has_copy_file_range_syscall.store(false, .Monotonic);
},
else => |err| return unexpectedErrno(err),
@@ -5652,11 +5647,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
}
} else {
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EFAULT => unreachable,
- EINTR => continue,
- EINVAL => unreachable,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return @intCast(usize, rc),
+ .FAULT => unreachable,
+ .INTR => continue,
+ .INVAL => unreachable,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -5681,11 +5676,11 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P
}
const rc = system.ppoll(fds.ptr, fds.len, ts_ptr, mask);
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EFAULT => unreachable,
- EINTR => return error.SignalInterrupt,
- EINVAL => unreachable,
- ENOMEM => return error.SystemResources,
+ .SUCCESS => return @intCast(usize, rc),
+ .FAULT => unreachable,
+ .INTR => return error.SignalInterrupt,
+ .INVAL => unreachable,
+ .NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}
@@ -5750,17 +5745,17 @@ pub fn recvfrom(
}
} else {
switch (errno(rc)) {
- 0 => return @intCast(usize, rc),
- EBADF => unreachable, // always a race condition
- EFAULT => unreachable,
- EINVAL => unreachable,
- ENOTCONN => unreachable,
- ENOTSOCK => unreachable,
- EINTR => continue,
- EAGAIN => return error.WouldBlock,
- ENOMEM => return error.SystemResources,
- ECONNREFUSED => return error.ConnectionRefused,
- ECONNRESET => return error.ConnectionResetByPeer,
+ .SUCCESS => return @intCast(usize, rc),
+ .BADF => unreachable, // always a race condition
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .NOTCONN => unreachable,
+ .NOTSOCK => unreachable,
+ .INTR => continue,
+ .AGAIN => return error.WouldBlock,
+ .NOMEM => return error.SystemResources,
+ .CONNREFUSED => return error.ConnectionRefused,
+ .CONNRESET => return error.ConnectionResetByPeer,
else => |err| return unexpectedErrno(err),
}
}
@@ -5830,8 +5825,8 @@ pub fn sched_yield() SchedYieldError!void {
return;
}
switch (errno(system.sched_yield())) {
- 0 => return,
- ENOSYS => return error.SystemCannotYield,
+ .SUCCESS => return,
+ .NOSYS => return error.SystemCannotYield,
else => return error.SystemCannotYield,
}
}
@@ -5874,17 +5869,17 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo
return;
} else {
switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
- 0 => {},
- EBADF => unreachable, // always a race condition
- ENOTSOCK => unreachable, // always a race condition
- EINVAL => unreachable,
- EFAULT => unreachable,
- EDOM => return error.TimeoutTooBig,
- EISCONN => return error.AlreadyConnected,
- ENOPROTOOPT => return error.InvalidProtocolOption,
- ENOMEM => return error.SystemResources,
- ENOBUFS => return error.SystemResources,
- EPERM => return error.PermissionDenied,
+ .SUCCESS => {},
+ .BADF => unreachable, // always a race condition
+ .NOTSOCK => unreachable, // always a race condition
+ .INVAL => unreachable,
+ .FAULT => unreachable,
+ .DOM => return error.TimeoutTooBig,
+ .ISCONN => return error.AlreadyConnected,
+ .NOPROTOOPT => return error.InvalidProtocolOption,
+ .NOMEM => return error.SystemResources,
+ .NOBUFS => return error.SystemResources,
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -5909,13 +5904,13 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
const getErrno = if (use_c) std.c.getErrno else linux.getErrno;
const rc = sys.memfd_create(name, flags);
switch (getErrno(rc)) {
- 0 => return @intCast(fd_t, rc),
- EFAULT => unreachable, // name has invalid memory
- EINVAL => unreachable, // name/flags are faulty
- ENFILE => return error.SystemFdQuotaExceeded,
- EMFILE => return error.ProcessFdQuotaExceeded,
- ENOMEM => return error.OutOfMemory,
- ENOSYS => return error.SystemOutdated,
+ .SUCCESS => return @intCast(fd_t, rc),
+ .FAULT => unreachable, // name has invalid memory
+ .INVAL => unreachable, // name/flags are faulty
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NOMEM => return error.OutOfMemory,
+ .NOSYS => return error.SystemOutdated,
else => |err| return unexpectedErrno(err),
}
}
@@ -5940,9 +5935,9 @@ pub fn getrusage(who: i32) rusage {
var result: rusage = undefined;
const rc = system.getrusage(who, &result);
switch (errno(rc)) {
- 0 => return result,
- EINVAL => unreachable,
- EFAULT => unreachable,
+ .SUCCESS => return result,
+ .INVAL => unreachable,
+ .FAULT => unreachable,
else => unreachable,
}
}
@@ -5953,10 +5948,10 @@ pub fn tcgetattr(handle: fd_t) TermiosGetError!termios {
while (true) {
var term: termios = undefined;
switch (errno(system.tcgetattr(handle, &term))) {
- 0 => return term,
- EINTR => continue,
- EBADF => unreachable,
- ENOTTY => return error.NotATerminal,
+ .SUCCESS => return term,
+ .INTR => continue,
+ .BADF => unreachable,
+ .NOTTY => return error.NotATerminal,
else => |err| return unexpectedErrno(err),
}
}
@@ -5967,12 +5962,12 @@ pub const TermiosSetError = TermiosGetError || error{ProcessOrphaned};
pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) TermiosSetError!void {
while (true) {
switch (errno(system.tcsetattr(handle, optional_action, &termios_p))) {
- 0 => return,
- EBADF => unreachable,
- EINTR => continue,
- EINVAL => unreachable,
- ENOTTY => return error.NotATerminal,
- EIO => return error.ProcessOrphaned,
+ .SUCCESS => return,
+ .BADF => unreachable,
+ .INTR => continue,
+ .INVAL => unreachable,
+ .NOTTY => return error.NotATerminal,
+ .IO => return error.ProcessOrphaned,
else => |err| return unexpectedErrno(err),
}
}
@@ -5986,15 +5981,15 @@ pub const IoCtl_SIOCGIFINDEX_Error = error{
pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
while (true) {
switch (errno(system.ioctl(fd, SIOCGIFINDEX, @ptrToInt(ifr)))) {
- 0 => return,
- EINVAL => unreachable, // Bad parameters.
- ENOTTY => unreachable,
- ENXIO => unreachable,
- EBADF => unreachable, // Always a race condition.
- EFAULT => unreachable, // Bad pointer parameter.
- EINTR => continue,
- EIO => return error.FileSystem,
- ENODEV => return error.InterfaceNotFound,
+ .SUCCESS => return,
+ .INVAL => unreachable, // Bad parameters.
+ .NOTTY => unreachable,
+ .NXIO => unreachable,
+ .BADF => unreachable, // Always a race condition.
+ .FAULT => unreachable, // Bad pointer parameter.
+ .INTR => continue,
+ .IO => return error.FileSystem,
+ .NODEV => return error.InterfaceNotFound,
else => |err| return unexpectedErrno(err),
}
}
@@ -6003,13 +5998,13 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
const rc = system.signalfd(fd, mask, flags);
switch (errno(rc)) {
- 0 => return @intCast(fd_t, rc),
- EBADF, EINVAL => unreachable,
- ENFILE => return error.SystemFdQuotaExceeded,
- ENOMEM => return error.SystemResources,
- EMFILE => return error.ProcessResources,
- ENODEV => return error.InodeMountFail,
- ENOSYS => return error.SystemOutdated,
+ .SUCCESS => return @intCast(fd_t, rc),
+ .BADF, .INVAL => unreachable,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOMEM => return error.SystemResources,
+ .MFILE => return error.ProcessResources,
+ .NODEV => return error.InodeMountFail,
+ .NOSYS => return error.SystemOutdated,
else => |err| return unexpectedErrno(err),
}
}
@@ -6030,11 +6025,11 @@ pub fn sync() void {
pub fn syncfs(fd: fd_t) SyncError!void {
const rc = system.syncfs(fd);
switch (errno(rc)) {
- 0 => return,
- EBADF, EINVAL, EROFS => unreachable,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EDQUOT => return error.DiskQuota,
+ .SUCCESS => return,
+ .BADF, .INVAL, .ROFS => unreachable,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .DQUOT => return error.DiskQuota,
else => |err| return unexpectedErrno(err),
}
}
@@ -6054,11 +6049,11 @@ pub fn fsync(fd: fd_t) SyncError!void {
}
const rc = system.fsync(fd);
switch (errno(rc)) {
- 0 => return,
- EBADF, EINVAL, EROFS => unreachable,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EDQUOT => return error.DiskQuota,
+ .SUCCESS => return,
+ .BADF, .INVAL, .ROFS => unreachable,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .DQUOT => return error.DiskQuota,
else => |err| return unexpectedErrno(err),
}
}
@@ -6073,11 +6068,11 @@ pub fn fdatasync(fd: fd_t) SyncError!void {
}
const rc = system.fdatasync(fd);
switch (errno(rc)) {
- 0 => return,
- EBADF, EINVAL, EROFS => unreachable,
- EIO => return error.InputOutput,
- ENOSPC => return error.NoSpaceLeft,
- EDQUOT => return error.DiskQuota,
+ .SUCCESS => return,
+ .BADF, .INVAL, .ROFS => unreachable,
+ .IO => return error.InputOutput,
+ .NOSPC => return error.NoSpaceLeft,
+ .DQUOT => return error.DiskQuota,
else => |err| return unexpectedErrno(err),
}
}
@@ -6111,15 +6106,15 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
const rc = system.prctl(@enumToInt(option), buf[0], buf[1], buf[2], buf[3]);
switch (errno(rc)) {
- 0 => return @intCast(u31, rc),
- EACCES => return error.AccessDenied,
- EBADF => return error.InvalidFileDescriptor,
- EFAULT => return error.InvalidAddress,
- EINVAL => unreachable,
- ENODEV, ENXIO => return error.UnsupportedFeature,
- EOPNOTSUPP => return error.OperationNotSupported,
- EPERM, EBUSY => return error.PermissionDenied,
- ERANGE => unreachable,
+ .SUCCESS => return @intCast(u31, rc),
+ .ACCES => return error.AccessDenied,
+ .BADF => return error.InvalidFileDescriptor,
+ .FAULT => return error.InvalidAddress,
+ .INVAL => unreachable,
+ .NODEV, .NXIO => return error.UnsupportedFeature,
+ .OPNOTSUPP => return error.OperationNotSupported,
+ .PERM, .BUSY => return error.PermissionDenied,
+ .RANGE => unreachable,
else => |err| return unexpectedErrno(err),
}
}
@@ -6134,9 +6129,9 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
var limits: rlimit = undefined;
switch (errno(getrlimit_sym(resource, &limits))) {
- 0 => return limits,
- EFAULT => unreachable, // bogus pointer
- EINVAL => unreachable,
+ .SUCCESS => return limits,
+ .FAULT => unreachable, // bogus pointer
+ .INVAL => unreachable,
else => |err| return unexpectedErrno(err),
}
}
@@ -6150,10 +6145,10 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void
system.setrlimit;
switch (errno(setrlimit_sym(resource, &limits))) {
- 0 => return,
- EFAULT => unreachable, // bogus pointer
- EINVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable
- EPERM => return error.PermissionDenied,
+ .SUCCESS => return,
+ .FAULT => unreachable, // bogus pointer
+ .INVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable
+ .PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -6194,14 +6189,14 @@ pub const MadviseError = error{
/// This syscall is optional and is sometimes configured to be disabled.
pub fn madvise(ptr: [*]align(mem.page_size) u8, length: usize, advice: u32) MadviseError!void {
switch (errno(system.madvise(ptr, length, advice))) {
- 0 => return,
- EACCES => return error.AccessDenied,
- EAGAIN => return error.SystemResources,
- EBADF => unreachable, // The map exists, but the area maps something that isn't a file.
- EINVAL => return error.InvalidSyscall,
- EIO => return error.WouldExceedMaximumResidentSetSize,
- ENOMEM => return error.OutOfMemory,
- ENOSYS => return error.MadviseUnavailable,
+ .SUCCESS => return,
+ .ACCES => return error.AccessDenied,
+ .AGAIN => return error.SystemResources,
+ .BADF => unreachable, // The map exists, but the area maps something that isn't a file.
+ .INVAL => return error.InvalidSyscall,
+ .IO => return error.WouldExceedMaximumResidentSetSize,
+ .NOMEM => return error.OutOfMemory,
+ .NOSYS => return error.MadviseUnavailable,
else => |err| return unexpectedErrno(err),
}
}
diff --git a/lib/std/os/bits.zig b/lib/std/os/bits.zig
index 5c39609182..36eda7707f 100644
--- a/lib/std/os/bits.zig
+++ b/lib/std/os/bits.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//! Platform-dependent types and values that are used along with OS-specific APIs.
//! These are imported into `std.c`, `std.os`, and `std.os.linux`.
//! Root source files can define `os.bits` and these will additionally be added
diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig
index 91705c0d2e..a0f5e5a400 100644
--- a/lib/std/os/bits/darwin.zig
+++ b/lib/std/os/bits/darwin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
@@ -235,6 +230,7 @@ pub const host_t = mach_port_t;
pub const CALENDAR_CLOCK = 1;
pub const PATH_MAX = 1024;
+pub const IOV_MAX = 16;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
@@ -865,337 +861,342 @@ pub fn WIFSIGNALED(x: u32) bool {
return wstatus(x) != wstopped and wstatus(x) != 0;
}
-/// Operation not permitted
-pub const EPERM = 1;
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
-/// No such file or directory
-pub const ENOENT = 2;
+ /// Operation not permitted
+ PERM = 1,
-/// No such process
-pub const ESRCH = 3;
+ /// No such file or directory
+ NOENT = 2,
-/// Interrupted system call
-pub const EINTR = 4;
+ /// No such process
+ SRCH = 3,
-/// Input/output error
-pub const EIO = 5;
+ /// Interrupted system call
+ INTR = 4,
-/// Device not configured
-pub const ENXIO = 6;
+ /// Input/output error
+ IO = 5,
-/// Argument list too long
-pub const E2BIG = 7;
+ /// Device not configured
+ NXIO = 6,
-/// Exec format error
-pub const ENOEXEC = 8;
+ /// Argument list too long
+ @"2BIG" = 7,
-/// Bad file descriptor
-pub const EBADF = 9;
+ /// Exec format error
+ NOEXEC = 8,
-/// No child processes
-pub const ECHILD = 10;
+ /// Bad file descriptor
+ BADF = 9,
-/// Resource deadlock avoided
-pub const EDEADLK = 11;
+ /// No child processes
+ CHILD = 10,
-/// Cannot allocate memory
-pub const ENOMEM = 12;
+ /// Resource deadlock avoided
+ DEADLK = 11,
-/// Permission denied
-pub const EACCES = 13;
+ /// Cannot allocate memory
+ NOMEM = 12,
-/// Bad address
-pub const EFAULT = 14;
+ /// Permission denied
+ ACCES = 13,
-/// Block device required
-pub const ENOTBLK = 15;
+ /// Bad address
+ FAULT = 14,
-/// Device / Resource busy
-pub const EBUSY = 16;
+ /// Block device required
+ NOTBLK = 15,
-/// File exists
-pub const EEXIST = 17;
+ /// Device / Resource busy
+ BUSY = 16,
-/// Cross-device link
-pub const EXDEV = 18;
+ /// File exists
+ EXIST = 17,
-/// Operation not supported by device
-pub const ENODEV = 19;
+ /// Cross-device link
+ XDEV = 18,
-/// Not a directory
-pub const ENOTDIR = 20;
+ /// Operation not supported by device
+ NODEV = 19,
-/// Is a directory
-pub const EISDIR = 21;
+ /// Not a directory
+ NOTDIR = 20,
-/// Invalid argument
-pub const EINVAL = 22;
+ /// Is a directory
+ ISDIR = 21,
-/// Too many open files in system
-pub const ENFILE = 23;
+ /// Invalid argument
+ INVAL = 22,
-/// Too many open files
-pub const EMFILE = 24;
+ /// Too many open files in system
+ NFILE = 23,
-/// Inappropriate ioctl for device
-pub const ENOTTY = 25;
+ /// Too many open files
+ MFILE = 24,
-/// Text file busy
-pub const ETXTBSY = 26;
+ /// Inappropriate ioctl for device
+ NOTTY = 25,
-/// File too large
-pub const EFBIG = 27;
+ /// Text file busy
+ TXTBSY = 26,
-/// No space left on device
-pub const ENOSPC = 28;
+ /// File too large
+ FBIG = 27,
-/// Illegal seek
-pub const ESPIPE = 29;
+ /// No space left on device
+ NOSPC = 28,
-/// Read-only file system
-pub const EROFS = 30;
+ /// Illegal seek
+ SPIPE = 29,
-/// Too many links
-pub const EMLINK = 31;
-/// Broken pipe
+ /// Read-only file system
+ ROFS = 30,
-// math software
-pub const EPIPE = 32;
+ /// Too many links
+ MLINK = 31,
-/// Numerical argument out of domain
-pub const EDOM = 33;
-/// Result too large
+ /// Broken pipe
+ PIPE = 32,
-// non-blocking and interrupt i/o
-pub const ERANGE = 34;
+ // math software
-/// Resource temporarily unavailable
-pub const EAGAIN = 35;
+ /// Numerical argument out of domain
+ DOM = 33,
-/// Operation would block
-pub const EWOULDBLOCK = EAGAIN;
+ /// Result too large
+ RANGE = 34,
-/// Operation now in progress
-pub const EINPROGRESS = 36;
-/// Operation already in progress
+ // non-blocking and interrupt i/o
-// ipc/network software -- argument errors
-pub const EALREADY = 37;
+ /// Resource temporarily unavailable
+ /// This is the same code used for `WOULDBLOCK`.
+ AGAIN = 35,
-/// Socket operation on non-socket
-pub const ENOTSOCK = 38;
+ /// Operation now in progress
+ INPROGRESS = 36,
-/// Destination address required
-pub const EDESTADDRREQ = 39;
+ /// Operation already in progress
+ ALREADY = 37,
-/// Message too long
-pub const EMSGSIZE = 40;
+ // ipc/network software -- argument errors
-/// Protocol wrong type for socket
-pub const EPROTOTYPE = 41;
+ /// Socket operation on non-socket
+ NOTSOCK = 38,
-/// Protocol not available
-pub const ENOPROTOOPT = 42;
+ /// Destination address required
+ DESTADDRREQ = 39,
-/// Protocol not supported
-pub const EPROTONOSUPPORT = 43;
+ /// Message too long
+ MSGSIZE = 40,
-/// Socket type not supported
-pub const ESOCKTNOSUPPORT = 44;
+ /// Protocol wrong type for socket
+ PROTOTYPE = 41,
-/// Operation not supported
-pub const ENOTSUP = 45;
+ /// Protocol not available
+ NOPROTOOPT = 42,
-/// Operation not supported. Alias of `ENOTSUP`.
-pub const EOPNOTSUPP = ENOTSUP;
+ /// Protocol not supported
+ PROTONOSUPPORT = 43,
-/// Protocol family not supported
-pub const EPFNOSUPPORT = 46;
+ /// Socket type not supported
+ SOCKTNOSUPPORT = 44,
-/// Address family not supported by protocol family
-pub const EAFNOSUPPORT = 47;
+ /// Operation not supported
+ /// The same code is used for `NOTSUP`.
+ OPNOTSUPP = 45,
-/// Address already in use
-pub const EADDRINUSE = 48;
-/// Can't assign requested address
+ /// Protocol family not supported
+ PFNOSUPPORT = 46,
-// ipc/network software -- operational errors
-pub const EADDRNOTAVAIL = 49;
+ /// Address family not supported by protocol family
+ AFNOSUPPORT = 47,
-/// Network is down
-pub const ENETDOWN = 50;
+ /// Address already in use
+ ADDRINUSE = 48,
+ /// Can't assign requested address
-/// Network is unreachable
-pub const ENETUNREACH = 51;
+ // ipc/network software -- operational errors
+ ADDRNOTAVAIL = 49,
-/// Network dropped connection on reset
-pub const ENETRESET = 52;
+ /// Network is down
+ NETDOWN = 50,
-/// Software caused connection abort
-pub const ECONNABORTED = 53;
+ /// Network is unreachable
+ NETUNREACH = 51,
-/// Connection reset by peer
-pub const ECONNRESET = 54;
+ /// Network dropped connection on reset
+ NETRESET = 52,
-/// No buffer space available
-pub const ENOBUFS = 55;
+ /// Software caused connection abort
+ CONNABORTED = 53,
-/// Socket is already connected
-pub const EISCONN = 56;
+ /// Connection reset by peer
+ CONNRESET = 54,
-/// Socket is not connected
-pub const ENOTCONN = 57;
+ /// No buffer space available
+ NOBUFS = 55,
-/// Can't send after socket shutdown
-pub const ESHUTDOWN = 58;
+ /// Socket is already connected
+ ISCONN = 56,
-/// Too many references: can't splice
-pub const ETOOMANYREFS = 59;
+ /// Socket is not connected
+ NOTCONN = 57,
-/// Operation timed out
-pub const ETIMEDOUT = 60;
+ /// Can't send after socket shutdown
+ SHUTDOWN = 58,
-/// Connection refused
-pub const ECONNREFUSED = 61;
+ /// Too many references: can't splice
+ TOOMANYREFS = 59,
-/// Too many levels of symbolic links
-pub const ELOOP = 62;
+ /// Operation timed out
+ TIMEDOUT = 60,
-/// File name too long
-pub const ENAMETOOLONG = 63;
+ /// Connection refused
+ CONNREFUSED = 61,
-/// Host is down
-pub const EHOSTDOWN = 64;
+ /// Too many levels of symbolic links
+ LOOP = 62,
-/// No route to host
-pub const EHOSTUNREACH = 65;
-/// Directory not empty
+ /// File name too long
+ NAMETOOLONG = 63,
-// quotas & mush
-pub const ENOTEMPTY = 66;
+ /// Host is down
+ HOSTDOWN = 64,
-/// Too many processes
-pub const EPROCLIM = 67;
+ /// No route to host
+ HOSTUNREACH = 65,
+ /// Directory not empty
-/// Too many users
-pub const EUSERS = 68;
-/// Disc quota exceeded
+ // quotas & mush
+ NOTEMPTY = 66,
-// Network File System
-pub const EDQUOT = 69;
+ /// Too many processes
+ PROCLIM = 67,
-/// Stale NFS file handle
-pub const ESTALE = 70;
+ /// Too many users
+ USERS = 68,
+ /// Disc quota exceeded
-/// Too many levels of remote in path
-pub const EREMOTE = 71;
+ // Network File System
+ DQUOT = 69,
-/// RPC struct is bad
-pub const EBADRPC = 72;
+ /// Stale NFS file handle
+ STALE = 70,
-/// RPC version wrong
-pub const ERPCMISMATCH = 73;
+ /// Too many levels of remote in path
+ REMOTE = 71,
-/// RPC prog. not avail
-pub const EPROGUNAVAIL = 74;
+ /// RPC struct is bad
+ BADRPC = 72,
-/// Program version wrong
-pub const EPROGMISMATCH = 75;
+ /// RPC version wrong
+ RPCMISMATCH = 73,
-/// Bad procedure for program
-pub const EPROCUNAVAIL = 76;
+ /// RPC prog. not avail
+ PROGUNAVAIL = 74,
-/// No locks available
-pub const ENOLCK = 77;
+ /// Program version wrong
+ PROGMISMATCH = 75,
-/// Function not implemented
-pub const ENOSYS = 78;
+ /// Bad procedure for program
+ PROCUNAVAIL = 76,
-/// Inappropriate file type or format
-pub const EFTYPE = 79;
+ /// No locks available
+ NOLCK = 77,
-/// Authentication error
-pub const EAUTH = 80;
-/// Need authenticator
+ /// Function not implemented
+ NOSYS = 78,
-// Intelligent device errors
-pub const ENEEDAUTH = 81;
+ /// Inappropriate file type or format
+ FTYPE = 79,
-/// Device power is off
-pub const EPWROFF = 82;
+ /// Authentication error
+ AUTH = 80,
-/// Device error, e.g. paper out
-pub const EDEVERR = 83;
-/// Value too large to be stored in data type
+ /// Need authenticator
+ NEEDAUTH = 81,
-// Program loading errors
-pub const EOVERFLOW = 84;
+ // Intelligent device errors
-/// Bad executable
-pub const EBADEXEC = 85;
+ /// Device power is off
+ PWROFF = 82,
-/// Bad CPU type in executable
-pub const EBADARCH = 86;
+ /// Device error, e.g. paper out
+ DEVERR = 83,
-/// Shared library version mismatch
-pub const ESHLIBVERS = 87;
+ /// Value too large to be stored in data type
+ OVERFLOW = 84,
-/// Malformed Macho file
-pub const EBADMACHO = 88;
+ // Program loading errors
-/// Operation canceled
-pub const ECANCELED = 89;
+ /// Bad executable
+ BADEXEC = 85,
-/// Identifier removed
-pub const EIDRM = 90;
+ /// Bad CPU type in executable
+ BADARCH = 86,
-/// No message of desired type
-pub const ENOMSG = 91;
+ /// Shared library version mismatch
+ SHLIBVERS = 87,
-/// Illegal byte sequence
-pub const EILSEQ = 92;
+ /// Malformed Macho file
+ BADMACHO = 88,
-/// Attribute not found
-pub const ENOATTR = 93;
+ /// Operation canceled
+ CANCELED = 89,
-/// Bad message
-pub const EBADMSG = 94;
+ /// Identifier removed
+ IDRM = 90,
-/// Reserved
-pub const EMULTIHOP = 95;
+ /// No message of desired type
+ NOMSG = 91,
-/// No message available on STREAM
-pub const ENODATA = 96;
+ /// Illegal byte sequence
+ ILSEQ = 92,
-/// Reserved
-pub const ENOLINK = 97;
+ /// Attribute not found
+ NOATTR = 93,
-/// No STREAM resources
-pub const ENOSR = 98;
+ /// Bad message
+ BADMSG = 94,
-/// Not a STREAM
-pub const ENOSTR = 99;
+ /// Reserved
+ MULTIHOP = 95,
-/// Protocol error
-pub const EPROTO = 100;
+ /// No message available on STREAM
+ NODATA = 96,
-/// STREAM ioctl timeout
-pub const ETIME = 101;
+ /// Reserved
+ NOLINK = 97,
-/// No such policy registered
-pub const ENOPOLICY = 103;
+ /// No STREAM resources
+ NOSR = 98,
-/// State not recoverable
-pub const ENOTRECOVERABLE = 104;
+ /// Not a STREAM
+ NOSTR = 99,
-/// Previous owner died
-pub const EOWNERDEAD = 105;
+ /// Protocol error
+ PROTO = 100,
-/// Interface output queue is full
-pub const EQFULL = 106;
+ /// STREAM ioctl timeout
+ TIME = 101,
-/// Must be equal largest errno
-pub const ELAST = 106;
+ /// No such policy registered
+ NOPOLICY = 103,
+
+ /// State not recoverable
+ NOTRECOVERABLE = 104,
+
+ /// Previous owner died
+ OWNERDEAD = 105,
+
+ /// Interface output queue is full
+ QFULL = 106,
+
+ _,
+};
pub const SIGSTKSZ = 131072;
pub const MINSIGSTKSZ = 32768;
diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig
index 573721749c..c13a3aea91 100644
--- a/lib/std/os/bits/dragonfly.zig
+++ b/lib/std/os/bits/dragonfly.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const maxInt = std.math.maxInt;
@@ -25,103 +20,108 @@ pub const gid_t = u32;
pub const time_t = isize;
pub const suseconds_t = c_long;
-pub const ENOTSUP = EOPNOTSUPP;
-pub const EWOULDBLOCK = EAGAIN;
-pub const EPERM = 1;
-pub const ENOENT = 2;
-pub const ESRCH = 3;
-pub const EINTR = 4;
-pub const EIO = 5;
-pub const ENXIO = 6;
-pub const E2BIG = 7;
-pub const ENOEXEC = 8;
-pub const EBADF = 9;
-pub const ECHILD = 10;
-pub const EDEADLK = 11;
-pub const ENOMEM = 12;
-pub const EACCES = 13;
-pub const EFAULT = 14;
-pub const ENOTBLK = 15;
-pub const EBUSY = 16;
-pub const EEXIST = 17;
-pub const EXDEV = 18;
-pub const ENODEV = 19;
-pub const ENOTDIR = 20;
-pub const EISDIR = 21;
-pub const EINVAL = 22;
-pub const ENFILE = 23;
-pub const EMFILE = 24;
-pub const ENOTTY = 25;
-pub const ETXTBSY = 26;
-pub const EFBIG = 27;
-pub const ENOSPC = 28;
-pub const ESPIPE = 29;
-pub const EROFS = 30;
-pub const EMLINK = 31;
-pub const EPIPE = 32;
-pub const EDOM = 33;
-pub const ERANGE = 34;
-pub const EAGAIN = 35;
-pub const EINPROGRESS = 36;
-pub const EALREADY = 37;
-pub const ENOTSOCK = 38;
-pub const EDESTADDRREQ = 39;
-pub const EMSGSIZE = 40;
-pub const EPROTOTYPE = 41;
-pub const ENOPROTOOPT = 42;
-pub const EPROTONOSUPPORT = 43;
-pub const ESOCKTNOSUPPORT = 44;
-pub const EOPNOTSUPP = 45;
-pub const EPFNOSUPPORT = 46;
-pub const EAFNOSUPPORT = 47;
-pub const EADDRINUSE = 48;
-pub const EADDRNOTAVAIL = 49;
-pub const ENETDOWN = 50;
-pub const ENETUNREACH = 51;
-pub const ENETRESET = 52;
-pub const ECONNABORTED = 53;
-pub const ECONNRESET = 54;
-pub const ENOBUFS = 55;
-pub const EISCONN = 56;
-pub const ENOTCONN = 57;
-pub const ESHUTDOWN = 58;
-pub const ETOOMANYREFS = 59;
-pub const ETIMEDOUT = 60;
-pub const ECONNREFUSED = 61;
-pub const ELOOP = 62;
-pub const ENAMETOOLONG = 63;
-pub const EHOSTDOWN = 64;
-pub const EHOSTUNREACH = 65;
-pub const ENOTEMPTY = 66;
-pub const EPROCLIM = 67;
-pub const EUSERS = 68;
-pub const EDQUOT = 69;
-pub const ESTALE = 70;
-pub const EREMOTE = 71;
-pub const EBADRPC = 72;
-pub const ERPCMISMATCH = 73;
-pub const EPROGUNAVAIL = 74;
-pub const EPROGMISMATCH = 75;
-pub const EPROCUNAVAIL = 76;
-pub const ENOLCK = 77;
-pub const ENOSYS = 78;
-pub const EFTYPE = 79;
-pub const EAUTH = 80;
-pub const ENEEDAUTH = 81;
-pub const EIDRM = 82;
-pub const ENOMSG = 83;
-pub const EOVERFLOW = 84;
-pub const ECANCELED = 85;
-pub const EILSEQ = 86;
-pub const ENOATTR = 87;
-pub const EDOOFUS = 88;
-pub const EBADMSG = 89;
-pub const EMULTIHOP = 90;
-pub const ENOLINK = 91;
-pub const EPROTO = 92;
-pub const ENOMEDIUM = 93;
-pub const ELAST = 99;
-pub const EASYNC = 99;
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
+
+ PERM = 1,
+ NOENT = 2,
+ SRCH = 3,
+ INTR = 4,
+ IO = 5,
+ NXIO = 6,
+ @"2BIG" = 7,
+ NOEXEC = 8,
+ BADF = 9,
+ CHILD = 10,
+ DEADLK = 11,
+ NOMEM = 12,
+ ACCES = 13,
+ FAULT = 14,
+ NOTBLK = 15,
+ BUSY = 16,
+ EXIST = 17,
+ XDEV = 18,
+ NODEV = 19,
+ NOTDIR = 20,
+ ISDIR = 21,
+ INVAL = 22,
+ NFILE = 23,
+ MFILE = 24,
+ NOTTY = 25,
+ TXTBSY = 26,
+ FBIG = 27,
+ NOSPC = 28,
+ SPIPE = 29,
+ ROFS = 30,
+ MLINK = 31,
+ PIPE = 32,
+ DOM = 33,
+ RANGE = 34,
+ /// This code is also used for `WOULDBLOCK`.
+ AGAIN = 35,
+ INPROGRESS = 36,
+ ALREADY = 37,
+ NOTSOCK = 38,
+ DESTADDRREQ = 39,
+ MSGSIZE = 40,
+ PROTOTYPE = 41,
+ NOPROTOOPT = 42,
+ PROTONOSUPPORT = 43,
+ SOCKTNOSUPPORT = 44,
+ /// This code is also used for `NOTSUP`.
+ OPNOTSUPP = 45,
+ PFNOSUPPORT = 46,
+ AFNOSUPPORT = 47,
+ ADDRINUSE = 48,
+ ADDRNOTAVAIL = 49,
+ NETDOWN = 50,
+ NETUNREACH = 51,
+ NETRESET = 52,
+ CONNABORTED = 53,
+ CONNRESET = 54,
+ NOBUFS = 55,
+ ISCONN = 56,
+ NOTCONN = 57,
+ SHUTDOWN = 58,
+ TOOMANYREFS = 59,
+ TIMEDOUT = 60,
+ CONNREFUSED = 61,
+ LOOP = 62,
+ NAMETOOLONG = 63,
+ HOSTDOWN = 64,
+ HOSTUNREACH = 65,
+ NOTEMPTY = 66,
+ PROCLIM = 67,
+ USERS = 68,
+ DQUOT = 69,
+ STALE = 70,
+ REMOTE = 71,
+ BADRPC = 72,
+ RPCMISMATCH = 73,
+ PROGUNAVAIL = 74,
+ PROGMISMATCH = 75,
+ PROCUNAVAIL = 76,
+ NOLCK = 77,
+ NOSYS = 78,
+ FTYPE = 79,
+ AUTH = 80,
+ NEEDAUTH = 81,
+ IDRM = 82,
+ NOMSG = 83,
+ OVERFLOW = 84,
+ CANCELED = 85,
+ ILSEQ = 86,
+ NOATTR = 87,
+ DOOFUS = 88,
+ BADMSG = 89,
+ MULTIHOP = 90,
+ NOLINK = 91,
+ PROTO = 92,
+ NOMEDIUM = 93,
+ ASYNC = 99,
+ _,
+};
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
@@ -168,6 +168,7 @@ pub const SA_NOCLDWAIT = 0x0020;
pub const SA_SIGINFO = 0x0040;
pub const PATH_MAX = 1024;
+pub const IOV_MAX = KERN_IOV_MAX;
pub const ino_t = c_ulong;
diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig
index 1805941993..51b7ef9f4d 100644
--- a/lib/std/os/bits/freebsd.zig
+++ b/lib/std/os/bits/freebsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
@@ -238,8 +233,10 @@ pub const CTL_DEBUG = 5;
pub const KERN_PROC = 14; // struct: process entries
pub const KERN_PROC_PATHNAME = 12; // path to executable
+pub const KERN_IOV_MAX = 35;
pub const PATH_MAX = 1024;
+pub const IOV_MAX = KERN_IOV_MAX;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
@@ -885,127 +882,134 @@ pub usingnamespace switch (builtin.target.cpu.arch) {
else => struct {},
};
-pub const EPERM = 1; // Operation not permitted
-pub const ENOENT = 2; // No such file or directory
-pub const ESRCH = 3; // No such process
-pub const EINTR = 4; // Interrupted system call
-pub const EIO = 5; // Input/output error
-pub const ENXIO = 6; // Device not configured
-pub const E2BIG = 7; // Argument list too long
-pub const ENOEXEC = 8; // Exec format error
-pub const EBADF = 9; // Bad file descriptor
-pub const ECHILD = 10; // No child processes
-pub const EDEADLK = 11; // Resource deadlock avoided
-// 11 was EAGAIN
-pub const ENOMEM = 12; // Cannot allocate memory
-pub const EACCES = 13; // Permission denied
-pub const EFAULT = 14; // Bad address
-pub const ENOTBLK = 15; // Block device required
-pub const EBUSY = 16; // Device busy
-pub const EEXIST = 17; // File exists
-pub const EXDEV = 18; // Cross-device link
-pub const ENODEV = 19; // Operation not supported by device
-pub const ENOTDIR = 20; // Not a directory
-pub const EISDIR = 21; // Is a directory
-pub const EINVAL = 22; // Invalid argument
-pub const ENFILE = 23; // Too many open files in system
-pub const EMFILE = 24; // Too many open files
-pub const ENOTTY = 25; // Inappropriate ioctl for device
-pub const ETXTBSY = 26; // Text file busy
-pub const EFBIG = 27; // File too large
-pub const ENOSPC = 28; // No space left on device
-pub const ESPIPE = 29; // Illegal seek
-pub const EROFS = 30; // Read-only filesystem
-pub const EMLINK = 31; // Too many links
-pub const EPIPE = 32; // Broken pipe
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
-// math software
-pub const EDOM = 33; // Numerical argument out of domain
-pub const ERANGE = 34; // Result too large
+ PERM = 1, // Operation not permitted
+ NOENT = 2, // No such file or directory
+ SRCH = 3, // No such process
+ INTR = 4, // Interrupted system call
+ IO = 5, // Input/output error
+ NXIO = 6, // Device not configured
+ @"2BIG" = 7, // Argument list too long
+ NOEXEC = 8, // Exec format error
+ BADF = 9, // Bad file descriptor
+ CHILD = 10, // No child processes
+ DEADLK = 11, // Resource deadlock avoided
+ // 11 was AGAIN
+ NOMEM = 12, // Cannot allocate memory
+ ACCES = 13, // Permission denied
+ FAULT = 14, // Bad address
+ NOTBLK = 15, // Block device required
+ BUSY = 16, // Device busy
+ EXIST = 17, // File exists
+ XDEV = 18, // Cross-device link
+ NODEV = 19, // Operation not supported by device
+ NOTDIR = 20, // Not a directory
+ ISDIR = 21, // Is a directory
+ INVAL = 22, // Invalid argument
+ NFILE = 23, // Too many open files in system
+ MFILE = 24, // Too many open files
+ NOTTY = 25, // Inappropriate ioctl for device
+ TXTBSY = 26, // Text file busy
+ FBIG = 27, // File too large
+ NOSPC = 28, // No space left on device
+ SPIPE = 29, // Illegal seek
+ ROFS = 30, // Read-only filesystem
+ MLINK = 31, // Too many links
+ PIPE = 32, // Broken pipe
-// non-blocking and interrupt i/o
-pub const EAGAIN = 35; // Resource temporarily unavailable
-pub const EWOULDBLOCK = EAGAIN; // Operation would block
-pub const EINPROGRESS = 36; // Operation now in progress
-pub const EALREADY = 37; // Operation already in progress
+ // math software
+ DOM = 33, // Numerical argument out of domain
+ RANGE = 34, // Result too large
-// ipc/network software -- argument errors
-pub const ENOTSOCK = 38; // Socket operation on non-socket
-pub const EDESTADDRREQ = 39; // Destination address required
-pub const EMSGSIZE = 40; // Message too long
-pub const EPROTOTYPE = 41; // Protocol wrong type for socket
-pub const ENOPROTOOPT = 42; // Protocol not available
-pub const EPROTONOSUPPORT = 43; // Protocol not supported
-pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
-pub const EOPNOTSUPP = 45; // Operation not supported
-pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
-pub const EPFNOSUPPORT = 46; // Protocol family not supported
-pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
-pub const EADDRINUSE = 48; // Address already in use
-pub const EADDRNOTAVAIL = 49; // Can't assign requested address
+ // non-blocking and interrupt i/o
-// ipc/network software -- operational errors
-pub const ENETDOWN = 50; // Network is down
-pub const ENETUNREACH = 51; // Network is unreachable
-pub const ENETRESET = 52; // Network dropped connection on reset
-pub const ECONNABORTED = 53; // Software caused connection abort
-pub const ECONNRESET = 54; // Connection reset by peer
-pub const ENOBUFS = 55; // No buffer space available
-pub const EISCONN = 56; // Socket is already connected
-pub const ENOTCONN = 57; // Socket is not connected
-pub const ESHUTDOWN = 58; // Can't send after socket shutdown
-pub const ETOOMANYREFS = 59; // Too many references: can't splice
-pub const ETIMEDOUT = 60; // Operation timed out
-pub const ECONNREFUSED = 61; // Connection refused
+ /// Resource temporarily unavailable
+ /// This code is also used for `WOULDBLOCK`: operation would block.
+ AGAIN = 35,
+ INPROGRESS = 36, // Operation now in progress
+ ALREADY = 37, // Operation already in progress
-pub const ELOOP = 62; // Too many levels of symbolic links
-pub const ENAMETOOLONG = 63; // File name too long
+ // ipc/network software -- argument errors
+ NOTSOCK = 38, // Socket operation on non-socket
+ DESTADDRREQ = 39, // Destination address required
+ MSGSIZE = 40, // Message too long
+ PROTOTYPE = 41, // Protocol wrong type for socket
+ NOPROTOOPT = 42, // Protocol not available
+ PROTONOSUPPORT = 43, // Protocol not supported
+ SOCKTNOSUPPORT = 44, // Socket type not supported
+ /// Operation not supported
+ /// This code is also used for `NOTSUP`.
+ OPNOTSUPP = 45,
+ PFNOSUPPORT = 46, // Protocol family not supported
+ AFNOSUPPORT = 47, // Address family not supported by protocol family
+ ADDRINUSE = 48, // Address already in use
+ ADDRNOTAVAIL = 49, // Can't assign requested address
-// should be rearranged
-pub const EHOSTDOWN = 64; // Host is down
-pub const EHOSTUNREACH = 65; // No route to host
-pub const ENOTEMPTY = 66; // Directory not empty
+ // ipc/network software -- operational errors
+ NETDOWN = 50, // Network is down
+ NETUNREACH = 51, // Network is unreachable
+ NETRESET = 52, // Network dropped connection on reset
+ CONNABORTED = 53, // Software caused connection abort
+ CONNRESET = 54, // Connection reset by peer
+ NOBUFS = 55, // No buffer space available
+ ISCONN = 56, // Socket is already connected
+ NOTCONN = 57, // Socket is not connected
+ SHUTDOWN = 58, // Can't send after socket shutdown
+ TOOMANYREFS = 59, // Too many references: can't splice
+ TIMEDOUT = 60, // Operation timed out
+ CONNREFUSED = 61, // Connection refused
-// quotas & mush
-pub const EPROCLIM = 67; // Too many processes
-pub const EUSERS = 68; // Too many users
-pub const EDQUOT = 69; // Disc quota exceeded
+ LOOP = 62, // Too many levels of symbolic links
+ NAMETOOLONG = 63, // File name too long
-// Network File System
-pub const ESTALE = 70; // Stale NFS file handle
-pub const EREMOTE = 71; // Too many levels of remote in path
-pub const EBADRPC = 72; // RPC struct is bad
-pub const ERPCMISMATCH = 73; // RPC version wrong
-pub const EPROGUNAVAIL = 74; // RPC prog. not avail
-pub const EPROGMISMATCH = 75; // Program version wrong
-pub const EPROCUNAVAIL = 76; // Bad procedure for program
+ // should be rearranged
+ HOSTDOWN = 64, // Host is down
+ HOSTUNREACH = 65, // No route to host
+ NOTEMPTY = 66, // Directory not empty
-pub const ENOLCK = 77; // No locks available
-pub const ENOSYS = 78; // Function not implemented
+ // quotas & mush
+ PROCLIM = 67, // Too many processes
+ USERS = 68, // Too many users
+ DQUOT = 69, // Disc quota exceeded
-pub const EFTYPE = 79; // Inappropriate file type or format
-pub const EAUTH = 80; // Authentication error
-pub const ENEEDAUTH = 81; // Need authenticator
-pub const EIDRM = 82; // Identifier removed
-pub const ENOMSG = 83; // No message of desired type
-pub const EOVERFLOW = 84; // Value too large to be stored in data type
-pub const ECANCELED = 85; // Operation canceled
-pub const EILSEQ = 86; // Illegal byte sequence
-pub const ENOATTR = 87; // Attribute not found
+ // Network File System
+ STALE = 70, // Stale NFS file handle
+ REMOTE = 71, // Too many levels of remote in path
+ BADRPC = 72, // RPC struct is bad
+ RPCMISMATCH = 73, // RPC version wrong
+ PROGUNAVAIL = 74, // RPC prog. not avail
+ PROGMISMATCH = 75, // Program version wrong
+ PROCUNAVAIL = 76, // Bad procedure for program
-pub const EDOOFUS = 88; // Programming error
+ NOLCK = 77, // No locks available
+ NOSYS = 78, // Function not implemented
-pub const EBADMSG = 89; // Bad message
-pub const EMULTIHOP = 90; // Multihop attempted
-pub const ENOLINK = 91; // Link has been severed
-pub const EPROTO = 92; // Protocol error
+ FTYPE = 79, // Inappropriate file type or format
+ AUTH = 80, // Authentication error
+ NEEDAUTH = 81, // Need authenticator
+ IDRM = 82, // Identifier removed
+ NOMSG = 83, // No message of desired type
+ OVERFLOW = 84, // Value too large to be stored in data type
+ CANCELED = 85, // Operation canceled
+ ILSEQ = 86, // Illegal byte sequence
+ NOATTR = 87, // Attribute not found
-pub const ENOTCAPABLE = 93; // Capabilities insufficient
-pub const ECAPMODE = 94; // Not permitted in capability mode
-pub const ENOTRECOVERABLE = 95; // State not recoverable
-pub const EOWNERDEAD = 96; // Previous owner died
+ DOOFUS = 88, // Programming error
-pub const ELAST = 96; // Must be equal largest errno
+ BADMSG = 89, // Bad message
+ MULTIHOP = 90, // Multihop attempted
+ NOLINK = 91, // Link has been severed
+ PROTO = 92, // Protocol error
+
+ NOTCAPABLE = 93, // Capabilities insufficient
+ CAPMODE = 94, // Not permitted in capability mode
+ NOTRECOVERABLE = 95, // State not recoverable
+ OWNERDEAD = 96, // Previous owner died
+ _,
+};
pub const MINSIGSTKSZ = switch (builtin.target.cpu.arch) {
.i386, .x86_64 => 2048,
diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig
index b3ea4aa0e2..620bf23414 100644
--- a/lib/std/os/bits/haiku.zig
+++ b/lib/std/os/bits/haiku.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const maxInt = std.math.maxInt;
@@ -734,125 +729,130 @@ pub const sigset_t = extern struct {
__bits: [_SIG_WORDS]u32,
};
-pub const EPERM = -0x7ffffff1; // Operation not permitted
-pub const ENOENT = -0x7fff9ffd; // No such file or directory
-pub const ESRCH = -0x7fff8ff3; // No such process
-pub const EINTR = -0x7ffffff6; // Interrupted system call
-pub const EIO = -0x7fffffff; // Input/output error
-pub const ENXIO = -0x7fff8ff5; // Device not configured
-pub const E2BIG = -0x7fff8fff; // Argument list too long
-pub const ENOEXEC = -0x7fffecfe; // Exec format error
-pub const ECHILD = -0x7fff8ffe; // No child processes
-pub const EDEADLK = -0x7fff8ffd; // Resource deadlock avoided
-pub const ENOMEM = -0x80000000; // Cannot allocate memory
-pub const EACCES = -0x7ffffffe; // Permission denied
-pub const EFAULT = -0x7fffecff; // Bad address
-pub const EBUSY = -0x7ffffff2; // Device busy
-pub const EEXIST = -0x7fff9ffe; // File exists
-pub const EXDEV = -0x7fff9ff5; // Cross-device link
-pub const ENODEV = -0x7fff8ff9; // Operation not supported by device
-pub const ENOTDIR = -0x7fff9ffb; // Not a directory
-pub const EISDIR = -0x7fff9ff7; // Is a directory
-pub const EINVAL = -0x7ffffffb; // Invalid argument
-pub const ENFILE = -0x7fff8ffa; // Too many open files in system
-pub const EMFILE = -0x7fff9ff6; // Too many open files
-pub const ENOTTY = -0x7fff8ff6; // Inappropriate ioctl for device
-pub const ETXTBSY = -0x7fff8fc5; // Text file busy
-pub const EFBIG = -0x7fff8ffc; // File too large
-pub const ENOSPC = -0x7fff9ff9; // No space left on device
-pub const ESPIPE = -0x7fff8ff4; // Illegal seek
-pub const EROFS = -0x7fff9ff8; // Read-only filesystem
-pub const EMLINK = -0x7fff8ffb; // Too many links
-pub const EPIPE = -0x7fff9ff3; // Broken pipe
-pub const EBADF = -0x7fffa000; // Bad file descriptor
+pub const E = enum(i32) {
+ /// No error occurred.
+ SUCCESS = 0,
+ PERM = -0x7ffffff1, // Operation not permitted
+ NOENT = -0x7fff9ffd, // No such file or directory
+ SRCH = -0x7fff8ff3, // No such process
+ INTR = -0x7ffffff6, // Interrupted system call
+ IO = -0x7fffffff, // Input/output error
+ NXIO = -0x7fff8ff5, // Device not configured
+ @"2BIG" = -0x7fff8fff, // Argument list too long
+ NOEXEC = -0x7fffecfe, // Exec format error
+ CHILD = -0x7fff8ffe, // No child processes
+ DEADLK = -0x7fff8ffd, // Resource deadlock avoided
+ NOMEM = -0x80000000, // Cannot allocate memory
+ ACCES = -0x7ffffffe, // Permission denied
+ FAULT = -0x7fffecff, // Bad address
+ BUSY = -0x7ffffff2, // Device busy
+ EXIST = -0x7fff9ffe, // File exists
+ XDEV = -0x7fff9ff5, // Cross-device link
+ NODEV = -0x7fff8ff9, // Operation not supported by device
+ NOTDIR = -0x7fff9ffb, // Not a directory
+ ISDIR = -0x7fff9ff7, // Is a directory
+ INVAL = -0x7ffffffb, // Invalid argument
+ NFILE = -0x7fff8ffa, // Too many open files in system
+ MFILE = -0x7fff9ff6, // Too many open files
+ NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device
+ TXTBSY = -0x7fff8fc5, // Text file busy
+ FBIG = -0x7fff8ffc, // File too large
+ NOSPC = -0x7fff9ff9, // No space left on device
+ SPIPE = -0x7fff8ff4, // Illegal seek
+ ROFS = -0x7fff9ff8, // Read-only filesystem
+ MLINK = -0x7fff8ffb, // Too many links
+ PIPE = -0x7fff9ff3, // Broken pipe
+ BADF = -0x7fffa000, // Bad file descriptor
-// math software
-pub const EDOM = 33; // Numerical argument out of domain
-pub const ERANGE = 34; // Result too large
+ // math software
+ DOM = 33, // Numerical argument out of domain
+ RANGE = 34, // Result too large
-// non-blocking and interrupt i/o
-pub const EAGAIN = -0x7ffffff5;
-pub const EWOULDBLOCK = -0x7ffffff5;
-pub const EINPROGRESS = -0x7fff8fdc;
-pub const EALREADY = -0x7fff8fdb;
+ // non-blocking and interrupt i/o
-// ipc/network software -- argument errors
-pub const ENOTSOCK = 38; // Socket operation on non-socket
-pub const EDESTADDRREQ = 39; // Destination address required
-pub const EMSGSIZE = 40; // Message too long
-pub const EPROTOTYPE = 41; // Protocol wrong type for socket
-pub const ENOPROTOOPT = 42; // Protocol not available
-pub const EPROTONOSUPPORT = 43; // Protocol not supported
-pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
-pub const EOPNOTSUPP = 45; // Operation not supported
-pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
-pub const EPFNOSUPPORT = 46; // Protocol family not supported
-pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
-pub const EADDRINUSE = 48; // Address already in use
-pub const EADDRNOTAVAIL = 49; // Can't assign requested address
+ /// Also used for `WOULDBLOCK`.
+ AGAIN = -0x7ffffff5,
+ INPROGRESS = -0x7fff8fdc,
+ ALREADY = -0x7fff8fdb,
-// ipc/network software -- operational errors
-pub const ENETDOWN = 50; // Network is down
-pub const ENETUNREACH = 51; // Network is unreachable
-pub const ENETRESET = 52; // Network dropped connection on reset
-pub const ECONNABORTED = 53; // Software caused connection abort
-pub const ECONNRESET = 54; // Connection reset by peer
-pub const ENOBUFS = 55; // No buffer space available
-pub const EISCONN = 56; // Socket is already connected
-pub const ENOTCONN = 57; // Socket is not connected
-pub const ESHUTDOWN = 58; // Can't send after socket shutdown
-pub const ETOOMANYREFS = 59; // Too many references: can't splice
-pub const ETIMEDOUT = 60; // Operation timed out
-pub const ECONNREFUSED = 61; // Connection refused
+ // ipc/network software -- argument errors
+ NOTSOCK = 38, // Socket operation on non-socket
+ DESTADDRREQ = 39, // Destination address required
+ MSGSIZE = 40, // Message too long
+ PROTOTYPE = 41, // Protocol wrong type for socket
+ NOPROTOOPT = 42, // Protocol not available
+ PROTONOSUPPORT = 43, // Protocol not supported
+ SOCKTNOSUPPORT = 44, // Socket type not supported
+ /// Also used for `NOTSUP`.
+ OPNOTSUPP = 45, // Operation not supported
+ PFNOSUPPORT = 46, // Protocol family not supported
+ AFNOSUPPORT = 47, // Address family not supported by protocol family
+ ADDRINUSE = 48, // Address already in use
+ ADDRNOTAVAIL = 49, // Can't assign requested address
-pub const ELOOP = 62; // Too many levels of symbolic links
-pub const ENAMETOOLONG = 63; // File name too long
+ // ipc/network software -- operational errors
+ NETDOWN = 50, // Network is down
+ NETUNREACH = 51, // Network is unreachable
+ NETRESET = 52, // Network dropped connection on reset
+ CONNABORTED = 53, // Software caused connection abort
+ CONNRESET = 54, // Connection reset by peer
+ NOBUFS = 55, // No buffer space available
+ ISCONN = 56, // Socket is already connected
+ NOTCONN = 57, // Socket is not connected
+ SHUTDOWN = 58, // Can't send after socket shutdown
+ TOOMANYREFS = 59, // Too many references: can't splice
+ TIMEDOUT = 60, // Operation timed out
+ CONNREFUSED = 61, // Connection refused
-// should be rearranged
-pub const EHOSTDOWN = 64; // Host is down
-pub const EHOSTUNREACH = 65; // No route to host
-pub const ENOTEMPTY = 66; // Directory not empty
+ LOOP = 62, // Too many levels of symbolic links
+ NAMETOOLONG = 63, // File name too long
-// quotas & mush
-pub const EPROCLIM = 67; // Too many processes
-pub const EUSERS = 68; // Too many users
-pub const EDQUOT = 69; // Disc quota exceeded
+ // should be rearranged
+ HOSTDOWN = 64, // Host is down
+ HOSTUNREACH = 65, // No route to host
+ NOTEMPTY = 66, // Directory not empty
-// Network File System
-pub const ESTALE = 70; // Stale NFS file handle
-pub const EREMOTE = 71; // Too many levels of remote in path
-pub const EBADRPC = 72; // RPC struct is bad
-pub const ERPCMISMATCH = 73; // RPC version wrong
-pub const EPROGUNAVAIL = 74; // RPC prog. not avail
-pub const EPROGMISMATCH = 75; // Program version wrong
-pub const EPROCUNAVAIL = 76; // Bad procedure for program
+ // quotas & mush
+ PROCLIM = 67, // Too many processes
+ USERS = 68, // Too many users
+ DQUOT = 69, // Disc quota exceeded
-pub const ENOLCK = 77; // No locks available
-pub const ENOSYS = 78; // Function not implemented
+ // Network File System
+ STALE = 70, // Stale NFS file handle
+ REMOTE = 71, // Too many levels of remote in path
+ BADRPC = 72, // RPC struct is bad
+ RPCMISMATCH = 73, // RPC version wrong
+ PROGUNAVAIL = 74, // RPC prog. not avail
+ PROGMISMATCH = 75, // Program version wrong
+ PROCUNAVAIL = 76, // Bad procedure for program
-pub const EFTYPE = 79; // Inappropriate file type or format
-pub const EAUTH = 80; // Authentication error
-pub const ENEEDAUTH = 81; // Need authenticator
-pub const EIDRM = 82; // Identifier removed
-pub const ENOMSG = 83; // No message of desired type
-pub const EOVERFLOW = 84; // Value too large to be stored in data type
-pub const ECANCELED = 85; // Operation canceled
-pub const EILSEQ = 86; // Illegal byte sequence
-pub const ENOATTR = 87; // Attribute not found
+ NOLCK = 77, // No locks available
+ NOSYS = 78, // Function not implemented
-pub const EDOOFUS = 88; // Programming error
+ FTYPE = 79, // Inappropriate file type or format
+ AUTH = 80, // Authentication error
+ NEEDAUTH = 81, // Need authenticator
+ IDRM = 82, // Identifier removed
+ NOMSG = 83, // No message of desired type
+ OVERFLOW = 84, // Value too large to be stored in data type
+ CANCELED = 85, // Operation canceled
+ ILSEQ = 86, // Illegal byte sequence
+ NOATTR = 87, // Attribute not found
-pub const EBADMSG = 89; // Bad message
-pub const EMULTIHOP = 90; // Multihop attempted
-pub const ENOLINK = 91; // Link has been severed
-pub const EPROTO = 92; // Protocol error
+ DOOFUS = 88, // Programming error
-pub const ENOTCAPABLE = 93; // Capabilities insufficient
-pub const ECAPMODE = 94; // Not permitted in capability mode
-pub const ENOTRECOVERABLE = 95; // State not recoverable
-pub const EOWNERDEAD = 96; // Previous owner died
+ BADMSG = 89, // Bad message
+ MULTIHOP = 90, // Multihop attempted
+ NOLINK = 91, // Link has been severed
+ PROTO = 92, // Protocol error
-pub const ELAST = 96; // Must be equal largest errno
+ NOTCAPABLE = 93, // Capabilities insufficient
+ CAPMODE = 94, // Not permitted in capability mode
+ NOTRECOVERABLE = 95, // State not recoverable
+ OWNERDEAD = 96, // Previous owner died
+
+ _,
+};
pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
.i386, .x86_64 => 2048,
diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig
index fdf240e954..653fb8f1e1 100644
--- a/lib/std/os/bits/linux.zig
+++ b/lib/std/os/bits/linux.zig
@@ -1,17 +1,12 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const maxInt = std.math.maxInt;
const arch = @import("builtin").target.cpu.arch;
pub usingnamespace @import("posix.zig");
-pub usingnamespace switch (arch) {
- .mips, .mipsel => @import("linux/errno-mips.zig"),
- .sparc, .sparcel, .sparcv9 => @import("linux/errno-sparc.zig"),
- else => @import("linux/errno-generic.zig"),
+pub const E = switch (arch) {
+ .mips, .mipsel => @import("linux/errno/mips.zig").E,
+ .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E,
+ else => @import("linux/errno/generic.zig").E,
};
pub usingnamespace switch (arch) {
@@ -887,6 +882,7 @@ pub const CLONE_VM = 0x00000100;
pub const CLONE_FS = 0x00000200;
pub const CLONE_FILES = 0x00000400;
pub const CLONE_SIGHAND = 0x00000800;
+pub const CLONE_PIDFD = 0x00001000;
pub const CLONE_PTRACE = 0x00002000;
pub const CLONE_VFORK = 0x00004000;
pub const CLONE_PARENT = 0x00008000;
@@ -911,6 +907,8 @@ pub const CLONE_IO = 0x80000000;
/// Clear any signal handler and reset to SIG_DFL.
pub const CLONE_CLEAR_SIGHAND = 0x100000000;
+/// Clone into a specific cgroup given the right permissions.
+pub const CLONE_INTO_CGROUP = 0x200000000;
// cloning flags intersect with CSIGNAL so can be used with unshare and clone3 syscalls only.
@@ -1131,6 +1129,9 @@ pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;
+pub const SFD_CLOEXEC = O_CLOEXEC;
+pub const SFD_NONBLOCK = O_NONBLOCK;
+
pub const signalfd_siginfo = extern struct {
signo: u32,
errno: i32,
@@ -1659,6 +1660,13 @@ pub const io_uring_cqe = extern struct {
/// result code for this event
res: i32,
flags: u32,
+
+ pub fn err(self: io_uring_cqe) E {
+ if (self.res > -4096 and self.res < 0) {
+ return @intToEnum(E, -self.res);
+ }
+ return .SUCCESS;
+ }
};
// io_uring_cqe.flags
diff --git a/lib/std/os/bits/linux/arm-eabi.zig b/lib/std/os/bits/linux/arm-eabi.zig
index 335ea074ec..91ca2b32d2 100644
--- a/lib/std/os/bits/linux/arm-eabi.zig
+++ b/lib/std/os/bits/linux/arm-eabi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// arm-eabi-specific declarations that are intended to be imported into the POSIX namespace.
const std = @import("../../../std.zig");
const linux = std.os.linux;
diff --git a/lib/std/os/bits/linux/arm64.zig b/lib/std/os/bits/linux/arm64.zig
index e0771e7f66..67c77ce186 100644
--- a/lib/std/os/bits/linux/arm64.zig
+++ b/lib/std/os/bits/linux/arm64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// arm64-specific declarations that are intended to be imported into the POSIX namespace.
// This does include Linux-only APIs.
diff --git a/lib/std/os/bits/linux/errno-generic.zig b/lib/std/os/bits/linux/errno-generic.zig
deleted file mode 100644
index f55aa3698e..0000000000
--- a/lib/std/os/bits/linux/errno-generic.zig
+++ /dev/null
@@ -1,462 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-/// Operation not permitted
-pub const EPERM = 1;
-
-/// No such file or directory
-pub const ENOENT = 2;
-
-/// No such process
-pub const ESRCH = 3;
-
-/// Interrupted system call
-pub const EINTR = 4;
-
-/// I/O error
-pub const EIO = 5;
-
-/// No such device or address
-pub const ENXIO = 6;
-
-/// Arg list too long
-pub const E2BIG = 7;
-
-/// Exec format error
-pub const ENOEXEC = 8;
-
-/// Bad file number
-pub const EBADF = 9;
-
-/// No child processes
-pub const ECHILD = 10;
-
-/// Try again
-pub const EAGAIN = 11;
-
-/// Out of memory
-pub const ENOMEM = 12;
-
-/// Permission denied
-pub const EACCES = 13;
-
-/// Bad address
-pub const EFAULT = 14;
-
-/// Block device required
-pub const ENOTBLK = 15;
-
-/// Device or resource busy
-pub const EBUSY = 16;
-
-/// File exists
-pub const EEXIST = 17;
-
-/// Cross-device link
-pub const EXDEV = 18;
-
-/// No such device
-pub const ENODEV = 19;
-
-/// Not a directory
-pub const ENOTDIR = 20;
-
-/// Is a directory
-pub const EISDIR = 21;
-
-/// Invalid argument
-pub const EINVAL = 22;
-
-/// File table overflow
-pub const ENFILE = 23;
-
-/// Too many open files
-pub const EMFILE = 24;
-
-/// Not a typewriter
-pub const ENOTTY = 25;
-
-/// Text file busy
-pub const ETXTBSY = 26;
-
-/// File too large
-pub const EFBIG = 27;
-
-/// No space left on device
-pub const ENOSPC = 28;
-
-/// Illegal seek
-pub const ESPIPE = 29;
-
-/// Read-only file system
-pub const EROFS = 30;
-
-/// Too many links
-pub const EMLINK = 31;
-
-/// Broken pipe
-pub const EPIPE = 32;
-
-/// Math argument out of domain of func
-pub const EDOM = 33;
-
-/// Math result not representable
-pub const ERANGE = 34;
-
-/// Resource deadlock would occur
-pub const EDEADLK = 35;
-
-/// File name too long
-pub const ENAMETOOLONG = 36;
-
-/// No record locks available
-pub const ENOLCK = 37;
-
-/// Function not implemented
-pub const ENOSYS = 38;
-
-/// Directory not empty
-pub const ENOTEMPTY = 39;
-
-/// Too many symbolic links encountered
-pub const ELOOP = 40;
-
-/// Operation would block
-pub const EWOULDBLOCK = EAGAIN;
-
-/// No message of desired type
-pub const ENOMSG = 42;
-
-/// Identifier removed
-pub const EIDRM = 43;
-
-/// Channel number out of range
-pub const ECHRNG = 44;
-
-/// Level 2 not synchronized
-pub const EL2NSYNC = 45;
-
-/// Level 3 halted
-pub const EL3HLT = 46;
-
-/// Level 3 reset
-pub const EL3RST = 47;
-
-/// Link number out of range
-pub const ELNRNG = 48;
-
-/// Protocol driver not attached
-pub const EUNATCH = 49;
-
-/// No CSI structure available
-pub const ENOCSI = 50;
-
-/// Level 2 halted
-pub const EL2HLT = 51;
-
-/// Invalid exchange
-pub const EBADE = 52;
-
-/// Invalid request descriptor
-pub const EBADR = 53;
-
-/// Exchange full
-pub const EXFULL = 54;
-
-/// No anode
-pub const ENOANO = 55;
-
-/// Invalid request code
-pub const EBADRQC = 56;
-
-/// Invalid slot
-pub const EBADSLT = 57;
-
-/// Bad font file format
-pub const EBFONT = 59;
-
-/// Device not a stream
-pub const ENOSTR = 60;
-
-/// No data available
-pub const ENODATA = 61;
-
-/// Timer expired
-pub const ETIME = 62;
-
-/// Out of streams resources
-pub const ENOSR = 63;
-
-/// Machine is not on the network
-pub const ENONET = 64;
-
-/// Package not installed
-pub const ENOPKG = 65;
-
-/// Object is remote
-pub const EREMOTE = 66;
-
-/// Link has been severed
-pub const ENOLINK = 67;
-
-/// Advertise error
-pub const EADV = 68;
-
-/// Srmount error
-pub const ESRMNT = 69;
-
-/// Communication error on send
-pub const ECOMM = 70;
-
-/// Protocol error
-pub const EPROTO = 71;
-
-/// Multihop attempted
-pub const EMULTIHOP = 72;
-
-/// RFS specific error
-pub const EDOTDOT = 73;
-
-/// Not a data message
-pub const EBADMSG = 74;
-
-/// Value too large for defined data type
-pub const EOVERFLOW = 75;
-
-/// Name not unique on network
-pub const ENOTUNIQ = 76;
-
-/// File descriptor in bad state
-pub const EBADFD = 77;
-
-/// Remote address changed
-pub const EREMCHG = 78;
-
-/// Can not access a needed shared library
-pub const ELIBACC = 79;
-
-/// Accessing a corrupted shared library
-pub const ELIBBAD = 80;
-
-/// .lib section in a.out corrupted
-pub const ELIBSCN = 81;
-
-/// Attempting to link in too many shared libraries
-pub const ELIBMAX = 82;
-
-/// Cannot exec a shared library directly
-pub const ELIBEXEC = 83;
-
-/// Illegal byte sequence
-pub const EILSEQ = 84;
-
-/// Interrupted system call should be restarted
-pub const ERESTART = 85;
-
-/// Streams pipe error
-pub const ESTRPIPE = 86;
-
-/// Too many users
-pub const EUSERS = 87;
-
-/// Socket operation on non-socket
-pub const ENOTSOCK = 88;
-
-/// Destination address required
-pub const EDESTADDRREQ = 89;
-
-/// Message too long
-pub const EMSGSIZE = 90;
-
-/// Protocol wrong type for socket
-pub const EPROTOTYPE = 91;
-
-/// Protocol not available
-pub const ENOPROTOOPT = 92;
-
-/// Protocol not supported
-pub const EPROTONOSUPPORT = 93;
-
-/// Socket type not supported
-pub const ESOCKTNOSUPPORT = 94;
-
-/// Operation not supported on transport endpoint
-pub const EOPNOTSUPP = 95;
-pub const ENOTSUP = EOPNOTSUPP;
-
-/// Protocol family not supported
-pub const EPFNOSUPPORT = 96;
-
-/// Address family not supported by protocol
-pub const EAFNOSUPPORT = 97;
-
-/// Address already in use
-pub const EADDRINUSE = 98;
-
-/// Cannot assign requested address
-pub const EADDRNOTAVAIL = 99;
-
-/// Network is down
-pub const ENETDOWN = 100;
-
-/// Network is unreachable
-pub const ENETUNREACH = 101;
-
-/// Network dropped connection because of reset
-pub const ENETRESET = 102;
-
-/// Software caused connection abort
-pub const ECONNABORTED = 103;
-
-/// Connection reset by peer
-pub const ECONNRESET = 104;
-
-/// No buffer space available
-pub const ENOBUFS = 105;
-
-/// Transport endpoint is already connected
-pub const EISCONN = 106;
-
-/// Transport endpoint is not connected
-pub const ENOTCONN = 107;
-
-/// Cannot send after transport endpoint shutdown
-pub const ESHUTDOWN = 108;
-
-/// Too many references: cannot splice
-pub const ETOOMANYREFS = 109;
-
-/// Connection timed out
-pub const ETIMEDOUT = 110;
-
-/// Connection refused
-pub const ECONNREFUSED = 111;
-
-/// Host is down
-pub const EHOSTDOWN = 112;
-
-/// No route to host
-pub const EHOSTUNREACH = 113;
-
-/// Operation already in progress
-pub const EALREADY = 114;
-
-/// Operation now in progress
-pub const EINPROGRESS = 115;
-
-/// Stale NFS file handle
-pub const ESTALE = 116;
-
-/// Structure needs cleaning
-pub const EUCLEAN = 117;
-
-/// Not a XENIX named type file
-pub const ENOTNAM = 118;
-
-/// No XENIX semaphores available
-pub const ENAVAIL = 119;
-
-/// Is a named type file
-pub const EISNAM = 120;
-
-/// Remote I/O error
-pub const EREMOTEIO = 121;
-
-/// Quota exceeded
-pub const EDQUOT = 122;
-
-/// No medium found
-pub const ENOMEDIUM = 123;
-
-/// Wrong medium type
-pub const EMEDIUMTYPE = 124;
-
-/// Operation canceled
-pub const ECANCELED = 125;
-
-/// Required key not available
-pub const ENOKEY = 126;
-
-/// Key has expired
-pub const EKEYEXPIRED = 127;
-
-/// Key has been revoked
-pub const EKEYREVOKED = 128;
-
-/// Key was rejected by service
-pub const EKEYREJECTED = 129;
-
-// for robust mutexes
-
-/// Owner died
-pub const EOWNERDEAD = 130;
-
-/// State not recoverable
-pub const ENOTRECOVERABLE = 131;
-
-/// Operation not possible due to RF-kill
-pub const ERFKILL = 132;
-
-/// Memory page has hardware error
-pub const EHWPOISON = 133;
-
-// nameserver query return codes
-
-/// DNS server returned answer with no data
-pub const ENSROK = 0;
-
-/// DNS server returned answer with no data
-pub const ENSRNODATA = 160;
-
-/// DNS server claims query was misformatted
-pub const ENSRFORMERR = 161;
-
-/// DNS server returned general failure
-pub const ENSRSERVFAIL = 162;
-
-/// Domain name not found
-pub const ENSRNOTFOUND = 163;
-
-/// DNS server does not implement requested operation
-pub const ENSRNOTIMP = 164;
-
-/// DNS server refused query
-pub const ENSRREFUSED = 165;
-
-/// Misformatted DNS query
-pub const ENSRBADQUERY = 166;
-
-/// Misformatted domain name
-pub const ENSRBADNAME = 167;
-
-/// Unsupported address family
-pub const ENSRBADFAMILY = 168;
-
-/// Misformatted DNS reply
-pub const ENSRBADRESP = 169;
-
-/// Could not contact DNS servers
-pub const ENSRCONNREFUSED = 170;
-
-/// Timeout while contacting DNS servers
-pub const ENSRTIMEOUT = 171;
-
-/// End of file
-pub const ENSROF = 172;
-
-/// Error reading file
-pub const ENSRFILE = 173;
-
-/// Out of memory
-pub const ENSRNOMEM = 174;
-
-/// Application terminated lookup
-pub const ENSRDESTRUCTION = 175;
-
-/// Domain name is too long
-pub const ENSRQUERYDOMAINTOOLONG = 176;
-
-/// Domain name is too long
-pub const ENSRCNAMELOOP = 177;
diff --git a/lib/std/os/bits/linux/errno-mips.zig b/lib/std/os/bits/linux/errno-mips.zig
deleted file mode 100644
index 2c22290288..0000000000
--- a/lib/std/os/bits/linux/errno-mips.zig
+++ /dev/null
@@ -1,143 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
-// These are MIPS ABI compatible.
-
-pub const EPERM = 1;
-pub const ENOENT = 2;
-pub const ESRCH = 3;
-pub const EINTR = 4;
-pub const EIO = 5;
-pub const ENXIO = 6;
-pub const E2BIG = 7;
-pub const ENOEXEC = 8;
-pub const EBADF = 9;
-pub const ECHILD = 10;
-pub const EAGAIN = 11;
-pub const ENOMEM = 12;
-pub const EACCES = 13;
-pub const EFAULT = 14;
-pub const ENOTBLK = 15;
-pub const EBUSY = 16;
-pub const EEXIST = 17;
-pub const EXDEV = 18;
-pub const ENODEV = 19;
-pub const ENOTDIR = 20;
-pub const EISDIR = 21;
-pub const EINVAL = 22;
-pub const ENFILE = 23;
-pub const EMFILE = 24;
-pub const ENOTTY = 25;
-pub const ETXTBSY = 26;
-pub const EFBIG = 27;
-pub const ENOSPC = 28;
-pub const ESPIPE = 29;
-pub const EROFS = 30;
-pub const EMLINK = 31;
-pub const EPIPE = 32;
-pub const EDOM = 33;
-pub const ERANGE = 34;
-
-pub const ENOMSG = 35;
-pub const EIDRM = 36;
-pub const ECHRNG = 37;
-pub const EL2NSYNC = 38;
-pub const EL3HLT = 39;
-pub const EL3RST = 40;
-pub const ELNRNG = 41;
-pub const EUNATCH = 42;
-pub const ENOCSI = 43;
-pub const EL2HLT = 44;
-pub const EDEADLK = 45;
-pub const ENOLCK = 46;
-pub const EBADE = 50;
-pub const EBADR = 51;
-pub const EXFULL = 52;
-pub const ENOANO = 53;
-pub const EBADRQC = 54;
-pub const EBADSLT = 55;
-pub const EDEADLOCK = 56;
-pub const EBFONT = 59;
-pub const ENOSTR = 60;
-pub const ENODATA = 61;
-pub const ETIME = 62;
-pub const ENOSR = 63;
-pub const ENONET = 64;
-pub const ENOPKG = 65;
-pub const EREMOTE = 66;
-pub const ENOLINK = 67;
-pub const EADV = 68;
-pub const ESRMNT = 69;
-pub const ECOMM = 70;
-pub const EPROTO = 71;
-pub const EDOTDOT = 73;
-pub const EMULTIHOP = 74;
-pub const EBADMSG = 77;
-pub const ENAMETOOLONG = 78;
-pub const EOVERFLOW = 79;
-pub const ENOTUNIQ = 80;
-pub const EBADFD = 81;
-pub const EREMCHG = 82;
-pub const ELIBACC = 83;
-pub const ELIBBAD = 84;
-pub const ELIBSCN = 85;
-pub const ELIBMAX = 86;
-pub const ELIBEXEC = 87;
-pub const EILSEQ = 88;
-pub const ENOSYS = 89;
-pub const ELOOP = 90;
-pub const ERESTART = 91;
-pub const ESTRPIPE = 92;
-pub const ENOTEMPTY = 93;
-pub const EUSERS = 94;
-pub const ENOTSOCK = 95;
-pub const EDESTADDRREQ = 96;
-pub const EMSGSIZE = 97;
-pub const EPROTOTYPE = 98;
-pub const ENOPROTOOPT = 99;
-pub const EPROTONOSUPPORT = 120;
-pub const ESOCKTNOSUPPORT = 121;
-pub const EOPNOTSUPP = 122;
-pub const ENOTSUP = EOPNOTSUPP;
-pub const EPFNOSUPPORT = 123;
-pub const EAFNOSUPPORT = 124;
-pub const EADDRINUSE = 125;
-pub const EADDRNOTAVAIL = 126;
-pub const ENETDOWN = 127;
-pub const ENETUNREACH = 128;
-pub const ENETRESET = 129;
-pub const ECONNABORTED = 130;
-pub const ECONNRESET = 131;
-pub const ENOBUFS = 132;
-pub const EISCONN = 133;
-pub const ENOTCONN = 134;
-pub const EUCLEAN = 135;
-pub const ENOTNAM = 137;
-pub const ENAVAIL = 138;
-pub const EISNAM = 139;
-pub const EREMOTEIO = 140;
-pub const ESHUTDOWN = 143;
-pub const ETOOMANYREFS = 144;
-pub const ETIMEDOUT = 145;
-pub const ECONNREFUSED = 146;
-pub const EHOSTDOWN = 147;
-pub const EHOSTUNREACH = 148;
-pub const EWOULDBLOCK = EAGAIN;
-pub const EALREADY = 149;
-pub const EINPROGRESS = 150;
-pub const ESTALE = 151;
-pub const ECANCELED = 158;
-pub const ENOMEDIUM = 159;
-pub const EMEDIUMTYPE = 160;
-pub const ENOKEY = 161;
-pub const EKEYEXPIRED = 162;
-pub const EKEYREVOKED = 163;
-pub const EKEYREJECTED = 164;
-pub const EOWNERDEAD = 165;
-pub const ENOTRECOVERABLE = 166;
-pub const ERFKILL = 167;
-pub const EHWPOISON = 168;
-pub const EDQUOT = 1133;
diff --git a/lib/std/os/bits/linux/errno-sparc.zig b/lib/std/os/bits/linux/errno-sparc.zig
deleted file mode 100644
index 94b696fc35..0000000000
--- a/lib/std/os/bits/linux/errno-sparc.zig
+++ /dev/null
@@ -1,145 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
-// These match the SunOS error numbering scheme.
-
-pub const EPERM = 1;
-pub const ENOENT = 2;
-pub const ESRCH = 3;
-pub const EINTR = 4;
-pub const EIO = 5;
-pub const ENXIO = 6;
-pub const E2BIG = 7;
-pub const ENOEXEC = 8;
-pub const EBADF = 9;
-pub const ECHILD = 10;
-pub const EAGAIN = 11;
-pub const ENOMEM = 12;
-pub const EACCES = 13;
-pub const EFAULT = 14;
-pub const ENOTBLK = 15;
-pub const EBUSY = 16;
-pub const EEXIST = 17;
-pub const EXDEV = 18;
-pub const ENODEV = 19;
-pub const ENOTDIR = 20;
-pub const EISDIR = 21;
-pub const EINVAL = 22;
-pub const ENFILE = 23;
-pub const EMFILE = 24;
-pub const ENOTTY = 25;
-pub const ETXTBSY = 26;
-pub const EFBIG = 27;
-pub const ENOSPC = 28;
-pub const ESPIPE = 29;
-pub const EROFS = 30;
-pub const EMLINK = 31;
-pub const EPIPE = 32;
-pub const EDOM = 33;
-pub const ERANGE = 34;
-
-pub const EWOULDBLOCK = EAGAIN;
-pub const EINPROGRESS = 36;
-pub const EALREADY = 37;
-pub const ENOTSOCK = 38;
-pub const EDESTADDRREQ = 39;
-pub const EMSGSIZE = 40;
-pub const EPROTOTYPE = 41;
-pub const ENOPROTOOPT = 42;
-pub const EPROTONOSUPPORT = 43;
-pub const ESOCKTNOSUPPORT = 44;
-pub const EOPNOTSUPP = 45;
-pub const ENOTSUP = EOPNOTSUPP;
-pub const EPFNOSUPPORT = 46;
-pub const EAFNOSUPPORT = 47;
-pub const EADDRINUSE = 48;
-pub const EADDRNOTAVAIL = 49;
-pub const ENETDOWN = 50;
-pub const ENETUNREACH = 51;
-pub const ENETRESET = 52;
-pub const ECONNABORTED = 53;
-pub const ECONNRESET = 54;
-pub const ENOBUFS = 55;
-pub const EISCONN = 56;
-pub const ENOTCONN = 57;
-pub const ESHUTDOWN = 58;
-pub const ETOOMANYREFS = 59;
-pub const ETIMEDOUT = 60;
-pub const ECONNREFUSED = 61;
-pub const ELOOP = 62;
-pub const ENAMETOOLONG = 63;
-pub const EHOSTDOWN = 64;
-pub const EHOSTUNREACH = 65;
-pub const ENOTEMPTY = 66;
-pub const EPROCLIM = 67;
-pub const EUSERS = 68;
-pub const EDQUOT = 69;
-pub const ESTALE = 70;
-pub const EREMOTE = 71;
-pub const ENOSTR = 72;
-pub const ETIME = 73;
-pub const ENOSR = 74;
-pub const ENOMSG = 75;
-pub const EBADMSG = 76;
-pub const EIDRM = 77;
-pub const EDEADLK = 78;
-pub const ENOLCK = 79;
-pub const ENONET = 80;
-pub const ERREMOTE = 81;
-pub const ENOLINK = 82;
-pub const EADV = 83;
-pub const ESRMNT = 84;
-pub const ECOMM = 85;
-pub const EPROTO = 86;
-pub const EMULTIHOP = 87;
-pub const EDOTDOT = 88;
-pub const EREMCHG = 89;
-pub const ENOSYS = 90;
-pub const ESTRPIPE = 91;
-pub const EOVERFLOW = 92;
-pub const EBADFD = 93;
-pub const ECHRNG = 94;
-pub const EL2NSYNC = 95;
-pub const EL3HLT = 96;
-pub const EL3RST = 97;
-pub const ELNRNG = 98;
-pub const EUNATCH = 99;
-pub const ENOCSI = 100;
-pub const EL2HLT = 101;
-pub const EBADE = 102;
-pub const EBADR = 103;
-pub const EXFULL = 104;
-pub const ENOANO = 105;
-pub const EBADRQC = 106;
-pub const EBADSLT = 107;
-pub const EDEADLOCK = 108;
-pub const EBFONT = 109;
-pub const ELIBEXEC = 110;
-pub const ENODATA = 111;
-pub const ELIBBAD = 112;
-pub const ENOPKG = 113;
-pub const ELIBACC = 114;
-pub const ENOTUNIQ = 115;
-pub const ERESTART = 116;
-pub const EUCLEAN = 117;
-pub const ENOTNAM = 118;
-pub const ENAVAIL = 119;
-pub const EISNAM = 120;
-pub const EREMOTEIO = 121;
-pub const EILSEQ = 122;
-pub const ELIBMAX = 123;
-pub const ELIBSCN = 124;
-pub const ENOMEDIUM = 125;
-pub const EMEDIUMTYPE = 126;
-pub const ECANCELED = 127;
-pub const ENOKEY = 128;
-pub const EKEYEXPIRED = 129;
-pub const EKEYREVOKED = 130;
-pub const EKEYREJECTED = 131;
-pub const EOWNERDEAD = 132;
-pub const ENOTRECOVERABLE = 133;
-pub const ERFKILL = 134;
-pub const EHWPOISON = 135;
diff --git a/lib/std/os/bits/linux/errno/generic.zig b/lib/std/os/bits/linux/errno/generic.zig
new file mode 100644
index 0000000000..730c71a5a2
--- /dev/null
+++ b/lib/std/os/bits/linux/errno/generic.zig
@@ -0,0 +1,460 @@
+pub const E = enum(u16) {
+ /// No error occurred.
+ /// Same code used for `NSROK`.
+ SUCCESS = 0,
+
+ /// Operation not permitted
+ PERM = 1,
+
+ /// No such file or directory
+ NOENT = 2,
+
+ /// No such process
+ SRCH = 3,
+
+ /// Interrupted system call
+ INTR = 4,
+
+ /// I/O error
+ IO = 5,
+
+ /// No such device or address
+ NXIO = 6,
+
+ /// Arg list too long
+ @"2BIG" = 7,
+
+ /// Exec format error
+ NOEXEC = 8,
+
+ /// Bad file number
+ BADF = 9,
+
+ /// No child processes
+ CHILD = 10,
+
+ /// Try again
+ /// Also means: WOULDBLOCK: operation would block
+ AGAIN = 11,
+
+ /// Out of memory
+ NOMEM = 12,
+
+ /// Permission denied
+ ACCES = 13,
+
+ /// Bad address
+ FAULT = 14,
+
+ /// Block device required
+ NOTBLK = 15,
+
+ /// Device or resource busy
+ BUSY = 16,
+
+ /// File exists
+ EXIST = 17,
+
+ /// Cross-device link
+ XDEV = 18,
+
+ /// No such device
+ NODEV = 19,
+
+ /// Not a directory
+ NOTDIR = 20,
+
+ /// Is a directory
+ ISDIR = 21,
+
+ /// Invalid argument
+ INVAL = 22,
+
+ /// File table overflow
+ NFILE = 23,
+
+ /// Too many open files
+ MFILE = 24,
+
+ /// Not a typewriter
+ NOTTY = 25,
+
+ /// Text file busy
+ TXTBSY = 26,
+
+ /// File too large
+ FBIG = 27,
+
+ /// No space left on device
+ NOSPC = 28,
+
+ /// Illegal seek
+ SPIPE = 29,
+
+ /// Read-only file system
+ ROFS = 30,
+
+ /// Too many links
+ MLINK = 31,
+
+ /// Broken pipe
+ PIPE = 32,
+
+ /// Math argument out of domain of func
+ DOM = 33,
+
+ /// Math result not representable
+ RANGE = 34,
+
+ /// Resource deadlock would occur
+ DEADLK = 35,
+
+ /// File name too long
+ NAMETOOLONG = 36,
+
+ /// No record locks available
+ NOLCK = 37,
+
+ /// Function not implemented
+ NOSYS = 38,
+
+ /// Directory not empty
+ NOTEMPTY = 39,
+
+ /// Too many symbolic links encountered
+ LOOP = 40,
+
+ /// No message of desired type
+ NOMSG = 42,
+
+ /// Identifier removed
+ IDRM = 43,
+
+ /// Channel number out of range
+ CHRNG = 44,
+
+ /// Level 2 not synchronized
+ L2NSYNC = 45,
+
+ /// Level 3 halted
+ L3HLT = 46,
+
+ /// Level 3 reset
+ L3RST = 47,
+
+ /// Link number out of range
+ LNRNG = 48,
+
+ /// Protocol driver not attached
+ UNATCH = 49,
+
+ /// No CSI structure available
+ NOCSI = 50,
+
+ /// Level 2 halted
+ L2HLT = 51,
+
+ /// Invalid exchange
+ BADE = 52,
+
+ /// Invalid request descriptor
+ BADR = 53,
+
+ /// Exchange full
+ XFULL = 54,
+
+ /// No anode
+ NOANO = 55,
+
+ /// Invalid request code
+ BADRQC = 56,
+
+ /// Invalid slot
+ BADSLT = 57,
+
+ /// Bad font file format
+ BFONT = 59,
+
+ /// Device not a stream
+ NOSTR = 60,
+
+ /// No data available
+ NODATA = 61,
+
+ /// Timer expired
+ TIME = 62,
+
+ /// Out of streams resources
+ NOSR = 63,
+
+ /// Machine is not on the network
+ NONET = 64,
+
+ /// Package not installed
+ NOPKG = 65,
+
+ /// Object is remote
+ REMOTE = 66,
+
+ /// Link has been severed
+ NOLINK = 67,
+
+ /// Advertise error
+ ADV = 68,
+
+ /// Srmount error
+ SRMNT = 69,
+
+ /// Communication error on send
+ COMM = 70,
+
+ /// Protocol error
+ PROTO = 71,
+
+ /// Multihop attempted
+ MULTIHOP = 72,
+
+ /// RFS specific error
+ DOTDOT = 73,
+
+ /// Not a data message
+ BADMSG = 74,
+
+ /// Value too large for defined data type
+ OVERFLOW = 75,
+
+ /// Name not unique on network
+ NOTUNIQ = 76,
+
+ /// File descriptor in bad state
+ BADFD = 77,
+
+ /// Remote address changed
+ REMCHG = 78,
+
+ /// Can not access a needed shared library
+ LIBACC = 79,
+
+ /// Accessing a corrupted shared library
+ LIBBAD = 80,
+
+ /// .lib section in a.out corrupted
+ LIBSCN = 81,
+
+ /// Attempting to link in too many shared libraries
+ LIBMAX = 82,
+
+ /// Cannot exec a shared library directly
+ LIBEXEC = 83,
+
+ /// Illegal byte sequence
+ ILSEQ = 84,
+
+ /// Interrupted system call should be restarted
+ RESTART = 85,
+
+ /// Streams pipe error
+ STRPIPE = 86,
+
+ /// Too many users
+ USERS = 87,
+
+ /// Socket operation on non-socket
+ NOTSOCK = 88,
+
+ /// Destination address required
+ DESTADDRREQ = 89,
+
+ /// Message too long
+ MSGSIZE = 90,
+
+ /// Protocol wrong type for socket
+ PROTOTYPE = 91,
+
+ /// Protocol not available
+ NOPROTOOPT = 92,
+
+ /// Protocol not supported
+ PROTONOSUPPORT = 93,
+
+ /// Socket type not supported
+ SOCKTNOSUPPORT = 94,
+
+ /// Operation not supported on transport endpoint
+ /// This code also means `NOTSUP`.
+ OPNOTSUPP = 95,
+
+ /// Protocol family not supported
+ PFNOSUPPORT = 96,
+
+ /// Address family not supported by protocol
+ AFNOSUPPORT = 97,
+
+ /// Address already in use
+ ADDRINUSE = 98,
+
+ /// Cannot assign requested address
+ ADDRNOTAVAIL = 99,
+
+ /// Network is down
+ NETDOWN = 100,
+
+ /// Network is unreachable
+ NETUNREACH = 101,
+
+ /// Network dropped connection because of reset
+ NETRESET = 102,
+
+ /// Software caused connection abort
+ CONNABORTED = 103,
+
+ /// Connection reset by peer
+ CONNRESET = 104,
+
+ /// No buffer space available
+ NOBUFS = 105,
+
+ /// Transport endpoint is already connected
+ ISCONN = 106,
+
+ /// Transport endpoint is not connected
+ NOTCONN = 107,
+
+ /// Cannot send after transport endpoint shutdown
+ SHUTDOWN = 108,
+
+ /// Too many references: cannot splice
+ TOOMANYREFS = 109,
+
+ /// Connection timed out
+ TIMEDOUT = 110,
+
+ /// Connection refused
+ CONNREFUSED = 111,
+
+ /// Host is down
+ HOSTDOWN = 112,
+
+ /// No route to host
+ HOSTUNREACH = 113,
+
+ /// Operation already in progress
+ ALREADY = 114,
+
+ /// Operation now in progress
+ INPROGRESS = 115,
+
+ /// Stale NFS file handle
+ STALE = 116,
+
+ /// Structure needs cleaning
+ UCLEAN = 117,
+
+ /// Not a XENIX named type file
+ NOTNAM = 118,
+
+ /// No XENIX semaphores available
+ NAVAIL = 119,
+
+ /// Is a named type file
+ ISNAM = 120,
+
+ /// Remote I/O error
+ REMOTEIO = 121,
+
+ /// Quota exceeded
+ DQUOT = 122,
+
+ /// No medium found
+ NOMEDIUM = 123,
+
+ /// Wrong medium type
+ MEDIUMTYPE = 124,
+
+ /// Operation canceled
+ CANCELED = 125,
+
+ /// Required key not available
+ NOKEY = 126,
+
+ /// Key has expired
+ KEYEXPIRED = 127,
+
+ /// Key has been revoked
+ KEYREVOKED = 128,
+
+ /// Key was rejected by service
+ KEYREJECTED = 129,
+
+ // for robust mutexes
+
+ /// Owner died
+ OWNERDEAD = 130,
+
+ /// State not recoverable
+ NOTRECOVERABLE = 131,
+
+ /// Operation not possible due to RF-kill
+ RFKILL = 132,
+
+ /// Memory page has hardware error
+ HWPOISON = 133,
+
+ // nameserver query return codes
+
+ /// DNS server returned answer with no data
+ NSRNODATA = 160,
+
+ /// DNS server claims query was misformatted
+ NSRFORMERR = 161,
+
+ /// DNS server returned general failure
+ NSRSERVFAIL = 162,
+
+ /// Domain name not found
+ NSRNOTFOUND = 163,
+
+ /// DNS server does not implement requested operation
+ NSRNOTIMP = 164,
+
+ /// DNS server refused query
+ NSRREFUSED = 165,
+
+ /// Misformatted DNS query
+ NSRBADQUERY = 166,
+
+ /// Misformatted domain name
+ NSRBADNAME = 167,
+
+ /// Unsupported address family
+ NSRBADFAMILY = 168,
+
+ /// Misformatted DNS reply
+ NSRBADRESP = 169,
+
+ /// Could not contact DNS servers
+ NSRCONNREFUSED = 170,
+
+ /// Timeout while contacting DNS servers
+ NSRTIMEOUT = 171,
+
+ /// End of file
+ NSROF = 172,
+
+ /// Error reading file
+ NSRFILE = 173,
+
+ /// Out of memory
+ NSRNOMEM = 174,
+
+ /// Application terminated lookup
+ NSRDESTRUCTION = 175,
+
+ /// Domain name is too long
+ NSRQUERYDOMAINTOOLONG = 176,
+
+ /// Domain name is too long
+ NSRCNAMELOOP = 177,
+
+ _,
+};
diff --git a/lib/std/os/bits/linux/errno/mips.zig b/lib/std/os/bits/linux/errno/mips.zig
new file mode 100644
index 0000000000..39fb9f71ea
--- /dev/null
+++ b/lib/std/os/bits/linux/errno/mips.zig
@@ -0,0 +1,141 @@
+//! These are MIPS ABI compatible.
+pub const E = enum(i32) {
+ /// No error occurred.
+ SUCCESS = 0,
+
+ PERM = 1,
+ NOENT = 2,
+ SRCH = 3,
+ INTR = 4,
+ IO = 5,
+ NXIO = 6,
+ @"2BIG" = 7,
+ NOEXEC = 8,
+ BADF = 9,
+ CHILD = 10,
+ /// Also used for WOULDBLOCK.
+ AGAIN = 11,
+ NOMEM = 12,
+ ACCES = 13,
+ FAULT = 14,
+ NOTBLK = 15,
+ BUSY = 16,
+ EXIST = 17,
+ XDEV = 18,
+ NODEV = 19,
+ NOTDIR = 20,
+ ISDIR = 21,
+ INVAL = 22,
+ NFILE = 23,
+ MFILE = 24,
+ NOTTY = 25,
+ TXTBSY = 26,
+ FBIG = 27,
+ NOSPC = 28,
+ SPIPE = 29,
+ ROFS = 30,
+ MLINK = 31,
+ PIPE = 32,
+ DOM = 33,
+ RANGE = 34,
+
+ NOMSG = 35,
+ IDRM = 36,
+ CHRNG = 37,
+ L2NSYNC = 38,
+ L3HLT = 39,
+ L3RST = 40,
+ LNRNG = 41,
+ UNATCH = 42,
+ NOCSI = 43,
+ L2HLT = 44,
+ DEADLK = 45,
+ NOLCK = 46,
+ BADE = 50,
+ BADR = 51,
+ XFULL = 52,
+ NOANO = 53,
+ BADRQC = 54,
+ BADSLT = 55,
+ DEADLOCK = 56,
+ BFONT = 59,
+ NOSTR = 60,
+ NODATA = 61,
+ TIME = 62,
+ NOSR = 63,
+ NONET = 64,
+ NOPKG = 65,
+ REMOTE = 66,
+ NOLINK = 67,
+ ADV = 68,
+ SRMNT = 69,
+ COMM = 70,
+ PROTO = 71,
+ DOTDOT = 73,
+ MULTIHOP = 74,
+ BADMSG = 77,
+ NAMETOOLONG = 78,
+ OVERFLOW = 79,
+ NOTUNIQ = 80,
+ BADFD = 81,
+ REMCHG = 82,
+ LIBACC = 83,
+ LIBBAD = 84,
+ LIBSCN = 85,
+ LIBMAX = 86,
+ LIBEXEC = 87,
+ ILSEQ = 88,
+ NOSYS = 89,
+ LOOP = 90,
+ RESTART = 91,
+ STRPIPE = 92,
+ NOTEMPTY = 93,
+ USERS = 94,
+ NOTSOCK = 95,
+ DESTADDRREQ = 96,
+ MSGSIZE = 97,
+ PROTOTYPE = 98,
+ NOPROTOOPT = 99,
+ PROTONOSUPPORT = 120,
+ SOCKTNOSUPPORT = 121,
+ OPNOTSUPP = 122,
+ PFNOSUPPORT = 123,
+ AFNOSUPPORT = 124,
+ ADDRINUSE = 125,
+ ADDRNOTAVAIL = 126,
+ NETDOWN = 127,
+ NETUNREACH = 128,
+ NETRESET = 129,
+ CONNABORTED = 130,
+ CONNRESET = 131,
+ NOBUFS = 132,
+ ISCONN = 133,
+ NOTCONN = 134,
+ UCLEAN = 135,
+ NOTNAM = 137,
+ NAVAIL = 138,
+ ISNAM = 139,
+ REMOTEIO = 140,
+ SHUTDOWN = 143,
+ TOOMANYREFS = 144,
+ TIMEDOUT = 145,
+ CONNREFUSED = 146,
+ HOSTDOWN = 147,
+ HOSTUNREACH = 148,
+ ALREADY = 149,
+ INPROGRESS = 150,
+ STALE = 151,
+ CANCELED = 158,
+ NOMEDIUM = 159,
+ MEDIUMTYPE = 160,
+ NOKEY = 161,
+ KEYEXPIRED = 162,
+ KEYREVOKED = 163,
+ KEYREJECTED = 164,
+ OWNERDEAD = 165,
+ NOTRECOVERABLE = 166,
+ RFKILL = 167,
+ HWPOISON = 168,
+ DQUOT = 1133,
+ _,
+};
diff --git a/lib/std/os/bits/linux/errno/sparc.zig b/lib/std/os/bits/linux/errno/sparc.zig
new file mode 100644
index 0000000000..c4ab65f34a
--- /dev/null
+++ b/lib/std/os/bits/linux/errno/sparc.zig
@@ -0,0 +1,144 @@
+//! These match the SunOS error numbering scheme.
+pub const E = enum(i32) {
+ /// No error occurred.
+ SUCCESS = 0,
+
+ PERM = 1,
+ NOENT = 2,
+ SRCH = 3,
+ INTR = 4,
+ IO = 5,
+ NXIO = 6,
+ @"2BIG" = 7,
+ NOEXEC = 8,
+ BADF = 9,
+ CHILD = 10,
+ /// Also used for WOULDBLOCK
+ AGAIN = 11,
+ NOMEM = 12,
+ ACCES = 13,
+ FAULT = 14,
+ NOTBLK = 15,
+ BUSY = 16,
+ EXIST = 17,
+ XDEV = 18,
+ NODEV = 19,
+ NOTDIR = 20,
+ ISDIR = 21,
+ INVAL = 22,
+ NFILE = 23,
+ MFILE = 24,
+ NOTTY = 25,
+ TXTBSY = 26,
+ FBIG = 27,
+ NOSPC = 28,
+ SPIPE = 29,
+ ROFS = 30,
+ MLINK = 31,
+ PIPE = 32,
+ DOM = 33,
+ RANGE = 34,
+
+ INPROGRESS = 36,
+ ALREADY = 37,
+ NOTSOCK = 38,
+ DESTADDRREQ = 39,
+ MSGSIZE = 40,
+ PROTOTYPE = 41,
+ NOPROTOOPT = 42,
+ PROTONOSUPPORT = 43,
+ SOCKTNOSUPPORT = 44,
+ /// Also used for NOTSUP
+ OPNOTSUPP = 45,
+ PFNOSUPPORT = 46,
+ AFNOSUPPORT = 47,
+ ADDRINUSE = 48,
+ ADDRNOTAVAIL = 49,
+ NETDOWN = 50,
+ NETUNREACH = 51,
+ NETRESET = 52,
+ CONNABORTED = 53,
+ CONNRESET = 54,
+ NOBUFS = 55,
+ ISCONN = 56,
+ NOTCONN = 57,
+ SHUTDOWN = 58,
+ TOOMANYREFS = 59,
+ TIMEDOUT = 60,
+ CONNREFUSED = 61,
+ LOOP = 62,
+ NAMETOOLONG = 63,
+ HOSTDOWN = 64,
+ HOSTUNREACH = 65,
+ NOTEMPTY = 66,
+ PROCLIM = 67,
+ USERS = 68,
+ DQUOT = 69,
+ STALE = 70,
+ REMOTE = 71,
+ NOSTR = 72,
+ TIME = 73,
+ NOSR = 74,
+ NOMSG = 75,
+ BADMSG = 76,
+ IDRM = 77,
+ DEADLK = 78,
+ NOLCK = 79,
+ NONET = 80,
+ RREMOTE = 81,
+ NOLINK = 82,
+ ADV = 83,
+ SRMNT = 84,
+ COMM = 85,
+ PROTO = 86,
+ MULTIHOP = 87,
+ DOTDOT = 88,
+ REMCHG = 89,
+ NOSYS = 90,
+ STRPIPE = 91,
+ OVERFLOW = 92,
+ BADFD = 93,
+ CHRNG = 94,
+ L2NSYNC = 95,
+ L3HLT = 96,
+ L3RST = 97,
+ LNRNG = 98,
+ UNATCH = 99,
+ NOCSI = 100,
+ L2HLT = 101,
+ BADE = 102,
+ BADR = 103,
+ XFULL = 104,
+ NOANO = 105,
+ BADRQC = 106,
+ BADSLT = 107,
+ DEADLOCK = 108,
+ BFONT = 109,
+ LIBEXEC = 110,
+ NODATA = 111,
+ LIBBAD = 112,
+ NOPKG = 113,
+ LIBACC = 114,
+ NOTUNIQ = 115,
+ RESTART = 116,
+ UCLEAN = 117,
+ NOTNAM = 118,
+ NAVAIL = 119,
+ ISNAM = 120,
+ REMOTEIO = 121,
+ ILSEQ = 122,
+ LIBMAX = 123,
+ LIBSCN = 124,
+ NOMEDIUM = 125,
+ MEDIUMTYPE = 126,
+ CANCELED = 127,
+ NOKEY = 128,
+ KEYEXPIRED = 129,
+ KEYREVOKED = 130,
+ KEYREJECTED = 131,
+ OWNERDEAD = 132,
+ NOTRECOVERABLE = 133,
+ RFKILL = 134,
+ HWPOISON = 135,
+ _,
+};
diff --git a/lib/std/os/bits/linux/i386.zig b/lib/std/os/bits/linux/i386.zig
index f8dadb8a60..12c8fa4713 100644
--- a/lib/std/os/bits/linux/i386.zig
+++ b/lib/std/os/bits/linux/i386.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// i386-specific declarations that are intended to be imported into the POSIX namespace.
// This does include Linux-only APIs.
diff --git a/lib/std/os/bits/linux/mips.zig b/lib/std/os/bits/linux/mips.zig
index e158755889..ddf241fb4d 100644
--- a/lib/std/os/bits/linux/mips.zig
+++ b/lib/std/os/bits/linux/mips.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../../std.zig");
const linux = std.os.linux;
const socklen_t = linux.socklen_t;
diff --git a/lib/std/os/bits/linux/netlink.zig b/lib/std/os/bits/linux/netlink.zig
index a840a47625..9de546fb20 100644
--- a/lib/std/os/bits/linux/netlink.zig
+++ b/lib/std/os/bits/linux/netlink.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../linux.zig");
/// Routing/device hook
diff --git a/lib/std/os/bits/linux/powerpc.zig b/lib/std/os/bits/linux/powerpc.zig
index 96908cb714..06f8e326ba 100644
--- a/lib/std/os/bits/linux/powerpc.zig
+++ b/lib/std/os/bits/linux/powerpc.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../../std.zig");
const linux = std.os.linux;
const socklen_t = linux.socklen_t;
diff --git a/lib/std/os/bits/linux/powerpc64.zig b/lib/std/os/bits/linux/powerpc64.zig
index 52b9109247..74c6ad11fc 100644
--- a/lib/std/os/bits/linux/powerpc64.zig
+++ b/lib/std/os/bits/linux/powerpc64.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../../std.zig");
const linux = std.os.linux;
const socklen_t = linux.socklen_t;
diff --git a/lib/std/os/bits/linux/prctl.zig b/lib/std/os/bits/linux/prctl.zig
index 249e60eca3..d29b6021b6 100644
--- a/lib/std/os/bits/linux/prctl.zig
+++ b/lib/std/os/bits/linux/prctl.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
pub const PR = enum(i32) {
SET_PDEATHSIG = 1,
GET_PDEATHSIG = 2,
diff --git a/lib/std/os/bits/linux/riscv64.zig b/lib/std/os/bits/linux/riscv64.zig
index 6147bca64f..7a0811cc1a 100644
--- a/lib/std/os/bits/linux/riscv64.zig
+++ b/lib/std/os/bits/linux/riscv64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// riscv64-specific declarations that are intended to be imported into the POSIX namespace.
const std = @import("../../../std.zig");
const uid_t = std.os.linux.uid_t;
diff --git a/lib/std/os/bits/linux/securebits.zig b/lib/std/os/bits/linux/securebits.zig
index 374f7c9f02..a23ced3cf2 100644
--- a/lib/std/os/bits/linux/securebits.zig
+++ b/lib/std/os/bits/linux/securebits.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
fn issecure_mask(comptime x: comptime_int) comptime_int {
return 1 << x;
}
diff --git a/lib/std/os/bits/linux/x86_64.zig b/lib/std/os/bits/linux/x86_64.zig
index 30e5af384f..69beac9d87 100644
--- a/lib/std/os/bits/linux/x86_64.zig
+++ b/lib/std/os/bits/linux/x86_64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// x86-64-specific declarations that are intended to be imported into the POSIX namespace.
const std = @import("../../../std.zig");
const pid_t = linux.pid_t;
diff --git a/lib/std/os/bits/linux/xdp.zig b/lib/std/os/bits/linux/xdp.zig
index be615ecf98..88fa9918a3 100644
--- a/lib/std/os/bits/linux/xdp.zig
+++ b/lib/std/os/bits/linux/xdp.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../linux.zig");
pub const XDP_SHARED_UMEM = (1 << 0);
diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig
index f3ece93493..be35889042 100644
--- a/lib/std/os/bits/netbsd.zig
+++ b/lib/std/os/bits/netbsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const builtin = std.builtin;
const maxInt = std.math.maxInt;
@@ -405,8 +400,10 @@ pub const CTL_DEBUG = 5;
pub const KERN_PROC_ARGS = 48; // struct: process argv/env
pub const KERN_PROC_PATHNAME = 5; // path to executable
+pub const KERN_IOV_MAX = 38;
pub const PATH_MAX = 1024;
+pub const IOV_MAX = KERN_IOV_MAX;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
@@ -931,140 +928,144 @@ pub const ucontext_t = extern struct {
]u32,
};
-pub const EPERM = 1; // Operation not permitted
-pub const ENOENT = 2; // No such file or directory
-pub const ESRCH = 3; // No such process
-pub const EINTR = 4; // Interrupted system call
-pub const EIO = 5; // Input/output error
-pub const ENXIO = 6; // Device not configured
-pub const E2BIG = 7; // Argument list too long
-pub const ENOEXEC = 8; // Exec format error
-pub const EBADF = 9; // Bad file descriptor
-pub const ECHILD = 10; // No child processes
-pub const EDEADLK = 11; // Resource deadlock avoided
-// 11 was EAGAIN
-pub const ENOMEM = 12; // Cannot allocate memory
-pub const EACCES = 13; // Permission denied
-pub const EFAULT = 14; // Bad address
-pub const ENOTBLK = 15; // Block device required
-pub const EBUSY = 16; // Device busy
-pub const EEXIST = 17; // File exists
-pub const EXDEV = 18; // Cross-device link
-pub const ENODEV = 19; // Operation not supported by device
-pub const ENOTDIR = 20; // Not a directory
-pub const EISDIR = 21; // Is a directory
-pub const EINVAL = 22; // Invalid argument
-pub const ENFILE = 23; // Too many open files in system
-pub const EMFILE = 24; // Too many open files
-pub const ENOTTY = 25; // Inappropriate ioctl for device
-pub const ETXTBSY = 26; // Text file busy
-pub const EFBIG = 27; // File too large
-pub const ENOSPC = 28; // No space left on device
-pub const ESPIPE = 29; // Illegal seek
-pub const EROFS = 30; // Read-only file system
-pub const EMLINK = 31; // Too many links
-pub const EPIPE = 32; // Broken pipe
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
+ PERM = 1, // Operation not permitted
+ NOENT = 2, // No such file or directory
+ SRCH = 3, // No such process
+ INTR = 4, // Interrupted system call
+ IO = 5, // Input/output error
+ NXIO = 6, // Device not configured
+ @"2BIG" = 7, // Argument list too long
+ NOEXEC = 8, // Exec format error
+ BADF = 9, // Bad file descriptor
+ CHILD = 10, // No child processes
+ DEADLK = 11, // Resource deadlock avoided
+ // 11 was AGAIN
+ NOMEM = 12, // Cannot allocate memory
+ ACCES = 13, // Permission denied
+ FAULT = 14, // Bad address
+ NOTBLK = 15, // Block device required
+ BUSY = 16, // Device busy
+ EXIST = 17, // File exists
+ XDEV = 18, // Cross-device link
+ NODEV = 19, // Operation not supported by device
+ NOTDIR = 20, // Not a directory
+ ISDIR = 21, // Is a directory
+ INVAL = 22, // Invalid argument
+ NFILE = 23, // Too many open files in system
+ MFILE = 24, // Too many open files
+ NOTTY = 25, // Inappropriate ioctl for device
+ TXTBSY = 26, // Text file busy
+ FBIG = 27, // File too large
+ NOSPC = 28, // No space left on device
+ SPIPE = 29, // Illegal seek
+ ROFS = 30, // Read-only file system
+ MLINK = 31, // Too many links
+ PIPE = 32, // Broken pipe
-// math software
-pub const EDOM = 33; // Numerical argument out of domain
-pub const ERANGE = 34; // Result too large or too small
+ // math software
+ DOM = 33, // Numerical argument out of domain
+ RANGE = 34, // Result too large or too small
-// non-blocking and interrupt i/o
-pub const EAGAIN = 35; // Resource temporarily unavailable
-pub const EWOULDBLOCK = EAGAIN; // Operation would block
-pub const EINPROGRESS = 36; // Operation now in progress
-pub const EALREADY = 37; // Operation already in progress
+ // non-blocking and interrupt i/o
+ // also: WOULDBLOCK: operation would block
+ AGAIN = 35, // Resource temporarily unavailable
+ INPROGRESS = 36, // Operation now in progress
+ ALREADY = 37, // Operation already in progress
-// ipc/network software -- argument errors
-pub const ENOTSOCK = 38; // Socket operation on non-socket
-pub const EDESTADDRREQ = 39; // Destination address required
-pub const EMSGSIZE = 40; // Message too long
-pub const EPROTOTYPE = 41; // Protocol wrong type for socket
-pub const ENOPROTOOPT = 42; // Protocol option not available
-pub const EPROTONOSUPPORT = 43; // Protocol not supported
-pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
-pub const EOPNOTSUPP = 45; // Operation not supported
-pub const EPFNOSUPPORT = 46; // Protocol family not supported
-pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
-pub const EADDRINUSE = 48; // Address already in use
-pub const EADDRNOTAVAIL = 49; // Can't assign requested address
+ // ipc/network software -- argument errors
+ NOTSOCK = 38, // Socket operation on non-socket
+ DESTADDRREQ = 39, // Destination address required
+ MSGSIZE = 40, // Message too long
+ PROTOTYPE = 41, // Protocol wrong type for socket
+ NOPROTOOPT = 42, // Protocol option not available
+ PROTONOSUPPORT = 43, // Protocol not supported
+ SOCKTNOSUPPORT = 44, // Socket type not supported
+ OPNOTSUPP = 45, // Operation not supported
+ PFNOSUPPORT = 46, // Protocol family not supported
+ AFNOSUPPORT = 47, // Address family not supported by protocol family
+ ADDRINUSE = 48, // Address already in use
+ ADDRNOTAVAIL = 49, // Can't assign requested address
-// ipc/network software -- operational errors
-pub const ENETDOWN = 50; // Network is down
-pub const ENETUNREACH = 51; // Network is unreachable
-pub const ENETRESET = 52; // Network dropped connection on reset
-pub const ECONNABORTED = 53; // Software caused connection abort
-pub const ECONNRESET = 54; // Connection reset by peer
-pub const ENOBUFS = 55; // No buffer space available
-pub const EISCONN = 56; // Socket is already connected
-pub const ENOTCONN = 57; // Socket is not connected
-pub const ESHUTDOWN = 58; // Can't send after socket shutdown
-pub const ETOOMANYREFS = 59; // Too many references: can't splice
-pub const ETIMEDOUT = 60; // Operation timed out
-pub const ECONNREFUSED = 61; // Connection refused
+ // ipc/network software -- operational errors
+ NETDOWN = 50, // Network is down
+ NETUNREACH = 51, // Network is unreachable
+ NETRESET = 52, // Network dropped connection on reset
+ CONNABORTED = 53, // Software caused connection abort
+ CONNRESET = 54, // Connection reset by peer
+ NOBUFS = 55, // No buffer space available
+ ISCONN = 56, // Socket is already connected
+ NOTCONN = 57, // Socket is not connected
+ SHUTDOWN = 58, // Can't send after socket shutdown
+ TOOMANYREFS = 59, // Too many references: can't splice
+ TIMEDOUT = 60, // Operation timed out
+ CONNREFUSED = 61, // Connection refused
-pub const ELOOP = 62; // Too many levels of symbolic links
-pub const ENAMETOOLONG = 63; // File name too long
+ LOOP = 62, // Too many levels of symbolic links
+ NAMETOOLONG = 63, // File name too long
-// should be rearranged
-pub const EHOSTDOWN = 64; // Host is down
-pub const EHOSTUNREACH = 65; // No route to host
-pub const ENOTEMPTY = 66; // Directory not empty
+ // should be rearranged
+ HOSTDOWN = 64, // Host is down
+ HOSTUNREACH = 65, // No route to host
+ NOTEMPTY = 66, // Directory not empty
-// quotas & mush
-pub const EPROCLIM = 67; // Too many processes
-pub const EUSERS = 68; // Too many users
-pub const EDQUOT = 69; // Disc quota exceeded
+ // quotas & mush
+ PROCLIM = 67, // Too many processes
+ USERS = 68, // Too many users
+ DQUOT = 69, // Disc quota exceeded
-// Network File System
-pub const ESTALE = 70; // Stale NFS file handle
-pub const EREMOTE = 71; // Too many levels of remote in path
-pub const EBADRPC = 72; // RPC struct is bad
-pub const ERPCMISMATCH = 73; // RPC version wrong
-pub const EPROGUNAVAIL = 74; // RPC prog. not avail
-pub const EPROGMISMATCH = 75; // Program version wrong
-pub const EPROCUNAVAIL = 76; // Bad procedure for program
+ // Network File System
+ STALE = 70, // Stale NFS file handle
+ REMOTE = 71, // Too many levels of remote in path
+ BADRPC = 72, // RPC struct is bad
+ RPCMISMATCH = 73, // RPC version wrong
+ PROGUNAVAIL = 74, // RPC prog. not avail
+ PROGMISMATCH = 75, // Program version wrong
+ PROCUNAVAIL = 76, // Bad procedure for program
-pub const ENOLCK = 77; // No locks available
-pub const ENOSYS = 78; // Function not implemented
+ NOLCK = 77, // No locks available
+ NOSYS = 78, // Function not implemented
-pub const EFTYPE = 79; // Inappropriate file type or format
-pub const EAUTH = 80; // Authentication error
-pub const ENEEDAUTH = 81; // Need authenticator
+ FTYPE = 79, // Inappropriate file type or format
+ AUTH = 80, // Authentication error
+ NEEDAUTH = 81, // Need authenticator
-// SystemV IPC
-pub const EIDRM = 82; // Identifier removed
-pub const ENOMSG = 83; // No message of desired type
-pub const EOVERFLOW = 84; // Value too large to be stored in data type
+ // SystemV IPC
+ IDRM = 82, // Identifier removed
+ NOMSG = 83, // No message of desired type
+ OVERFLOW = 84, // Value too large to be stored in data type
-// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
-pub const EILSEQ = 85; // Illegal byte sequence
+ // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
+ ILSEQ = 85, // Illegal byte sequence
-// From IEEE Std 1003.1-2001
-// Base, Realtime, Threads or Thread Priority Scheduling option errors
-pub const ENOTSUP = 86; // Not supported
+ // From IEEE Std 1003.1-2001
+ // Base, Realtime, Threads or Thread Priority Scheduling option errors
+ NOTSUP = 86, // Not supported
-// Realtime option errors
-pub const ECANCELED = 87; // Operation canceled
+ // Realtime option errors
+ CANCELED = 87, // Operation canceled
-// Realtime, XSI STREAMS option errors
-pub const EBADMSG = 88; // Bad or Corrupt message
+ // Realtime, XSI STREAMS option errors
+ BADMSG = 88, // Bad or Corrupt message
-// XSI STREAMS option errors
-pub const ENODATA = 89; // No message available
-pub const ENOSR = 90; // No STREAM resources
-pub const ENOSTR = 91; // Not a STREAM
-pub const ETIME = 92; // STREAM ioctl timeout
+ // XSI STREAMS option errors
+ NODATA = 89, // No message available
+ NOSR = 90, // No STREAM resources
+ NOSTR = 91, // Not a STREAM
+ TIME = 92, // STREAM ioctl timeout
-// File system extended attribute errors
-pub const ENOATTR = 93; // Attribute not found
+ // File system extended attribute errors
+ NOATTR = 93, // Attribute not found
-// Realtime, XSI STREAMS option errors
-pub const EMULTIHOP = 94; // Multihop attempted
-pub const ENOLINK = 95; // Link has been severed
-pub const EPROTO = 96; // Protocol error
+ // Realtime, XSI STREAMS option errors
+ MULTIHOP = 94, // Multihop attempted
+ NOLINK = 95, // Link has been severed
+ PROTO = 96, // Protocol error
-pub const ELAST = 96; // Must equal largest errno
+ _,
+};
pub const MINSIGSTKSZ = 8192;
pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig
index 233ebcbd68..c7d1c0583b 100644
--- a/lib/std/os/bits/openbsd.zig
+++ b/lib/std/os/bits/openbsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const builtin = std.builtin;
const maxInt = std.math.maxInt;
@@ -295,6 +290,7 @@ pub const AI_NUMERICSERV = 16;
pub const AI_ADDRCONFIG = 64;
pub const PATH_MAX = 1024;
+pub const IOV_MAX = 1024;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
@@ -824,125 +820,129 @@ pub usingnamespace switch (builtin.target.cpu.arch) {
pub const sigset_t = c_uint;
pub const empty_sigset: sigset_t = 0;
-pub const EPERM = 1; // Operation not permitted
-pub const ENOENT = 2; // No such file or directory
-pub const ESRCH = 3; // No such process
-pub const EINTR = 4; // Interrupted system call
-pub const EIO = 5; // Input/output error
-pub const ENXIO = 6; // Device not configured
-pub const E2BIG = 7; // Argument list too long
-pub const ENOEXEC = 8; // Exec format error
-pub const EBADF = 9; // Bad file descriptor
-pub const ECHILD = 10; // No child processes
-pub const EDEADLK = 11; // Resource deadlock avoided
-// 11 was EAGAIN
-pub const ENOMEM = 12; // Cannot allocate memory
-pub const EACCES = 13; // Permission denied
-pub const EFAULT = 14; // Bad address
-pub const ENOTBLK = 15; // Block device required
-pub const EBUSY = 16; // Device busy
-pub const EEXIST = 17; // File exists
-pub const EXDEV = 18; // Cross-device link
-pub const ENODEV = 19; // Operation not supported by device
-pub const ENOTDIR = 20; // Not a directory
-pub const EISDIR = 21; // Is a directory
-pub const EINVAL = 22; // Invalid argument
-pub const ENFILE = 23; // Too many open files in system
-pub const EMFILE = 24; // Too many open files
-pub const ENOTTY = 25; // Inappropriate ioctl for device
-pub const ETXTBSY = 26; // Text file busy
-pub const EFBIG = 27; // File too large
-pub const ENOSPC = 28; // No space left on device
-pub const ESPIPE = 29; // Illegal seek
-pub const EROFS = 30; // Read-only file system
-pub const EMLINK = 31; // Too many links
-pub const EPIPE = 32; // Broken pipe
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
+ PERM = 1, // Operation not permitted
+ NOENT = 2, // No such file or directory
+ SRCH = 3, // No such process
+ INTR = 4, // Interrupted system call
+ IO = 5, // Input/output error
+ NXIO = 6, // Device not configured
+ @"2BIG" = 7, // Argument list too long
+ NOEXEC = 8, // Exec format error
+ BADF = 9, // Bad file descriptor
+ CHILD = 10, // No child processes
+ DEADLK = 11, // Resource deadlock avoided
+ // 11 was AGAIN
+ NOMEM = 12, // Cannot allocate memory
+ ACCES = 13, // Permission denied
+ FAULT = 14, // Bad address
+ NOTBLK = 15, // Block device required
+ BUSY = 16, // Device busy
+ EXIST = 17, // File exists
+ XDEV = 18, // Cross-device link
+ NODEV = 19, // Operation not supported by device
+ NOTDIR = 20, // Not a directory
+ ISDIR = 21, // Is a directory
+ INVAL = 22, // Invalid argument
+ NFILE = 23, // Too many open files in system
+ MFILE = 24, // Too many open files
+ NOTTY = 25, // Inappropriate ioctl for device
+ TXTBSY = 26, // Text file busy
+ FBIG = 27, // File too large
+ NOSPC = 28, // No space left on device
+ SPIPE = 29, // Illegal seek
+ ROFS = 30, // Read-only file system
+ MLINK = 31, // Too many links
+ PIPE = 32, // Broken pipe
-// math software
-pub const EDOM = 33; // Numerical argument out of domain
-pub const ERANGE = 34; // Result too large or too small
+ // math software
+ DOM = 33, // Numerical argument out of domain
+ RANGE = 34, // Result too large or too small
-// non-blocking and interrupt i/o
-pub const EAGAIN = 35; // Resource temporarily unavailable
-pub const EWOULDBLOCK = EAGAIN; // Operation would block
-pub const EINPROGRESS = 36; // Operation now in progress
-pub const EALREADY = 37; // Operation already in progress
+ // non-blocking and interrupt i/o
+ // also: WOULDBLOCK: operation would block
+ AGAIN = 35, // Resource temporarily unavailable
+ INPROGRESS = 36, // Operation now in progress
+ ALREADY = 37, // Operation already in progress
-// ipc/network software -- argument errors
-pub const ENOTSOCK = 38; // Socket operation on non-socket
-pub const EDESTADDRREQ = 39; // Destination address required
-pub const EMSGSIZE = 40; // Message too long
-pub const EPROTOTYPE = 41; // Protocol wrong type for socket
-pub const ENOPROTOOPT = 42; // Protocol option not available
-pub const EPROTONOSUPPORT = 43; // Protocol not supported
-pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
-pub const EOPNOTSUPP = 45; // Operation not supported
-pub const EPFNOSUPPORT = 46; // Protocol family not supported
-pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
-pub const EADDRINUSE = 48; // Address already in use
-pub const EADDRNOTAVAIL = 49; // Can't assign requested address
+ // ipc/network software -- argument errors
+ NOTSOCK = 38, // Socket operation on non-socket
+ DESTADDRREQ = 39, // Destination address required
+ MSGSIZE = 40, // Message too long
+ PROTOTYPE = 41, // Protocol wrong type for socket
+ NOPROTOOPT = 42, // Protocol option not available
+ PROTONOSUPPORT = 43, // Protocol not supported
+ SOCKTNOSUPPORT = 44, // Socket type not supported
+ OPNOTSUPP = 45, // Operation not supported
+ PFNOSUPPORT = 46, // Protocol family not supported
+ AFNOSUPPORT = 47, // Address family not supported by protocol family
+ ADDRINUSE = 48, // Address already in use
+ ADDRNOTAVAIL = 49, // Can't assign requested address
-// ipc/network software -- operational errors
-pub const ENETDOWN = 50; // Network is down
-pub const ENETUNREACH = 51; // Network is unreachable
-pub const ENETRESET = 52; // Network dropped connection on reset
-pub const ECONNABORTED = 53; // Software caused connection abort
-pub const ECONNRESET = 54; // Connection reset by peer
-pub const ENOBUFS = 55; // No buffer space available
-pub const EISCONN = 56; // Socket is already connected
-pub const ENOTCONN = 57; // Socket is not connected
-pub const ESHUTDOWN = 58; // Can't send after socket shutdown
-pub const ETOOMANYREFS = 59; // Too many references: can't splice
-pub const ETIMEDOUT = 60; // Operation timed out
-pub const ECONNREFUSED = 61; // Connection refused
+ // ipc/network software -- operational errors
+ NETDOWN = 50, // Network is down
+ NETUNREACH = 51, // Network is unreachable
+ NETRESET = 52, // Network dropped connection on reset
+ CONNABORTED = 53, // Software caused connection abort
+ CONNRESET = 54, // Connection reset by peer
+ NOBUFS = 55, // No buffer space available
+ ISCONN = 56, // Socket is already connected
+ NOTCONN = 57, // Socket is not connected
+ SHUTDOWN = 58, // Can't send after socket shutdown
+ TOOMANYREFS = 59, // Too many references: can't splice
+ TIMEDOUT = 60, // Operation timed out
+ CONNREFUSED = 61, // Connection refused
-pub const ELOOP = 62; // Too many levels of symbolic links
-pub const ENAMETOOLONG = 63; // File name too long
+ LOOP = 62, // Too many levels of symbolic links
+ NAMETOOLONG = 63, // File name too long
-// should be rearranged
-pub const EHOSTDOWN = 64; // Host is down
-pub const EHOSTUNREACH = 65; // No route to host
-pub const ENOTEMPTY = 66; // Directory not empty
+ // should be rearranged
+ HOSTDOWN = 64, // Host is down
+ HOSTUNREACH = 65, // No route to host
+ NOTEMPTY = 66, // Directory not empty
-// quotas & mush
-pub const EPROCLIM = 67; // Too many processes
-pub const EUSERS = 68; // Too many users
-pub const EDQUOT = 69; // Disc quota exceeded
+ // quotas & mush
+ PROCLIM = 67, // Too many processes
+ USERS = 68, // Too many users
+ DQUOT = 69, // Disc quota exceeded
-// Network File System
-pub const ESTALE = 70; // Stale NFS file handle
-pub const EREMOTE = 71; // Too many levels of remote in path
-pub const EBADRPC = 72; // RPC struct is bad
-pub const ERPCMISMATCH = 73; // RPC version wrong
-pub const EPROGUNAVAIL = 74; // RPC prog. not avail
-pub const EPROGMISMATCH = 75; // Program version wrong
-pub const EPROCUNAVAIL = 76; // Bad procedure for program
+ // Network File System
+ STALE = 70, // Stale NFS file handle
+ REMOTE = 71, // Too many levels of remote in path
+ BADRPC = 72, // RPC struct is bad
+ RPCMISMATCH = 73, // RPC version wrong
+ PROGUNAVAIL = 74, // RPC prog. not avail
+ PROGMISMATCH = 75, // Program version wrong
+ PROCUNAVAIL = 76, // Bad procedure for program
-pub const ENOLCK = 77; // No locks available
-pub const ENOSYS = 78; // Function not implemented
+ NOLCK = 77, // No locks available
+ NOSYS = 78, // Function not implemented
-pub const EFTYPE = 79; // Inappropriate file type or format
-pub const EAUTH = 80; // Authentication error
-pub const ENEEDAUTH = 81; // Need authenticator
-pub const EIPSEC = 82; // IPsec processing failure
-pub const ENOATTR = 83; // Attribute not found
+ FTYPE = 79, // Inappropriate file type or format
+ AUTH = 80, // Authentication error
+ NEEDAUTH = 81, // Need authenticator
+ IPSEC = 82, // IPsec processing failure
+ NOATTR = 83, // Attribute not found
-// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
-pub const EILSEQ = 84; // Illegal byte sequence
+ // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
+ ILSEQ = 84, // Illegal byte sequence
-pub const ENOMEDIUM = 85; // No medium found
-pub const EMEDIUMTYPE = 86; // Wrong medium type
-pub const EOVERFLOW = 87; // Value too large to be stored in data type
-pub const ECANCELED = 88; // Operation canceled
-pub const EIDRM = 89; // Identifier removed
-pub const ENOMSG = 90; // No message of desired type
-pub const ENOTSUP = 91; // Not supported
-pub const EBADMSG = 92; // Bad or Corrupt message
-pub const ENOTRECOVERABLE = 93; // State not recoverable
-pub const EOWNERDEAD = 94; // Previous owner died
-pub const EPROTO = 95; // Protocol error
+ NOMEDIUM = 85, // No medium found
+ MEDIUMTYPE = 86, // Wrong medium type
+ OVERFLOW = 87, // Value too large to be stored in data type
+ CANCELED = 88, // Operation canceled
+ IDRM = 89, // Identifier removed
+ NOMSG = 90, // No message of desired type
+ NOTSUP = 91, // Not supported
+ BADMSG = 92, // Bad or Corrupt message
+ NOTRECOVERABLE = 93, // State not recoverable
+ OWNERDEAD = 94, // Previous owner died
+ PROTO = 95, // Protocol error
-pub const ELAST = 95; // Must equal largest errno
+ _,
+};
const _MAX_PAGE_SHIFT = switch (builtin.target.cpu.arch) {
.i386 => 12,
diff --git a/lib/std/os/bits/posix.zig b/lib/std/os/bits/posix.zig
index 0f015cd573..6ffd2dcf6a 100644
--- a/lib/std/os/bits/posix.zig
+++ b/lib/std/os/bits/posix.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
pub const iovec = extern struct {
iov_base: [*]u8,
iov_len: usize,
diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig
index 5102d9b439..567d74961e 100644
--- a/lib/std/os/bits/wasi.zig
+++ b/lib/std/os/bits/wasi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Convenience types and consts used by std.os module
const builtin = @import("builtin");
const posix = @import("posix.zig");
@@ -76,6 +71,8 @@ pub const kernel_stat = struct {
}
};
+pub const IOV_MAX = 1024;
+
pub const AT_REMOVEDIR: u32 = 0x4;
pub const AT_FDCWD: fd_t = -2;
@@ -109,86 +106,89 @@ pub const dirent_t = extern struct {
d_type: filetype_t,
};
-pub const errno_t = u16;
-pub const ESUCCESS: errno_t = 0;
-pub const E2BIG: errno_t = 1;
-pub const EACCES: errno_t = 2;
-pub const EADDRINUSE: errno_t = 3;
-pub const EADDRNOTAVAIL: errno_t = 4;
-pub const EAFNOSUPPORT: errno_t = 5;
-pub const EAGAIN: errno_t = 6;
-pub const EWOULDBLOCK = EAGAIN;
-pub const EALREADY: errno_t = 7;
-pub const EBADF: errno_t = 8;
-pub const EBADMSG: errno_t = 9;
-pub const EBUSY: errno_t = 10;
-pub const ECANCELED: errno_t = 11;
-pub const ECHILD: errno_t = 12;
-pub const ECONNABORTED: errno_t = 13;
-pub const ECONNREFUSED: errno_t = 14;
-pub const ECONNRESET: errno_t = 15;
-pub const EDEADLK: errno_t = 16;
-pub const EDESTADDRREQ: errno_t = 17;
-pub const EDOM: errno_t = 18;
-pub const EDQUOT: errno_t = 19;
-pub const EEXIST: errno_t = 20;
-pub const EFAULT: errno_t = 21;
-pub const EFBIG: errno_t = 22;
-pub const EHOSTUNREACH: errno_t = 23;
-pub const EIDRM: errno_t = 24;
-pub const EILSEQ: errno_t = 25;
-pub const EINPROGRESS: errno_t = 26;
-pub const EINTR: errno_t = 27;
-pub const EINVAL: errno_t = 28;
-pub const EIO: errno_t = 29;
-pub const EISCONN: errno_t = 30;
-pub const EISDIR: errno_t = 31;
-pub const ELOOP: errno_t = 32;
-pub const EMFILE: errno_t = 33;
-pub const EMLINK: errno_t = 34;
-pub const EMSGSIZE: errno_t = 35;
-pub const EMULTIHOP: errno_t = 36;
-pub const ENAMETOOLONG: errno_t = 37;
-pub const ENETDOWN: errno_t = 38;
-pub const ENETRESET: errno_t = 39;
-pub const ENETUNREACH: errno_t = 40;
-pub const ENFILE: errno_t = 41;
-pub const ENOBUFS: errno_t = 42;
-pub const ENODEV: errno_t = 43;
-pub const ENOENT: errno_t = 44;
-pub const ENOEXEC: errno_t = 45;
-pub const ENOLCK: errno_t = 46;
-pub const ENOLINK: errno_t = 47;
-pub const ENOMEM: errno_t = 48;
-pub const ENOMSG: errno_t = 49;
-pub const ENOPROTOOPT: errno_t = 50;
-pub const ENOSPC: errno_t = 51;
-pub const ENOSYS: errno_t = 52;
-pub const ENOTCONN: errno_t = 53;
-pub const ENOTDIR: errno_t = 54;
-pub const ENOTEMPTY: errno_t = 55;
-pub const ENOTRECOVERABLE: errno_t = 56;
-pub const ENOTSOCK: errno_t = 57;
-pub const ENOTSUP: errno_t = 58;
-pub const EOPNOTSUPP = ENOTSUP;
-pub const ENOTTY: errno_t = 59;
-pub const ENXIO: errno_t = 60;
-pub const EOVERFLOW: errno_t = 61;
-pub const EOWNERDEAD: errno_t = 62;
-pub const EPERM: errno_t = 63;
-pub const EPIPE: errno_t = 64;
-pub const EPROTO: errno_t = 65;
-pub const EPROTONOSUPPORT: errno_t = 66;
-pub const EPROTOTYPE: errno_t = 67;
-pub const ERANGE: errno_t = 68;
-pub const EROFS: errno_t = 69;
-pub const ESPIPE: errno_t = 70;
-pub const ESRCH: errno_t = 71;
-pub const ESTALE: errno_t = 72;
-pub const ETIMEDOUT: errno_t = 73;
-pub const ETXTBSY: errno_t = 74;
-pub const EXDEV: errno_t = 75;
-pub const ENOTCAPABLE: errno_t = 76;
+pub const errno_t = enum(u16) {
+ SUCCESS = 0,
+ @"2BIG" = 1,
+ ACCES = 2,
+ ADDRINUSE = 3,
+ ADDRNOTAVAIL = 4,
+ AFNOSUPPORT = 5,
+ /// This is also the error code used for `WOULDBLOCK`.
+ AGAIN = 6,
+ ALREADY = 7,
+ BADF = 8,
+ BADMSG = 9,
+ BUSY = 10,
+ CANCELED = 11,
+ CHILD = 12,
+ CONNABORTED = 13,
+ CONNREFUSED = 14,
+ CONNRESET = 15,
+ DEADLK = 16,
+ DESTADDRREQ = 17,
+ DOM = 18,
+ DQUOT = 19,
+ EXIST = 20,
+ FAULT = 21,
+ FBIG = 22,
+ HOSTUNREACH = 23,
+ IDRM = 24,
+ ILSEQ = 25,
+ INPROGRESS = 26,
+ INTR = 27,
+ INVAL = 28,
+ IO = 29,
+ ISCONN = 30,
+ ISDIR = 31,
+ LOOP = 32,
+ MFILE = 33,
+ MLINK = 34,
+ MSGSIZE = 35,
+ MULTIHOP = 36,
+ NAMETOOLONG = 37,
+ NETDOWN = 38,
+ NETRESET = 39,
+ NETUNREACH = 40,
+ NFILE = 41,
+ NOBUFS = 42,
+ NODEV = 43,
+ NOENT = 44,
+ NOEXEC = 45,
+ NOLCK = 46,
+ NOLINK = 47,
+ NOMEM = 48,
+ NOMSG = 49,
+ NOPROTOOPT = 50,
+ NOSPC = 51,
+ NOSYS = 52,
+ NOTCONN = 53,
+ NOTDIR = 54,
+ NOTEMPTY = 55,
+ NOTRECOVERABLE = 56,
+ NOTSOCK = 57,
+ /// This is also the code used for `NOTSUP`.
+ OPNOTSUPP = 58,
+ NOTTY = 59,
+ NXIO = 60,
+ OVERFLOW = 61,
+ OWNERDEAD = 62,
+ PERM = 63,
+ PIPE = 64,
+ PROTO = 65,
+ PROTONOSUPPORT = 66,
+ PROTOTYPE = 67,
+ RANGE = 68,
+ ROFS = 69,
+ SPIPE = 70,
+ SRCH = 71,
+ STALE = 72,
+ TIMEDOUT = 73,
+ TXTBSY = 74,
+ XDEV = 75,
+ NOTCAPABLE = 76,
+ _,
+};
+pub const E = errno_t;
pub const event_t = extern struct {
userdata: userdata_t,
diff --git a/lib/std/os/bits/windows.zig b/lib/std/os/bits/windows.zig
index 05c50ffe47..bb57a13ffe 100644
--- a/lib/std/os/bits/windows.zig
+++ b/lib/std/os/bits/windows.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
usingnamespace @import("../windows/bits.zig");
@@ -87,94 +82,98 @@ pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;
-pub const EPERM = 1;
-pub const ENOENT = 2;
-pub const ESRCH = 3;
-pub const EINTR = 4;
-pub const EIO = 5;
-pub const ENXIO = 6;
-pub const E2BIG = 7;
-pub const ENOEXEC = 8;
-pub const EBADF = 9;
-pub const ECHILD = 10;
-pub const EAGAIN = 11;
-pub const ENOMEM = 12;
-pub const EACCES = 13;
-pub const EFAULT = 14;
-pub const EBUSY = 16;
-pub const EEXIST = 17;
-pub const EXDEV = 18;
-pub const ENODEV = 19;
-pub const ENOTDIR = 20;
-pub const EISDIR = 21;
-pub const ENFILE = 23;
-pub const EMFILE = 24;
-pub const ENOTTY = 25;
-pub const EFBIG = 27;
-pub const ENOSPC = 28;
-pub const ESPIPE = 29;
-pub const EROFS = 30;
-pub const EMLINK = 31;
-pub const EPIPE = 32;
-pub const EDOM = 33;
-pub const EDEADLK = 36;
-pub const ENAMETOOLONG = 38;
-pub const ENOLCK = 39;
-pub const ENOSYS = 40;
-pub const ENOTEMPTY = 41;
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
+ PERM = 1,
+ NOENT = 2,
+ SRCH = 3,
+ INTR = 4,
+ IO = 5,
+ NXIO = 6,
+ @"2BIG" = 7,
+ NOEXEC = 8,
+ BADF = 9,
+ CHILD = 10,
+ AGAIN = 11,
+ NOMEM = 12,
+ ACCES = 13,
+ FAULT = 14,
+ BUSY = 16,
+ EXIST = 17,
+ XDEV = 18,
+ NODEV = 19,
+ NOTDIR = 20,
+ ISDIR = 21,
+ NFILE = 23,
+ MFILE = 24,
+ NOTTY = 25,
+ FBIG = 27,
+ NOSPC = 28,
+ SPIPE = 29,
+ ROFS = 30,
+ MLINK = 31,
+ PIPE = 32,
+ DOM = 33,
+ /// Also means `DEADLOCK`.
+ DEADLK = 36,
+ NAMETOOLONG = 38,
+ NOLCK = 39,
+ NOSYS = 40,
+ NOTEMPTY = 41,
+
+ INVAL = 22,
+ RANGE = 34,
+ ILSEQ = 42,
+
+ // POSIX Supplement
+ ADDRINUSE = 100,
+ ADDRNOTAVAIL = 101,
+ AFNOSUPPORT = 102,
+ ALREADY = 103,
+ BADMSG = 104,
+ CANCELED = 105,
+ CONNABORTED = 106,
+ CONNREFUSED = 107,
+ CONNRESET = 108,
+ DESTADDRREQ = 109,
+ HOSTUNREACH = 110,
+ IDRM = 111,
+ INPROGRESS = 112,
+ ISCONN = 113,
+ LOOP = 114,
+ MSGSIZE = 115,
+ NETDOWN = 116,
+ NETRESET = 117,
+ NETUNREACH = 118,
+ NOBUFS = 119,
+ NODATA = 120,
+ NOLINK = 121,
+ NOMSG = 122,
+ NOPROTOOPT = 123,
+ NOSR = 124,
+ NOSTR = 125,
+ NOTCONN = 126,
+ NOTRECOVERABLE = 127,
+ NOTSOCK = 128,
+ NOTSUP = 129,
+ OPNOTSUPP = 130,
+ OTHER = 131,
+ OVERFLOW = 132,
+ OWNERDEAD = 133,
+ PROTO = 134,
+ PROTONOSUPPORT = 135,
+ PROTOTYPE = 136,
+ TIME = 137,
+ TIMEDOUT = 138,
+ TXTBSY = 139,
+ WOULDBLOCK = 140,
+ DQUOT = 10069,
+ _,
+};
-pub const EINVAL = 22;
-pub const ERANGE = 34;
-pub const EILSEQ = 42;
pub const STRUNCATE = 80;
-// Support EDEADLOCK for compatibility with older Microsoft C versions
-pub const EDEADLOCK = EDEADLK;
-
-// POSIX Supplement
-pub const EADDRINUSE = 100;
-pub const EADDRNOTAVAIL = 101;
-pub const EAFNOSUPPORT = 102;
-pub const EALREADY = 103;
-pub const EBADMSG = 104;
-pub const ECANCELED = 105;
-pub const ECONNABORTED = 106;
-pub const ECONNREFUSED = 107;
-pub const ECONNRESET = 108;
-pub const EDESTADDRREQ = 109;
-pub const EHOSTUNREACH = 110;
-pub const EIDRM = 111;
-pub const EINPROGRESS = 112;
-pub const EISCONN = 113;
-pub const ELOOP = 114;
-pub const EMSGSIZE = 115;
-pub const ENETDOWN = 116;
-pub const ENETRESET = 117;
-pub const ENETUNREACH = 118;
-pub const ENOBUFS = 119;
-pub const ENODATA = 120;
-pub const ENOLINK = 121;
-pub const ENOMSG = 122;
-pub const ENOPROTOOPT = 123;
-pub const ENOSR = 124;
-pub const ENOSTR = 125;
-pub const ENOTCONN = 126;
-pub const ENOTRECOVERABLE = 127;
-pub const ENOTSOCK = 128;
-pub const ENOTSUP = 129;
-pub const EOPNOTSUPP = 130;
-pub const EOTHER = 131;
-pub const EOVERFLOW = 132;
-pub const EOWNERDEAD = 133;
-pub const EPROTO = 134;
-pub const EPROTONOSUPPORT = 135;
-pub const EPROTOTYPE = 136;
-pub const ETIME = 137;
-pub const ETIMEDOUT = 138;
-pub const ETXTBSY = 139;
-pub const EWOULDBLOCK = 140;
-pub const EDQUOT = 10069;
-
pub const F_OK = 0;
/// Remove directory instead of unlinking file
diff --git a/lib/std/os/darwin.zig b/lib/std/os/darwin.zig
index 572b470239..5f9684b96d 100644
--- a/lib/std/os/darwin.zig
+++ b/lib/std/os/darwin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub usingnamespace std.c;
pub usingnamespace @import("bits.zig");
diff --git a/lib/std/os/dragonfly.zig b/lib/std/os/dragonfly.zig
index 572b470239..5f9684b96d 100644
--- a/lib/std/os/dragonfly.zig
+++ b/lib/std/os/dragonfly.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub usingnamespace std.c;
pub usingnamespace @import("bits.zig");
diff --git a/lib/std/os/freebsd.zig b/lib/std/os/freebsd.zig
index 572b470239..5f9684b96d 100644
--- a/lib/std/os/freebsd.zig
+++ b/lib/std/os/freebsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub usingnamespace std.c;
pub usingnamespace @import("bits.zig");
diff --git a/lib/std/os/haiku.zig b/lib/std/os/haiku.zig
index a713a009ad..5f9684b96d 100644
--- a/lib/std/os/haiku.zig
+++ b/lib/std/os/haiku.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub usingnamespace std.c;
pub usingnamespace @import("bits.zig");
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index ca8f0907e1..369fae8f53 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// This file provides the system interface functions for Linux matching those
// that are provided by libc, whether or not libc is linked. The following
// abstractions are made:
@@ -91,9 +86,10 @@ fn splitValue64(val: i64) [2]u32 {
}
/// Get the errno from a syscall return value, or 0 for no error.
-pub fn getErrno(r: usize) u12 {
+pub fn getErrno(r: usize) E {
const signed_r = @bitCast(isize, r);
- return if (signed_r > -4096 and signed_r < 0) @intCast(u12, -signed_r) else 0;
+ const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0;
+ return @intToEnum(E, int);
}
pub fn dup(old: i32) usize {
@@ -281,7 +277,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
if (@hasField(SYS, "mmap2")) {
// Make sure the offset is also specified in multiples of page size
if ((offset & (MMAP2_UNIT - 1)) != 0)
- return @bitCast(usize, @as(isize, -EINVAL));
+ return @bitCast(usize, -@as(isize, @enumToInt(E.INVAL)));
return syscall6(
.mmap2,
@@ -746,7 +742,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
const rc = f(clk_id, tp);
switch (rc) {
- 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
+ 0, @bitCast(usize, -@as(isize, @enumToInt(E.INVAL))) => return rc,
else => {},
}
}
@@ -764,7 +760,7 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
return f(clk, ts);
}
- return @bitCast(usize, @as(isize, -ENOSYS));
+ return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS)));
}
pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
@@ -961,7 +957,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
.sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),
};
- if (getErrno(result) != 0) return result;
+ if (getErrno(result) != .SUCCESS) return result;
if (oact) |old| {
old.handler.handler = oldksa.handler;
@@ -1202,7 +1198,7 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
@ptrToInt(statx_buf),
);
}
- return @bitCast(usize, @as(isize, -ENOSYS));
+ return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS)));
}
pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig
index 469b7299d1..ded72fd100 100644
--- a/lib/std/os/linux/arm-eabi.zig
+++ b/lib/std/os/linux/arm-eabi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig
index 4c8306c048..92942a16ce 100644
--- a/lib/std/os/linux/arm64.zig
+++ b/lib/std/os/linux/arm64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig
index 86993083e3..cff4acaeee 100644
--- a/lib/std/os/linux/bpf.zig
+++ b/lib/std/os/linux/bpf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace std.os.linux;
const std = @import("../../std.zig");
const errno = getErrno;
@@ -1508,13 +1503,13 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries
attr.map_create.max_entries = max_entries;
const rc = bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
- return switch (errno(rc)) {
- 0 => @intCast(fd_t, rc),
- EINVAL => error.MapTypeOrAttrInvalid,
- ENOMEM => error.SystemResources,
- EPERM => error.AccessDenied,
- else => |err| unexpectedErrno(err),
- };
+ switch (errno(rc)) {
+ .SUCCESS => return @intCast(fd_t, rc),
+ .INVAL => return error.MapTypeOrAttrInvalid,
+ .NOMEM => return error.SystemResources,
+ .PERM => return error.AccessDenied,
+ else => |err| return unexpectedErrno(err),
+ }
}
test "map_create" {
@@ -1533,12 +1528,12 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {
const rc = bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr));
switch (errno(rc)) {
- 0 => return,
- EBADF => return error.BadFd,
- EFAULT => unreachable,
- EINVAL => return error.FieldInAttrNeedsZeroing,
- ENOENT => return error.NotFound,
- EPERM => return error.AccessDenied,
+ .SUCCESS => return,
+ .BADF => return error.BadFd,
+ .FAULT => unreachable,
+ .INVAL => return error.FieldInAttrNeedsZeroing,
+ .NOENT => return error.NotFound,
+ .PERM => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -1555,13 +1550,13 @@ pub fn map_update_elem(fd: fd_t, key: []const u8, value: []const u8, flags: u64)
const rc = bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr));
switch (errno(rc)) {
- 0 => return,
- E2BIG => return error.ReachedMaxEntries,
- EBADF => return error.BadFd,
- EFAULT => unreachable,
- EINVAL => return error.FieldInAttrNeedsZeroing,
- ENOMEM => return error.SystemResources,
- EPERM => return error.AccessDenied,
+ .SUCCESS => return,
+ .@"2BIG" => return error.ReachedMaxEntries,
+ .BADF => return error.BadFd,
+ .FAULT => unreachable,
+ .INVAL => return error.FieldInAttrNeedsZeroing,
+ .NOMEM => return error.SystemResources,
+ .PERM => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -1576,12 +1571,12 @@ pub fn map_delete_elem(fd: fd_t, key: []const u8) !void {
const rc = bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr));
switch (errno(rc)) {
- 0 => return,
- EBADF => return error.BadFd,
- EFAULT => unreachable,
- EINVAL => return error.FieldInAttrNeedsZeroing,
- ENOENT => return error.NotFound,
- EPERM => return error.AccessDenied,
+ .SUCCESS => return,
+ .BADF => return error.BadFd,
+ .FAULT => unreachable,
+ .INVAL => return error.FieldInAttrNeedsZeroing,
+ .NOENT => return error.NotFound,
+ .PERM => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -1639,11 +1634,11 @@ pub fn prog_load(
const rc = bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
return switch (errno(rc)) {
- 0 => @intCast(fd_t, rc),
- EACCES => error.UnsafeProgram,
- EFAULT => unreachable,
- EINVAL => error.InvalidProgram,
- EPERM => error.AccessDenied,
+ .SUCCESS => @intCast(fd_t, rc),
+ .ACCES => error.UnsafeProgram,
+ .FAULT => unreachable,
+ .INVAL => error.InvalidProgram,
+ .PERM => error.AccessDenied,
else => |err| unexpectedErrno(err),
};
}
diff --git a/lib/std/os/linux/bpf/btf.zig b/lib/std/os/linux/bpf/btf.zig
index d8a0cb57a9..35eaf10561 100644
--- a/lib/std/os/linux/bpf/btf.zig
+++ b/lib/std/os/linux/bpf/btf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const magic = 0xeb9f;
const version = 1;
diff --git a/lib/std/os/linux/bpf/btf_ext.zig b/lib/std/os/linux/bpf/btf_ext.zig
index ca713f1910..05d5d57059 100644
--- a/lib/std/os/linux/bpf/btf_ext.zig
+++ b/lib/std/os/linux/bpf/btf_ext.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const Header = packed struct {
magic: u16,
version: u8,
diff --git a/lib/std/os/linux/bpf/helpers.zig b/lib/std/os/linux/bpf/helpers.zig
index 757c37949b..86c86c1ec5 100644
--- a/lib/std/os/linux/bpf/helpers.zig
+++ b/lib/std/os/linux/bpf/helpers.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const kern = @import("kern.zig");
// in BPF, all the helper calls
diff --git a/lib/std/os/linux/bpf/kern.zig b/lib/std/os/linux/bpf/kern.zig
index 4d489eef5c..729495e91d 100644
--- a/lib/std/os/linux/bpf/kern.zig
+++ b/lib/std/os/linux/bpf/kern.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../../std.zig");
const in_bpf_program = switch (std.builtin.cpu.arch) {
diff --git a/lib/std/os/linux/i386.zig b/lib/std/os/linux/i386.zig
index 2ec34bac40..70178656d5 100644
--- a/lib/std/os/linux/i386.zig
+++ b/lib/std/os/linux/i386.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig
index b6bde34b7d..b74a7da3dd 100644
--- a/lib/std/os/linux/io_uring.zig
+++ b/lib/std/os/linux/io_uring.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const assert = std.debug.assert;
const builtin = std.builtin;
@@ -54,19 +49,19 @@ pub const IO_Uring = struct {
const res = linux.io_uring_setup(entries, p);
switch (linux.getErrno(res)) {
- 0 => {},
- linux.EFAULT => return error.ParamsOutsideAccessibleAddressSpace,
+ .SUCCESS => {},
+ .FAULT => return error.ParamsOutsideAccessibleAddressSpace,
// The resv array contains non-zero data, p.flags contains an unsupported flag,
// entries out of bounds, IORING_SETUP_SQ_AFF was specified without IORING_SETUP_SQPOLL,
// or IORING_SETUP_CQSIZE was specified but io_uring_params.cq_entries was invalid:
- linux.EINVAL => return error.ArgumentsInvalid,
- linux.EMFILE => return error.ProcessFdQuotaExceeded,
- linux.ENFILE => return error.SystemFdQuotaExceeded,
- linux.ENOMEM => return error.SystemResources,
+ .INVAL => return error.ArgumentsInvalid,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOMEM => return error.SystemResources,
// IORING_SETUP_SQPOLL was specified but effective user ID lacks sufficient privileges,
// or a container seccomp policy prohibits io_uring syscalls:
- linux.EPERM => return error.PermissionDenied,
- linux.ENOSYS => return error.SystemOutdated,
+ .PERM => return error.PermissionDenied,
+ .NOSYS => return error.SystemOutdated,
else => |errno| return os.unexpectedErrno(errno),
}
const fd = @intCast(os.fd_t, res);
@@ -180,31 +175,31 @@ pub const IO_Uring = struct {
assert(self.fd >= 0);
const res = linux.io_uring_enter(self.fd, to_submit, min_complete, flags, null);
switch (linux.getErrno(res)) {
- 0 => {},
+ .SUCCESS => {},
// The kernel was unable to allocate memory or ran out of resources for the request.
// The application should wait for some completions and try again:
- linux.EAGAIN => return error.SystemResources,
+ .AGAIN => return error.SystemResources,
// The SQE `fd` is invalid, or IOSQE_FIXED_FILE was set but no files were registered:
- linux.EBADF => return error.FileDescriptorInvalid,
+ .BADF => return error.FileDescriptorInvalid,
// The file descriptor is valid, but the ring is not in the right state.
// See io_uring_register(2) for how to enable the ring.
- linux.EBADFD => return error.FileDescriptorInBadState,
+ .BADFD => return error.FileDescriptorInBadState,
// The application attempted to overcommit the number of requests it can have pending.
// The application should wait for some completions and try again:
- linux.EBUSY => return error.CompletionQueueOvercommitted,
+ .BUSY => return error.CompletionQueueOvercommitted,
// The SQE is invalid, or valid but the ring was setup with IORING_SETUP_IOPOLL:
- linux.EINVAL => return error.SubmissionQueueEntryInvalid,
+ .INVAL => return error.SubmissionQueueEntryInvalid,
// The buffer is outside the process' accessible address space, or IORING_OP_READ_FIXED
// or IORING_OP_WRITE_FIXED was specified but no buffers were registered, or the range
// described by `addr` and `len` is not within the buffer registered at `buf_index`:
- linux.EFAULT => return error.BufferInvalid,
- linux.ENXIO => return error.RingShuttingDown,
+ .FAULT => return error.BufferInvalid,
+ .NXIO => return error.RingShuttingDown,
// The kernel believes our `self.fd` does not refer to an io_uring instance,
// or the opcode is valid but not supported by this kernel (more likely):
- linux.EOPNOTSUPP => return error.OpcodeNotSupported,
+ .OPNOTSUPP => return error.OpcodeNotSupported,
// The operation was interrupted by a delivery of a signal before it could complete.
// This can happen while waiting for events with IORING_ENTER_GETEVENTS:
- linux.EINTR => return error.SignalInterrupt,
+ .INTR => return error.SignalInterrupt,
else => |errno| return os.unexpectedErrno(errno),
}
return @intCast(u32, res);
@@ -681,22 +676,22 @@ pub const IO_Uring = struct {
fn handle_registration_result(res: usize) !void {
switch (linux.getErrno(res)) {
- 0 => {},
+ .SUCCESS => {},
// One or more fds in the array are invalid, or the kernel does not support sparse sets:
- linux.EBADF => return error.FileDescriptorInvalid,
- linux.EBUSY => return error.FilesAlreadyRegistered,
- linux.EINVAL => return error.FilesEmpty,
+ .BADF => return error.FileDescriptorInvalid,
+ .BUSY => return error.FilesAlreadyRegistered,
+ .INVAL => return error.FilesEmpty,
// Adding `nr_args` file references would exceed the maximum allowed number of files the
// user is allowed to have according to the per-user RLIMIT_NOFILE resource limit and
// the CAP_SYS_RESOURCE capability is not set, or `nr_args` exceeds the maximum allowed
// for a fixed file set (older kernels have a limit of 1024 files vs 64K files):
- linux.EMFILE => return error.UserFdQuotaExceeded,
+ .MFILE => return error.UserFdQuotaExceeded,
// Insufficient kernel resources, or the caller had a non-zero RLIMIT_MEMLOCK soft
// resource limit but tried to lock more memory than the limit permitted (not enforced
// when the process is privileged with CAP_IPC_LOCK):
- linux.ENOMEM => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
// Attempt to register files on a ring already registering files or being torn down:
- linux.ENXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles,
+ .NXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles,
else => |errno| return os.unexpectedErrno(errno),
}
}
@@ -706,8 +701,8 @@ pub const IO_Uring = struct {
assert(self.fd >= 0);
const res = linux.io_uring_register(self.fd, .UNREGISTER_FILES, null, 0);
switch (linux.getErrno(res)) {
- 0 => {},
- linux.ENXIO => return error.FilesNotRegistered,
+ .SUCCESS => {},
+ .NXIO => return error.FilesNotRegistered,
else => |errno| return os.unexpectedErrno(errno),
}
}
@@ -1272,8 +1267,8 @@ test "write/read" {
const cqe_read = try ring.copy_cqe();
// Prior to Linux Kernel 5.6 this is the only way to test for read/write support:
// https://lwn.net/Articles/809820/
- if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
- if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_write.err() == .INVAL) return error.SkipZigTest;
+ if (cqe_read.err() == .INVAL) return error.SkipZigTest;
try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x11111111,
.res = buffer_write.len,
@@ -1322,11 +1317,11 @@ test "openat" {
const cqe_openat = try ring.copy_cqe();
try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
- if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_openat.err() == .INVAL) return error.SkipZigTest;
// AT_FDCWD is not fully supported before kernel 5.6:
// See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
// We use IORING_FEAT_RW_CUR_POS to know if we are pre-5.6 since that feature was added in 5.6.
- if (cqe_openat.res == -linux.EBADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) {
+ if (cqe_openat.err() == .BADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) {
return error.SkipZigTest;
}
if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
@@ -1357,7 +1352,7 @@ test "close" {
try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe_close = try ring.copy_cqe();
- if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_close.err() == .INVAL) return error.SkipZigTest;
try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x44444444,
.res = 0,
@@ -1397,9 +1392,9 @@ test "accept/connect/send/recv" {
try testing.expectEqual(@as(u32, 1), try ring.submit());
var cqe_accept = try ring.copy_cqe();
- if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_accept.err() == .INVAL) return error.SkipZigTest;
var cqe_connect = try ring.copy_cqe();
- if (cqe_connect.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_connect.err() == .INVAL) return error.SkipZigTest;
// The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first:
if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) {
@@ -1425,7 +1420,7 @@ test "accept/connect/send/recv" {
try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_send = try ring.copy_cqe();
- if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_send.err() == .INVAL) return error.SkipZigTest;
try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xeeeeeeee,
.res = buffer_send.len,
@@ -1433,7 +1428,7 @@ test "accept/connect/send/recv" {
}, cqe_send);
const cqe_recv = try ring.copy_cqe();
- if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
+ if (cqe_recv.err() == .INVAL) return error.SkipZigTest;
try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xffffffff,
.res = buffer_recv.len,
@@ -1466,7 +1461,7 @@ test "timeout (after a relative time)" {
try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x55555555,
- .res = -linux.ETIME,
+ .res = -@as(i32, @enumToInt(linux.E.TIME)),
.flags = 0,
}, cqe);
@@ -1535,14 +1530,14 @@ test "timeout_remove" {
// We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.
// We don't want to skip this test for newer kernels.
if (cqe_timeout.user_data == 0x99999999 and
- cqe_timeout.res == -linux.EBADF and
+ cqe_timeout.err() == .BADF and
(ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0)
{
return error.SkipZigTest;
}
try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x88888888,
- .res = -linux.ECANCELED,
+ .res = -@as(i32, @enumToInt(linux.E.CANCELED)),
.flags = 0,
}, cqe_timeout);
@@ -1578,15 +1573,15 @@ test "fallocate" {
try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe = try ring.copy_cqe();
- switch (-cqe.res) {
- 0 => {},
+ switch (cqe.err()) {
+ .SUCCESS => {},
// This kernel's io_uring does not yet implement fallocate():
- linux.EINVAL => return error.SkipZigTest,
+ .INVAL => return error.SkipZigTest,
// This kernel does not implement fallocate():
- linux.ENOSYS => return error.SkipZigTest,
+ .NOSYS => return error.SkipZigTest,
// The filesystem containing the file referred to by fd does not support this operation;
// or the mode is not supported by the filesystem containing the file referred to by fd:
- linux.EOPNOTSUPP => return error.SkipZigTest,
+ .OPNOTSUPP => return error.SkipZigTest,
else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
}
try testing.expectEqual(linux.io_uring_cqe{
diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig
index 85157f04f8..5cff1e9265 100644
--- a/lib/std/os/linux/mips.zig
+++ b/lib/std/os/linux/mips.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig
index 611eee1c5f..c48d86a155 100644
--- a/lib/std/os/linux/powerpc.zig
+++ b/lib/std/os/linux/powerpc.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig
index 611eee1c5f..c48d86a155 100644
--- a/lib/std/os/linux/powerpc64.zig
+++ b/lib/std/os/linux/powerpc64.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig
index 3e2b15b599..dfc7e164e8 100644
--- a/lib/std/os/linux/riscv64.zig
+++ b/lib/std/os/linux/riscv64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig
index f347a0e88e..1c08d39c05 100644
--- a/lib/std/os/linux/sparc64.zig
+++ b/lib/std/os/linux/sparc64.zig
@@ -169,7 +169,9 @@ pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags:
pub const restore = restore_rt;
-pub fn restore_rt() callconv(.Naked) void {
+// Need to use C ABI here instead of naked
+// to prevent an infinite loop when calling rt_sigreturn.
+pub fn restore_rt() callconv(.C) void {
return asm volatile ("t 0x6d"
:
: [number] "{g1}" (@enumToInt(SYS.rt_sigreturn))
diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig
index 2e98fe359d..e45c9dbb99 100644
--- a/lib/std/os/linux/test.zig
+++ b/lib/std/os/linux/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const builtin = std.builtin;
const linux = std.os.linux;
@@ -22,9 +17,9 @@ test "fallocate" {
const len: i64 = 65536;
switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
- 0 => {},
- linux.ENOSYS => return error.SkipZigTest,
- linux.EOPNOTSUPP => return error.SkipZigTest,
+ .SUCCESS => {},
+ .NOSYS => return error.SkipZigTest,
+ .OPNOTSUPP => return error.SkipZigTest,
else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
}
@@ -37,11 +32,11 @@ test "getpid" {
test "timer" {
const epoll_fd = linux.epoll_create();
- var err: usize = linux.getErrno(epoll_fd);
- try expect(err == 0);
+ var err: linux.E = linux.getErrno(epoll_fd);
+ try expect(err == .SUCCESS);
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
- try expect(linux.getErrno(timer_fd) == 0);
+ try expect(linux.getErrno(timer_fd) == .SUCCESS);
const time_interval = linux.timespec{
.tv_sec = 0,
@@ -53,22 +48,22 @@ test "timer" {
.it_value = time_interval,
};
- err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
- try expect(err == 0);
+ err = linux.getErrno(linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null));
+ try expect(err == .SUCCESS);
var event = linux.epoll_event{
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
.data = linux.epoll_data{ .ptr = 0 },
};
- err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
- try expect(err == 0);
+ err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event));
+ try expect(err == .SUCCESS);
const events_one: linux.epoll_event = undefined;
var events = [_]linux.epoll_event{events_one} ** 8;
- // TODO implicit cast from *[N]T to [*]T
- err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
+ err = linux.getErrno(linux.epoll_wait(@intCast(i32, epoll_fd), &events, 8, -1));
+ try expect(err == .SUCCESS);
}
test "statx" {
@@ -81,15 +76,15 @@ test "statx" {
var statx_buf: linux.Statx = undefined;
switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
- 0 => {},
+ .SUCCESS => {},
// The statx syscall was only introduced in linux 4.11
- linux.ENOSYS => return error.SkipZigTest,
+ .NOSYS => return error.SkipZigTest,
else => unreachable,
}
var stat_buf: linux.kernel_stat = undefined;
switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
- 0 => {},
+ .SUCCESS => {},
else => unreachable,
}
diff --git a/lib/std/os/linux/thumb.zig b/lib/std/os/linux/thumb.zig
index 85f8bfc52b..d965e4430e 100644
--- a/lib/std/os/linux/thumb.zig
+++ b/lib/std/os/linux/thumb.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
// The syscall interface is identical to the ARM one but we're facing an extra
diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig
index 5649cadd8b..47230cf786 100644
--- a/lib/std/os/linux/tls.zig
+++ b/lib/std/os/linux/tls.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const os = std.os;
const mem = std.mem;
diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig
index f42bb06452..f059ccad4e 100644
--- a/lib/std/os/linux/vdso.zig
+++ b/lib/std/os/linux/vdso.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const elf = std.elf;
const linux = std.os.linux;
diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig
index 5aa32c56c3..c403742d3d 100644
--- a/lib/std/os/linux/x86_64.zig
+++ b/lib/std/os/linux/x86_64.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("../bits/linux.zig");
pub fn syscall0(number: SYS) usize {
diff --git a/lib/std/os/netbsd.zig b/lib/std/os/netbsd.zig
index 572b470239..5f9684b96d 100644
--- a/lib/std/os/netbsd.zig
+++ b/lib/std/os/netbsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub usingnamespace std.c;
pub usingnamespace @import("bits.zig");
diff --git a/lib/std/os/openbsd.zig b/lib/std/os/openbsd.zig
index 572b470239..5f9684b96d 100644
--- a/lib/std/os/openbsd.zig
+++ b/lib/std/os/openbsd.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
pub usingnamespace std.c;
pub usingnamespace @import("bits.zig");
diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig
index 6184c97706..53a040294e 100644
--- a/lib/std/os/test.zig
+++ b/lib/std/os/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const os = std.os;
const testing = std.testing;
@@ -786,3 +781,17 @@ test "dup & dup2" {
var buf: [7]u8 = undefined;
try testing.expectEqualStrings("dupdup2", buf[0..try file.readAll(&buf)]);
}
+
+test "writev longer than IOV_MAX" {
+ if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
+
+ var tmp = tmpDir(.{});
+ defer tmp.cleanup();
+
+ var file = try tmp.dir.createFile("pwritev", .{});
+ defer file.close();
+
+ const iovecs = [_]os.iovec_const{.{ .iov_base = "a", .iov_len = 1 }} ** (os.IOV_MAX + 1);
+ const amt = try file.writev(&iovecs);
+ try testing.expectEqual(@as(usize, os.IOV_MAX), amt);
+}
diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig
index 4bb8e37559..b4582c121d 100644
--- a/lib/std/os/uefi.zig
+++ b/lib/std/os/uefi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
/// A protocol is an interface identified by a GUID.
diff --git a/lib/std/os/uefi/protocols.zig b/lib/std/os/uefi/protocols.zig
index 68dafdcecb..353c628a05 100644
--- a/lib/std/os/uefi/protocols.zig
+++ b/lib/std/os/uefi/protocols.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const LoadedImageProtocol = @import("protocols/loaded_image_protocol.zig").LoadedImageProtocol;
pub const loaded_image_device_path_protocol_guid = @import("protocols/loaded_image_protocol.zig").loaded_image_device_path_protocol_guid;
diff --git a/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig b/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
index 3dfe972331..ee79569233 100644
--- a/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
+++ b/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/device_path_protocol.zig b/lib/std/os/uefi/protocols/device_path_protocol.zig
index d6b239fbbb..df59498822 100644
--- a/lib/std/os/uefi/protocols/device_path_protocol.zig
+++ b/lib/std/os/uefi/protocols/device_path_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/edid_active_protocol.zig b/lib/std/os/uefi/protocols/edid_active_protocol.zig
index 750ff2833b..fcdef78d83 100644
--- a/lib/std/os/uefi/protocols/edid_active_protocol.zig
+++ b/lib/std/os/uefi/protocols/edid_active_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/edid_discovered_protocol.zig b/lib/std/os/uefi/protocols/edid_discovered_protocol.zig
index fdbe594563..00b59cb6c8 100644
--- a/lib/std/os/uefi/protocols/edid_discovered_protocol.zig
+++ b/lib/std/os/uefi/protocols/edid_discovered_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/edid_override_protocol.zig b/lib/std/os/uefi/protocols/edid_override_protocol.zig
index ad3a0939b5..8bf848c59a 100644
--- a/lib/std/os/uefi/protocols/edid_override_protocol.zig
+++ b/lib/std/os/uefi/protocols/edid_override_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Handle = uefi.Handle;
diff --git a/lib/std/os/uefi/protocols/file_protocol.zig b/lib/std/os/uefi/protocols/file_protocol.zig
index a1d001065c..1f80df0af2 100644
--- a/lib/std/os/uefi/protocols/file_protocol.zig
+++ b/lib/std/os/uefi/protocols/file_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Time = uefi.Time;
diff --git a/lib/std/os/uefi/protocols/graphics_output_protocol.zig b/lib/std/os/uefi/protocols/graphics_output_protocol.zig
index 4cb7744e8a..a3bb50f0d2 100644
--- a/lib/std/os/uefi/protocols/graphics_output_protocol.zig
+++ b/lib/std/os/uefi/protocols/graphics_output_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Status = uefi.Status;
diff --git a/lib/std/os/uefi/protocols/hii.zig b/lib/std/os/uefi/protocols/hii.zig
index 9d85f293b3..5e3c23d22a 100644
--- a/lib/std/os/uefi/protocols/hii.zig
+++ b/lib/std/os/uefi/protocols/hii.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/hii_database_protocol.zig b/lib/std/os/uefi/protocols/hii_database_protocol.zig
index 33014e1cb7..e34f72c2f3 100644
--- a/lib/std/os/uefi/protocols/hii_database_protocol.zig
+++ b/lib/std/os/uefi/protocols/hii_database_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Status = uefi.Status;
diff --git a/lib/std/os/uefi/protocols/hii_popup_protocol.zig b/lib/std/os/uefi/protocols/hii_popup_protocol.zig
index ebbc1608b7..cf6bdf6da5 100644
--- a/lib/std/os/uefi/protocols/hii_popup_protocol.zig
+++ b/lib/std/os/uefi/protocols/hii_popup_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Status = uefi.Status;
diff --git a/lib/std/os/uefi/protocols/ip6_config_protocol.zig b/lib/std/os/uefi/protocols/ip6_config_protocol.zig
index d6af0e5f39..aa9d783fd8 100644
--- a/lib/std/os/uefi/protocols/ip6_config_protocol.zig
+++ b/lib/std/os/uefi/protocols/ip6_config_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Event = uefi.Event;
diff --git a/lib/std/os/uefi/protocols/ip6_protocol.zig b/lib/std/os/uefi/protocols/ip6_protocol.zig
index fbca959656..dbe0f16396 100644
--- a/lib/std/os/uefi/protocols/ip6_protocol.zig
+++ b/lib/std/os/uefi/protocols/ip6_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Event = uefi.Event;
diff --git a/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig b/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig
index 69a410c01c..97ab1a431c 100644
--- a/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig
+++ b/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Handle = uefi.Handle;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/loaded_image_protocol.zig b/lib/std/os/uefi/protocols/loaded_image_protocol.zig
index a5c5610f9b..b8afcb1063 100644
--- a/lib/std/os/uefi/protocols/loaded_image_protocol.zig
+++ b/lib/std/os/uefi/protocols/loaded_image_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Handle = uefi.Handle;
diff --git a/lib/std/os/uefi/protocols/managed_network_protocol.zig b/lib/std/os/uefi/protocols/managed_network_protocol.zig
index 0da6d902f3..122482be23 100644
--- a/lib/std/os/uefi/protocols/managed_network_protocol.zig
+++ b/lib/std/os/uefi/protocols/managed_network_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Event = uefi.Event;
diff --git a/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig b/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig
index f0b8c5fb15..e9657e4456 100644
--- a/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig
+++ b/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Handle = uefi.Handle;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/rng_protocol.zig b/lib/std/os/uefi/protocols/rng_protocol.zig
index 25f7c936c3..a32b202f44 100644
--- a/lib/std/os/uefi/protocols/rng_protocol.zig
+++ b/lib/std/os/uefi/protocols/rng_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Status = uefi.Status;
diff --git a/lib/std/os/uefi/protocols/shell_parameters_protocol.zig b/lib/std/os/uefi/protocols/shell_parameters_protocol.zig
index 338d88fc9b..afbd26e939 100644
--- a/lib/std/os/uefi/protocols/shell_parameters_protocol.zig
+++ b/lib/std/os/uefi/protocols/shell_parameters_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const FileHandle = uefi.FileHandle;
diff --git a/lib/std/os/uefi/protocols/simple_file_system_protocol.zig b/lib/std/os/uefi/protocols/simple_file_system_protocol.zig
index 68f08ebff8..119c1e6587 100644
--- a/lib/std/os/uefi/protocols/simple_file_system_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_file_system_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const FileProtocol = uefi.protocols.FileProtocol;
diff --git a/lib/std/os/uefi/protocols/simple_network_protocol.zig b/lib/std/os/uefi/protocols/simple_network_protocol.zig
index 1cd93bc491..a3743ac2c1 100644
--- a/lib/std/os/uefi/protocols/simple_network_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_network_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/simple_pointer_protocol.zig b/lib/std/os/uefi/protocols/simple_pointer_protocol.zig
index b76b5bc512..d217ab5930 100644
--- a/lib/std/os/uefi/protocols/simple_pointer_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_pointer_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig b/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
index 0cc1416641..4a2b098e61 100644
--- a/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/simple_text_input_protocol.zig b/lib/std/os/uefi/protocols/simple_text_input_protocol.zig
index 47e632021b..8102ea9955 100644
--- a/lib/std/os/uefi/protocols/simple_text_input_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_text_input_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig
index 6fb56724c7..84f540cb78 100644
--- a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Status = uefi.Status;
diff --git a/lib/std/os/uefi/protocols/udp6_protocol.zig b/lib/std/os/uefi/protocols/udp6_protocol.zig
index c2e4228998..46c76beaa6 100644
--- a/lib/std/os/uefi/protocols/udp6_protocol.zig
+++ b/lib/std/os/uefi/protocols/udp6_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const Event = uefi.Event;
diff --git a/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig b/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig
index 620f015722..811692adc3 100644
--- a/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig
+++ b/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Handle = uefi.Handle;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/status.zig b/lib/std/os/uefi/status.zig
index 48b8008b91..09bc5030eb 100644
--- a/lib/std/os/uefi/status.zig
+++ b/lib/std/os/uefi/status.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const high_bit = 1 << @typeInfo(usize).Int.bits - 1;
pub const Status = enum(usize) {
diff --git a/lib/std/os/uefi/tables.zig b/lib/std/os/uefi/tables.zig
index 649fe95cd2..0011c80a9c 100644
--- a/lib/std/os/uefi/tables.zig
+++ b/lib/std/os/uefi/tables.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const AllocateType = @import("tables/boot_services.zig").AllocateType;
pub const BootServices = @import("tables/boot_services.zig").BootServices;
pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable;
diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig
index 8617642eaf..31ac352089 100644
--- a/lib/std/os/uefi/tables/boot_services.zig
+++ b/lib/std/os/uefi/tables/boot_services.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/tables/configuration_table.zig b/lib/std/os/uefi/tables/configuration_table.zig
index 00c8f2f429..0ac3bd73c8 100644
--- a/lib/std/os/uefi/tables/configuration_table.zig
+++ b/lib/std/os/uefi/tables/configuration_table.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
diff --git a/lib/std/os/uefi/tables/runtime_services.zig b/lib/std/os/uefi/tables/runtime_services.zig
index 2d1a1cdb82..c3c59f957f 100644
--- a/lib/std/os/uefi/tables/runtime_services.zig
+++ b/lib/std/os/uefi/tables/runtime_services.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const Guid = uefi.Guid;
const TableHeader = uefi.tables.TableHeader;
diff --git a/lib/std/os/uefi/tables/system_table.zig b/lib/std/os/uefi/tables/system_table.zig
index c5b6c5f1e9..b52104f9c7 100644
--- a/lib/std/os/uefi/tables/system_table.zig
+++ b/lib/std/os/uefi/tables/system_table.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const uefi = @import("std").os.uefi;
const BootServices = uefi.tables.BootServices;
const ConfigurationTable = uefi.tables.ConfigurationTable;
diff --git a/lib/std/os/uefi/tables/table_header.zig b/lib/std/os/uefi/tables/table_header.zig
index 8af1895cad..d5d4094232 100644
--- a/lib/std/os/uefi/tables/table_header.zig
+++ b/lib/std/os/uefi/tables/table_header.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const TableHeader = extern struct {
signature: u64,
revision: u32,
diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig
index 3965ae77a0..708f445ee4 100644
--- a/lib/std/os/wasi.zig
+++ b/lib/std/os/wasi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// wasi_snapshot_preview1 spec available (in witx format) here:
// * typenames -- https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
// * module -- https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/wasi_snapshot_preview1.witx
@@ -83,6 +78,6 @@ pub extern "wasi_snapshot_preview1" fn sock_send(sock: fd_t, si_data: *const cio
pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;
/// Get the errno from a syscall return value, or 0 for no error.
-pub fn getErrno(r: errno_t) usize {
+pub fn getErrno(r: errno_t) errno_t {
return r;
}
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index 04ce433758..6972de597c 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// This file contains thin wrappers around Windows-specific APIs, with these
// specific goals in mind:
// * Convert "errno"-style error codes into Zig errors.
diff --git a/lib/std/os/windows/advapi32.zig b/lib/std/os/windows/advapi32.zig
index 6fa9ae2b45..db77c4b7e9 100644
--- a/lib/std/os/windows/advapi32.zig
+++ b/lib/std/os/windows/advapi32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub extern "advapi32" fn RegOpenKeyExW(
diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig
index 59a2a87415..7bc0e131ea 100644
--- a/lib/std/os/windows/bits.zig
+++ b/lib/std/os/windows/bits.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Platform-dependent types and values that are used along with OS-specific APIs.
const std = @import("../../std.zig");
diff --git a/lib/std/os/windows/gdi32.zig b/lib/std/os/windows/gdi32.zig
index c91e1d487c..132fd80a34 100644
--- a/lib/std/os/windows/gdi32.zig
+++ b/lib/std/os/windows/gdi32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub const PIXELFORMATDESCRIPTOR = extern struct {
diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig
index a04314324d..6996ad9991 100644
--- a/lib/std/os/windows/kernel32.zig
+++ b/lib/std/os/windows/kernel32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub extern "kernel32" fn AddVectoredExceptionHandler(First: c_ulong, Handler: ?VECTORED_EXCEPTION_HANDLER) callconv(WINAPI) ?*c_void;
diff --git a/lib/std/os/windows/lang.zig b/lib/std/os/windows/lang.zig
index 40b363cfae..b173a62a73 100644
--- a/lib/std/os/windows/lang.zig
+++ b/lib/std/os/windows/lang.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const NEUTRAL = 0x00;
pub const INVARIANT = 0x7f;
pub const AFRIKAANS = 0x36;
diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig
index ddc08e4bb2..5a0154db6f 100644
--- a/lib/std/os/windows/ntdll.zig
+++ b/lib/std/os/windows/ntdll.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub extern "NtDll" fn RtlGetVersion(
diff --git a/lib/std/os/windows/ntstatus.zig b/lib/std/os/windows/ntstatus.zig
index 11668a7206..41ba3ac81f 100644
--- a/lib/std/os/windows/ntstatus.zig
+++ b/lib/std/os/windows/ntstatus.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
/// NTSTATUS codes from https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55?
pub const NTSTATUS = enum(u32) {
/// The caller specified WaitAny for WaitType and one of the dispatcher
diff --git a/lib/std/os/windows/ole32.zig b/lib/std/os/windows/ole32.zig
index bf1eabd63e..e4e0432659 100644
--- a/lib/std/os/windows/ole32.zig
+++ b/lib/std/os/windows/ole32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub extern "ole32" fn CoTaskMemFree(pv: LPVOID) callconv(WINAPI) void;
diff --git a/lib/std/os/windows/psapi.zig b/lib/std/os/windows/psapi.zig
index 2952df1635..cebe03d3aa 100644
--- a/lib/std/os/windows/psapi.zig
+++ b/lib/std/os/windows/psapi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub extern "psapi" fn EmptyWorkingSet(hProcess: HANDLE) callconv(WINAPI) BOOL;
diff --git a/lib/std/os/windows/shell32.zig b/lib/std/os/windows/shell32.zig
index d184ba1036..8739f9301e 100644
--- a/lib/std/os/windows/shell32.zig
+++ b/lib/std/os/windows/shell32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub extern "shell32" fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*:0]WCHAR) callconv(WINAPI) HRESULT;
diff --git a/lib/std/os/windows/sublang.zig b/lib/std/os/windows/sublang.zig
index ecc46dbfc4..e9929c6d79 100644
--- a/lib/std/os/windows/sublang.zig
+++ b/lib/std/os/windows/sublang.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const NEUTRAL = 0x00;
pub const DEFAULT = 0x01;
pub const SYS_DEFAULT = 0x02;
diff --git a/lib/std/os/windows/test.zig b/lib/std/os/windows/test.zig
index 8c18d413ca..8e4d88615c 100644
--- a/lib/std/os/windows/test.zig
+++ b/lib/std/os/windows/test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
const builtin = @import("builtin");
const windows = std.os.windows;
diff --git a/lib/std/os/windows/user32.zig b/lib/std/os/windows/user32.zig
index d996a0f394..e4511b62d3 100644
--- a/lib/std/os/windows/user32.zig
+++ b/lib/std/os/windows/user32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
const std = @import("std");
const builtin = std.builtin;
diff --git a/lib/std/os/windows/win32error.zig b/lib/std/os/windows/win32error.zig
index b66d1734cb..008316ca13 100644
--- a/lib/std/os/windows/win32error.zig
+++ b/lib/std/os/windows/win32error.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Codes are from https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d
pub const Win32Error = enum(u16) {
/// The operation completed successfully.
diff --git a/lib/std/os/windows/winmm.zig b/lib/std/os/windows/winmm.zig
index 69e4cef605..925905fb46 100644
--- a/lib/std/os/windows/winmm.zig
+++ b/lib/std/os/windows/winmm.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
usingnamespace @import("bits.zig");
pub const MMRESULT = UINT;
diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig
index 1aa6daa3e6..be55966917 100644
--- a/lib/std/os/windows/ws2_32.zig
+++ b/lib/std/os/windows/ws2_32.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../../std.zig");
usingnamespace @import("bits.zig");
diff --git a/lib/std/packed_int_array.zig b/lib/std/packed_int_array.zig
index 571aae6e4d..e6ae58ff18 100644
--- a/lib/std/packed_int_array.zig
+++ b/lib/std/packed_int_array.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = @import("builtin");
const debug = std.debug;
diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig
index 30b98941b0..698407a3a8 100644
--- a/lib/std/pdb.zig
+++ b/lib/std/pdb.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = std.builtin;
const std = @import("std.zig");
const io = std.io;
diff --git a/lib/std/priority_dequeue.zig b/lib/std/priority_dequeue.zig
index 81329a0a74..d154f5df5e 100644
--- a/lib/std/priority_dequeue.zig
+++ b/lib/std/priority_dequeue.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig
index de68442ea7..228c07cadb 100644
--- a/lib/std/priority_queue.zig
+++ b/lib/std/priority_queue.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
diff --git a/lib/std/process.zig b/lib/std/process.zig
index 47e800c124..f8b986d695 100644
--- a/lib/std/process.zig
+++ b/lib/std/process.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const os = std.os;
@@ -93,7 +88,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
var environ_buf_size: usize = undefined;
const environ_sizes_get_ret = os.wasi.environ_sizes_get(&environ_count, &environ_buf_size);
- if (environ_sizes_get_ret != os.wasi.ESUCCESS) {
+ if (environ_sizes_get_ret != .SUCCESS) {
return os.unexpectedErrno(environ_sizes_get_ret);
}
@@ -103,7 +98,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
defer allocator.free(environ_buf);
const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);
- if (environ_get_ret != os.wasi.ESUCCESS) {
+ if (environ_get_ret != .SUCCESS) {
return os.unexpectedErrno(environ_get_ret);
}
@@ -255,7 +250,7 @@ pub const ArgIteratorWasi = struct {
var buf_size: usize = undefined;
switch (w.args_sizes_get(&count, &buf_size)) {
- w.ESUCCESS => {},
+ .SUCCESS => {},
else => |err| return os.unexpectedErrno(err),
}
@@ -265,7 +260,7 @@ pub const ArgIteratorWasi = struct {
var argv_buf = try allocator.alloc(u8, buf_size);
switch (w.args_get(argv.ptr, argv_buf.ptr)) {
- w.ESUCCESS => {},
+ .SUCCESS => {},
else => |err| return os.unexpectedErrno(err),
}
diff --git a/lib/std/rand.zig b/lib/std/rand.zig
index 7d967d3715..104be7f692 100644
--- a/lib/std/rand.zig
+++ b/lib/std/rand.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! The engines provided here should be initialized from an external source.
//! For a thread-local cryptographically secure pseudo random number generator,
//! use `std.crypto.random`.
diff --git a/lib/std/rand/Gimli.zig b/lib/std/rand/Gimli.zig
index 8356c7afde..3f1488aa62 100644
--- a/lib/std/rand/Gimli.zig
+++ b/lib/std/rand/Gimli.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! CSPRNG
const std = @import("std");
diff --git a/lib/std/rand/Isaac64.zig b/lib/std/rand/Isaac64.zig
index ec505b0bf6..c3821d81aa 100644
--- a/lib/std/rand/Isaac64.zig
+++ b/lib/std/rand/Isaac64.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! ISAAC64 - http://www.burtleburtle.net/bob/rand/isaacafa.html
//!
//! Follows the general idea of the implementation from here with a few shortcuts.
diff --git a/lib/std/rand/Pcg.zig b/lib/std/rand/Pcg.zig
index 8f468b5ea3..5c9789aa7b 100644
--- a/lib/std/rand/Pcg.zig
+++ b/lib/std/rand/Pcg.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! PCG32 - http://www.pcg-random.org/
//!
//! PRNG
diff --git a/lib/std/rand/Sfc64.zig b/lib/std/rand/Sfc64.zig
index 1966a59ceb..5808376e78 100644
--- a/lib/std/rand/Sfc64.zig
+++ b/lib/std/rand/Sfc64.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Sfc64 pseudo-random number generator from Practically Random.
//! Fastest engine of pracrand and smallest footprint.
//! See http://pracrand.sourceforge.net/
diff --git a/lib/std/rand/Xoroshiro128.zig b/lib/std/rand/Xoroshiro128.zig
index 4b507cec74..43dc95afb1 100644
--- a/lib/std/rand/Xoroshiro128.zig
+++ b/lib/std/rand/Xoroshiro128.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Xoroshiro128+ - http://xoroshiro.di.unimi.it/
//!
//! PRNG
diff --git a/lib/std/rand/Xoshiro256.zig b/lib/std/rand/Xoshiro256.zig
index ead27b0fd1..c95cfc164d 100644
--- a/lib/std/rand/Xoshiro256.zig
+++ b/lib/std/rand/Xoshiro256.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Xoshiro256++ - http://xoroshiro.di.unimi.it/
//!
//! PRNG
diff --git a/lib/std/rand/ziggurat.zig b/lib/std/rand/ziggurat.zig
index c01f7c659a..2b9728fa96 100644
--- a/lib/std/rand/ziggurat.zig
+++ b/lib/std/rand/ziggurat.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Implements ZIGNOR [1].
//
// [1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to Generate Normal Random Samples*]
diff --git a/lib/std/sort.zig b/lib/std/sort.zig
index 67a4394b1e..cbc24d9abd 100644
--- a/lib/std/sort.zig
+++ b/lib/std/sort.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const assert = std.debug.assert;
const testing = std.testing;
diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig
index 2da273a673..9be6ffa671 100644
--- a/lib/std/special/build_runner.zig
+++ b/lib/std/special/build_runner.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const root = @import("@build");
const std = @import("std");
const builtin = @import("builtin");
diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig
index a6de965f90..d34e7a8a46 100644
--- a/lib/std/special/c.zig
+++ b/lib/std/special/c.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// This is Zig's multi-target implementation of libc.
// When builtin.link_libc is true, we need to export all the functions and
// provide an entire C API.
diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig
index 69e099ae57..27a2ba7a04 100644
--- a/lib/std/special/compiler_rt.zig
+++ b/lib/std/special/compiler_rt.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const is_test = builtin.is_test;
diff --git a/lib/std/special/compiler_rt/addXf3.zig b/lib/std/special/compiler_rt/addXf3.zig
index c5c7397680..59e9393ad6 100644
--- a/lib/std/special/compiler_rt/addXf3.zig
+++ b/lib/std/special/compiler_rt/addXf3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/lib/builtins/fp_add_impl.inc
diff --git a/lib/std/special/compiler_rt/addXf3_test.zig b/lib/std/special/compiler_rt/addXf3_test.zig
index 33051ed970..70eb203cee 100644
--- a/lib/std/special/compiler_rt/addXf3_test.zig
+++ b/lib/std/special/compiler_rt/addXf3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c
diff --git a/lib/std/special/compiler_rt/arm.zig b/lib/std/special/compiler_rt/arm.zig
index f100f8293c..f30d2fd6ec 100644
--- a/lib/std/special/compiler_rt/arm.zig
+++ b/lib/std/special/compiler_rt/arm.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// ARM specific builtins
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/ashldi3_test.zig b/lib/std/special/compiler_rt/ashldi3_test.zig
index 4b1eb1f9e4..b69b7a16ad 100644
--- a/lib/std/special/compiler_rt/ashldi3_test.zig
+++ b/lib/std/special/compiler_rt/ashldi3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __ashldi3 = @import("shift.zig").__ashldi3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/ashlti3_test.zig b/lib/std/special/compiler_rt/ashlti3_test.zig
index 1187120457..5ab53c3b78 100644
--- a/lib/std/special/compiler_rt/ashlti3_test.zig
+++ b/lib/std/special/compiler_rt/ashlti3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __ashlti3 = @import("shift.zig").__ashlti3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/ashrdi3_test.zig b/lib/std/special/compiler_rt/ashrdi3_test.zig
index 423c22fc12..c40b9bc054 100644
--- a/lib/std/special/compiler_rt/ashrdi3_test.zig
+++ b/lib/std/special/compiler_rt/ashrdi3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __ashrdi3 = @import("shift.zig").__ashrdi3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/ashrti3_test.zig b/lib/std/special/compiler_rt/ashrti3_test.zig
index e6d1d7ddba..d456897a27 100644
--- a/lib/std/special/compiler_rt/ashrti3_test.zig
+++ b/lib/std/special/compiler_rt/ashrti3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __ashrti3 = @import("shift.zig").__ashrti3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/atomics.zig b/lib/std/special/compiler_rt/atomics.zig
index 1b592da019..b6d0b55e33 100644
--- a/lib/std/special/compiler_rt/atomics.zig
+++ b/lib/std/special/compiler_rt/atomics.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const arch = std.Target.current.cpu.arch;
diff --git a/lib/std/special/compiler_rt/aulldiv.zig b/lib/std/special/compiler_rt/aulldiv.zig
index 196c218e24..7709e17e63 100644
--- a/lib/std/special/compiler_rt/aulldiv.zig
+++ b/lib/std/special/compiler_rt/aulldiv.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
diff --git a/lib/std/special/compiler_rt/aullrem.zig b/lib/std/special/compiler_rt/aullrem.zig
index 7d0eef5921..dbd52cd377 100644
--- a/lib/std/special/compiler_rt/aullrem.zig
+++ b/lib/std/special/compiler_rt/aullrem.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
diff --git a/lib/std/special/compiler_rt/clear_cache.zig b/lib/std/special/compiler_rt/clear_cache.zig
index 568373aabe..033441acdb 100644
--- a/lib/std/special/compiler_rt/clear_cache.zig
+++ b/lib/std/special/compiler_rt/clear_cache.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const arch = std.builtin.cpu.arch;
const os = std.builtin.os.tag;
diff --git a/lib/std/special/compiler_rt/clzsi2.zig b/lib/std/special/compiler_rt/clzsi2.zig
index d7464d5ea9..29ef4bf85e 100644
--- a/lib/std/special/compiler_rt/clzsi2.zig
+++ b/lib/std/special/compiler_rt/clzsi2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
diff --git a/lib/std/special/compiler_rt/clzsi2_test.zig b/lib/std/special/compiler_rt/clzsi2_test.zig
index b7828cf632..c8f6519b5b 100644
--- a/lib/std/special/compiler_rt/clzsi2_test.zig
+++ b/lib/std/special/compiler_rt/clzsi2_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const clzsi2 = @import("clzsi2.zig");
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/compareXf2.zig b/lib/std/special/compiler_rt/compareXf2.zig
index 8a9dcf9492..fa7cdfe2a2 100644
--- a/lib/std/special/compiler_rt/compareXf2.zig
+++ b/lib/std/special/compiler_rt/compareXf2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c
diff --git a/lib/std/special/compiler_rt/comparedf2_test.zig b/lib/std/special/compiler_rt/comparedf2_test.zig
index 018d95c0ae..a80297ffbf 100644
--- a/lib/std/special/compiler_rt/comparedf2_test.zig
+++ b/lib/std/special/compiler_rt/comparedf2_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparedf2_test.c
diff --git a/lib/std/special/compiler_rt/comparesf2_test.zig b/lib/std/special/compiler_rt/comparesf2_test.zig
index 10ffc3c063..8bc2c67956 100644
--- a/lib/std/special/compiler_rt/comparesf2_test.zig
+++ b/lib/std/special/compiler_rt/comparesf2_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparesf2_test.c
diff --git a/lib/std/special/compiler_rt/divdf3.zig b/lib/std/special/compiler_rt/divdf3.zig
index 10a548090a..b39e428d96 100644
--- a/lib/std/special/compiler_rt/divdf3.zig
+++ b/lib/std/special/compiler_rt/divdf3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c
diff --git a/lib/std/special/compiler_rt/divdf3_test.zig b/lib/std/special/compiler_rt/divdf3_test.zig
index a472b5ed08..28cb0bc4df 100644
--- a/lib/std/special/compiler_rt/divdf3_test.zig
+++ b/lib/std/special/compiler_rt/divdf3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/divdf3_test.c
diff --git a/lib/std/special/compiler_rt/divsf3.zig b/lib/std/special/compiler_rt/divsf3.zig
index 3f89f12313..b44f19506d 100644
--- a/lib/std/special/compiler_rt/divsf3.zig
+++ b/lib/std/special/compiler_rt/divsf3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c
diff --git a/lib/std/special/compiler_rt/divsf3_test.zig b/lib/std/special/compiler_rt/divsf3_test.zig
index 97f34d34a5..0c06d4c15a 100644
--- a/lib/std/special/compiler_rt/divsf3_test.zig
+++ b/lib/std/special/compiler_rt/divsf3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/divsf3_test.c
diff --git a/lib/std/special/compiler_rt/divtf3.zig b/lib/std/special/compiler_rt/divtf3.zig
index d8ef463e49..ea71c7502f 100644
--- a/lib/std/special/compiler_rt/divtf3.zig
+++ b/lib/std/special/compiler_rt/divtf3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/divtf3_test.zig b/lib/std/special/compiler_rt/divtf3_test.zig
index 3915177091..f426f827e8 100644
--- a/lib/std/special/compiler_rt/divtf3_test.zig
+++ b/lib/std/special/compiler_rt/divtf3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const math = std.math;
const testing = std.testing;
diff --git a/lib/std/special/compiler_rt/divti3.zig b/lib/std/special/compiler_rt/divti3.zig
index 03bae3f3f8..1fb7947e6f 100644
--- a/lib/std/special/compiler_rt/divti3.zig
+++ b/lib/std/special/compiler_rt/divti3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/divti3_test.zig b/lib/std/special/compiler_rt/divti3_test.zig
index c4f7fd01b6..7992e4312f 100644
--- a/lib/std/special/compiler_rt/divti3_test.zig
+++ b/lib/std/special/compiler_rt/divti3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __divti3 = @import("divti3.zig").__divti3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/emutls.zig b/lib/std/special/compiler_rt/emutls.zig
index 46d0dd98e8..5d018d84ae 100644
--- a/lib/std/special/compiler_rt/emutls.zig
+++ b/lib/std/special/compiler_rt/emutls.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2018 LLVM Compiler Infrastructure
-// Copyright (c) 2020 Sebastien Marie
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// __emutls_get_address specific builtin
//
// derived work from LLVM Compiler Infrastructure - release 8.0 (MIT)
@@ -201,7 +195,7 @@ const current_thread_storage = struct {
/// Initialize pthread_key_t.
fn init() void {
- if (std.c.pthread_key_create(¤t_thread_storage.key, current_thread_storage.deinit) != 0) {
+ if (std.c.pthread_key_create(¤t_thread_storage.key, current_thread_storage.deinit) != .SUCCESS) {
abort();
}
}
@@ -248,14 +242,14 @@ const emutls_control = extern struct {
/// Simple wrapper for global lock.
fn lock() void {
- if (std.c.pthread_mutex_lock(&emutls_control.mutex) != 0) {
+ if (std.c.pthread_mutex_lock(&emutls_control.mutex) != .SUCCESS) {
abort();
}
}
/// Simple wrapper for global unlock.
fn unlock() void {
- if (std.c.pthread_mutex_unlock(&emutls_control.mutex) != 0) {
+ if (std.c.pthread_mutex_unlock(&emutls_control.mutex) != .SUCCESS) {
abort();
}
}
diff --git a/lib/std/special/compiler_rt/extendXfYf2.zig b/lib/std/special/compiler_rt/extendXfYf2.zig
index 9a42a938b9..1c95fd68c1 100644
--- a/lib/std/special/compiler_rt/extendXfYf2.zig
+++ b/lib/std/special/compiler_rt/extendXfYf2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = @import("builtin");
const is_test = builtin.is_test;
diff --git a/lib/std/special/compiler_rt/extendXfYf2_test.zig b/lib/std/special/compiler_rt/extendXfYf2_test.zig
index 6a53dc5b44..89545576a2 100644
--- a/lib/std/special/compiler_rt/extendXfYf2_test.zig
+++ b/lib/std/special/compiler_rt/extendXfYf2_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;
const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2;
diff --git a/lib/std/special/compiler_rt/fixdfdi.zig b/lib/std/special/compiler_rt/fixdfdi.zig
index f827f22a4a..11b5009129 100644
--- a/lib/std/special/compiler_rt/fixdfdi.zig
+++ b/lib/std/special/compiler_rt/fixdfdi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixdfdi_test.zig b/lib/std/special/compiler_rt/fixdfdi_test.zig
index c8220b532d..a9182cb723 100644
--- a/lib/std/special/compiler_rt/fixdfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixdfdi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixdfsi.zig b/lib/std/special/compiler_rt/fixdfsi.zig
index 2e9fab2297..8a6d8da342 100644
--- a/lib/std/special/compiler_rt/fixdfsi.zig
+++ b/lib/std/special/compiler_rt/fixdfsi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixdfsi_test.zig b/lib/std/special/compiler_rt/fixdfsi_test.zig
index c9ebcbeddc..b3f0953160 100644
--- a/lib/std/special/compiler_rt/fixdfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixdfsi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixdfsi = @import("fixdfsi.zig").__fixdfsi;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixdfti.zig b/lib/std/special/compiler_rt/fixdfti.zig
index 88072de063..0e21f0ba19 100644
--- a/lib/std/special/compiler_rt/fixdfti.zig
+++ b/lib/std/special/compiler_rt/fixdfti.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixdfti_test.zig b/lib/std/special/compiler_rt/fixdfti_test.zig
index 76f08f985d..a66dc0eeef 100644
--- a/lib/std/special/compiler_rt/fixdfti_test.zig
+++ b/lib/std/special/compiler_rt/fixdfti_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixdfti = @import("fixdfti.zig").__fixdfti;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixint.zig b/lib/std/special/compiler_rt/fixint.zig
index 2947154d20..6ef6474105 100644
--- a/lib/std/special/compiler_rt/fixint.zig
+++ b/lib/std/special/compiler_rt/fixint.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const is_test = @import("builtin").is_test;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixint_test.zig b/lib/std/special/compiler_rt/fixint_test.zig
index 86bc32e642..e8249813d4 100644
--- a/lib/std/special/compiler_rt/fixint_test.zig
+++ b/lib/std/special/compiler_rt/fixint_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const is_test = @import("builtin").is_test;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixsfdi.zig b/lib/std/special/compiler_rt/fixsfdi.zig
index 9563af1a56..d0d958cdd6 100644
--- a/lib/std/special/compiler_rt/fixsfdi.zig
+++ b/lib/std/special/compiler_rt/fixsfdi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixsfdi_test.zig b/lib/std/special/compiler_rt/fixsfdi_test.zig
index e18a15d9a3..d184f934ed 100644
--- a/lib/std/special/compiler_rt/fixsfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixsfdi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixsfsi.zig b/lib/std/special/compiler_rt/fixsfsi.zig
index f1a32d9f77..84395d0fa6 100644
--- a/lib/std/special/compiler_rt/fixsfsi.zig
+++ b/lib/std/special/compiler_rt/fixsfsi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixsfsi_test.zig b/lib/std/special/compiler_rt/fixsfsi_test.zig
index 6bc451a697..588a76c9d4 100644
--- a/lib/std/special/compiler_rt/fixsfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixsfsi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixsfsi = @import("fixsfsi.zig").__fixsfsi;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixsfti.zig b/lib/std/special/compiler_rt/fixsfti.zig
index 75c0a2fe1d..d7ce4b3a60 100644
--- a/lib/std/special/compiler_rt/fixsfti.zig
+++ b/lib/std/special/compiler_rt/fixsfti.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixsfti_test.zig b/lib/std/special/compiler_rt/fixsfti_test.zig
index 792716d5d3..220984a37e 100644
--- a/lib/std/special/compiler_rt/fixsfti_test.zig
+++ b/lib/std/special/compiler_rt/fixsfti_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixsfti = @import("fixsfti.zig").__fixsfti;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixtfdi.zig b/lib/std/special/compiler_rt/fixtfdi.zig
index a9e37b777f..0ef3aa2259 100644
--- a/lib/std/special/compiler_rt/fixtfdi.zig
+++ b/lib/std/special/compiler_rt/fixtfdi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixtfdi_test.zig b/lib/std/special/compiler_rt/fixtfdi_test.zig
index ef72e6527c..663023a475 100644
--- a/lib/std/special/compiler_rt/fixtfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixtfdi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixtfdi = @import("fixtfdi.zig").__fixtfdi;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixtfsi.zig b/lib/std/special/compiler_rt/fixtfsi.zig
index cd92a972c4..15e89a11b0 100644
--- a/lib/std/special/compiler_rt/fixtfsi.zig
+++ b/lib/std/special/compiler_rt/fixtfsi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixtfsi_test.zig b/lib/std/special/compiler_rt/fixtfsi_test.zig
index 61a963b07d..2e2637f53b 100644
--- a/lib/std/special/compiler_rt/fixtfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixtfsi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixtfti.zig b/lib/std/special/compiler_rt/fixtfti.zig
index cfae7c249b..733fa1eed1 100644
--- a/lib/std/special/compiler_rt/fixtfti.zig
+++ b/lib/std/special/compiler_rt/fixtfti.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixint = @import("fixint.zig").fixint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixtfti_test.zig b/lib/std/special/compiler_rt/fixtfti_test.zig
index 23ec67a737..354e835f27 100644
--- a/lib/std/special/compiler_rt/fixtfti_test.zig
+++ b/lib/std/special/compiler_rt/fixtfti_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixtfti = @import("fixtfti.zig").__fixtfti;
const std = @import("std");
const math = std.math;
diff --git a/lib/std/special/compiler_rt/fixuint.zig b/lib/std/special/compiler_rt/fixuint.zig
index 518b5de4e4..c51b80fbdb 100644
--- a/lib/std/special/compiler_rt/fixuint.zig
+++ b/lib/std/special/compiler_rt/fixuint.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const is_test = @import("builtin").is_test;
const Log2Int = @import("std").math.Log2Int;
diff --git a/lib/std/special/compiler_rt/fixunsdfdi.zig b/lib/std/special/compiler_rt/fixunsdfdi.zig
index 24a88236e0..800c9b1148 100644
--- a/lib/std/special/compiler_rt/fixunsdfdi.zig
+++ b/lib/std/special/compiler_rt/fixunsdfdi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunsdfdi_test.zig b/lib/std/special/compiler_rt/fixunsdfdi_test.zig
index dcccb076d4..59591cf181 100644
--- a/lib/std/special/compiler_rt/fixunsdfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixunsdfdi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunsdfsi.zig b/lib/std/special/compiler_rt/fixunsdfsi.zig
index 416ffc59af..156c21a887 100644
--- a/lib/std/special/compiler_rt/fixunsdfsi.zig
+++ b/lib/std/special/compiler_rt/fixunsdfsi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunsdfsi_test.zig b/lib/std/special/compiler_rt/fixunsdfsi_test.zig
index 059eb208c7..b4b7ec8840 100644
--- a/lib/std/special/compiler_rt/fixunsdfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixunsdfsi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunsdfti.zig b/lib/std/special/compiler_rt/fixunsdfti.zig
index 02836a6f75..3dcec6bf89 100644
--- a/lib/std/special/compiler_rt/fixunsdfti.zig
+++ b/lib/std/special/compiler_rt/fixunsdfti.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunsdfti_test.zig b/lib/std/special/compiler_rt/fixunsdfti_test.zig
index 89098afb33..d9e1424836 100644
--- a/lib/std/special/compiler_rt/fixunsdfti_test.zig
+++ b/lib/std/special/compiler_rt/fixunsdfti_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunssfdi.zig b/lib/std/special/compiler_rt/fixunssfdi.zig
index 77077b4344..ec00a7ee35 100644
--- a/lib/std/special/compiler_rt/fixunssfdi.zig
+++ b/lib/std/special/compiler_rt/fixunssfdi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunssfdi_test.zig b/lib/std/special/compiler_rt/fixunssfdi_test.zig
index 005e005a9b..3c46511b6d 100644
--- a/lib/std/special/compiler_rt/fixunssfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixunssfdi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunssfsi.zig b/lib/std/special/compiler_rt/fixunssfsi.zig
index 9c63424629..a4e5a323f5 100644
--- a/lib/std/special/compiler_rt/fixunssfsi.zig
+++ b/lib/std/special/compiler_rt/fixunssfsi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunssfsi_test.zig b/lib/std/special/compiler_rt/fixunssfsi_test.zig
index 90cb202230..4bf90e4bff 100644
--- a/lib/std/special/compiler_rt/fixunssfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixunssfsi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunssfti.zig b/lib/std/special/compiler_rt/fixunssfti.zig
index ab5b95ec7f..dff9eb7498 100644
--- a/lib/std/special/compiler_rt/fixunssfti.zig
+++ b/lib/std/special/compiler_rt/fixunssfti.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunssfti_test.zig b/lib/std/special/compiler_rt/fixunssfti_test.zig
index 6dabae8ba8..3c1a314e91 100644
--- a/lib/std/special/compiler_rt/fixunssfti_test.zig
+++ b/lib/std/special/compiler_rt/fixunssfti_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunstfdi.zig b/lib/std/special/compiler_rt/fixunstfdi.zig
index 2053b948e0..907116c165 100644
--- a/lib/std/special/compiler_rt/fixunstfdi.zig
+++ b/lib/std/special/compiler_rt/fixunstfdi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunstfdi_test.zig b/lib/std/special/compiler_rt/fixunstfdi_test.zig
index ca7a8c8c0d..aa746799b7 100644
--- a/lib/std/special/compiler_rt/fixunstfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixunstfdi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunstfsi.zig b/lib/std/special/compiler_rt/fixunstfsi.zig
index 3c317cd7fe..c66a3f18b4 100644
--- a/lib/std/special/compiler_rt/fixunstfsi.zig
+++ b/lib/std/special/compiler_rt/fixunstfsi.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunstfsi_test.zig b/lib/std/special/compiler_rt/fixunstfsi_test.zig
index f445edb59c..206161bef5 100644
--- a/lib/std/special/compiler_rt/fixunstfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixunstfsi_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/fixunstfti.zig b/lib/std/special/compiler_rt/fixunstfti.zig
index b089fedd3f..1867c69234 100644
--- a/lib/std/special/compiler_rt/fixunstfti.zig
+++ b/lib/std/special/compiler_rt/fixunstfti.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/fixunstfti_test.zig b/lib/std/special/compiler_rt/fixunstfti_test.zig
index 94ec32302a..e35e2a65be 100644
--- a/lib/std/special/compiler_rt/fixunstfti_test.zig
+++ b/lib/std/special/compiler_rt/fixunstfti_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatXisf.zig b/lib/std/special/compiler_rt/floatXisf.zig
index 4ce97c98f6..b02ff5f622 100644
--- a/lib/std/special/compiler_rt/floatXisf.zig
+++ b/lib/std/special/compiler_rt/floatXisf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
diff --git a/lib/std/special/compiler_rt/floatdidf.zig b/lib/std/special/compiler_rt/floatdidf.zig
index 2e07c91dd5..afe9e906fd 100644
--- a/lib/std/special/compiler_rt/floatdidf.zig
+++ b/lib/std/special/compiler_rt/floatdidf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatdidf_test.zig b/lib/std/special/compiler_rt/floatdidf_test.zig
index d20e6b39aa..6b01ac5f3f 100644
--- a/lib/std/special/compiler_rt/floatdidf_test.zig
+++ b/lib/std/special/compiler_rt/floatdidf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatdidf = @import("floatdidf.zig").__floatdidf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatdisf_test.zig b/lib/std/special/compiler_rt/floatdisf_test.zig
index a90326e943..010c4faddd 100644
--- a/lib/std/special/compiler_rt/floatdisf_test.zig
+++ b/lib/std/special/compiler_rt/floatdisf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatdisf = @import("floatXisf.zig").__floatdisf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatditf.zig b/lib/std/special/compiler_rt/floatditf.zig
index a06f66e71e..581a0e0532 100644
--- a/lib/std/special/compiler_rt/floatditf.zig
+++ b/lib/std/special/compiler_rt/floatditf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatditf_test.zig b/lib/std/special/compiler_rt/floatditf_test.zig
index bec8384dce..cf8a81c68c 100644
--- a/lib/std/special/compiler_rt/floatditf_test.zig
+++ b/lib/std/special/compiler_rt/floatditf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatditf = @import("floatditf.zig").__floatditf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatsiXf.zig b/lib/std/special/compiler_rt/floatsiXf.zig
index 91e52ac50a..23d5cb1e3c 100644
--- a/lib/std/special/compiler_rt/floatsiXf.zig
+++ b/lib/std/special/compiler_rt/floatsiXf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
diff --git a/lib/std/special/compiler_rt/floattidf.zig b/lib/std/special/compiler_rt/floattidf.zig
index 2fa5fee400..6b5013287b 100644
--- a/lib/std/special/compiler_rt/floattidf.zig
+++ b/lib/std/special/compiler_rt/floattidf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floattidf_test.zig b/lib/std/special/compiler_rt/floattidf_test.zig
index 826b73f8a1..62b131744f 100644
--- a/lib/std/special/compiler_rt/floattidf_test.zig
+++ b/lib/std/special/compiler_rt/floattidf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floattidf = @import("floattidf.zig").__floattidf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floattisf_test.zig b/lib/std/special/compiler_rt/floattisf_test.zig
index 28df0b54ea..30b36c3f9f 100644
--- a/lib/std/special/compiler_rt/floattisf_test.zig
+++ b/lib/std/special/compiler_rt/floattisf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floattisf = @import("floatXisf.zig").__floattisf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floattitf.zig b/lib/std/special/compiler_rt/floattitf.zig
index a577b6dc10..90bc241306 100644
--- a/lib/std/special/compiler_rt/floattitf.zig
+++ b/lib/std/special/compiler_rt/floattitf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floattitf_test.zig b/lib/std/special/compiler_rt/floattitf_test.zig
index cf0aa138a9..76dfc8fbfc 100644
--- a/lib/std/special/compiler_rt/floattitf_test.zig
+++ b/lib/std/special/compiler_rt/floattitf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floattitf = @import("floattitf.zig").__floattitf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatundidf.zig b/lib/std/special/compiler_rt/floatundidf.zig
index e079dabced..1efe55da40 100644
--- a/lib/std/special/compiler_rt/floatundidf.zig
+++ b/lib/std/special/compiler_rt/floatundidf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatundidf_test.zig b/lib/std/special/compiler_rt/floatundidf_test.zig
index 3094396326..71bfdd3087 100644
--- a/lib/std/special/compiler_rt/floatundidf_test.zig
+++ b/lib/std/special/compiler_rt/floatundidf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatundidf = @import("floatundidf.zig").__floatundidf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatundisf.zig b/lib/std/special/compiler_rt/floatundisf.zig
index 2367416847..aca30ee309 100644
--- a/lib/std/special/compiler_rt/floatundisf.zig
+++ b/lib/std/special/compiler_rt/floatundisf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
diff --git a/lib/std/special/compiler_rt/floatunditf.zig b/lib/std/special/compiler_rt/floatunditf.zig
index 59c433b372..dda5dd6ea5 100644
--- a/lib/std/special/compiler_rt/floatunditf.zig
+++ b/lib/std/special/compiler_rt/floatunditf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatunditf_test.zig b/lib/std/special/compiler_rt/floatunditf_test.zig
index 20dca4df4e..ae6834c082 100644
--- a/lib/std/special/compiler_rt/floatunditf_test.zig
+++ b/lib/std/special/compiler_rt/floatunditf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatunditf = @import("floatunditf.zig").__floatunditf;
fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
diff --git a/lib/std/special/compiler_rt/floatunsidf.zig b/lib/std/special/compiler_rt/floatunsidf.zig
index e3f54e8042..555d4f5657 100644
--- a/lib/std/special/compiler_rt/floatunsidf.zig
+++ b/lib/std/special/compiler_rt/floatunsidf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
diff --git a/lib/std/special/compiler_rt/floatunsisf.zig b/lib/std/special/compiler_rt/floatunsisf.zig
index 1ff11c6388..c8a654ff7a 100644
--- a/lib/std/special/compiler_rt/floatunsisf.zig
+++ b/lib/std/special/compiler_rt/floatunsisf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
diff --git a/lib/std/special/compiler_rt/floatunsitf.zig b/lib/std/special/compiler_rt/floatunsitf.zig
index 1220e31b89..a430471f3a 100644
--- a/lib/std/special/compiler_rt/floatunsitf.zig
+++ b/lib/std/special/compiler_rt/floatunsitf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatunsitf_test.zig b/lib/std/special/compiler_rt/floatunsitf_test.zig
index a6a446dd4f..7ae7c43281 100644
--- a/lib/std/special/compiler_rt/floatunsitf_test.zig
+++ b/lib/std/special/compiler_rt/floatunsitf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;
fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {
diff --git a/lib/std/special/compiler_rt/floatuntidf.zig b/lib/std/special/compiler_rt/floatuntidf.zig
index 6e1fe3b117..5b5adc0491 100644
--- a/lib/std/special/compiler_rt/floatuntidf.zig
+++ b/lib/std/special/compiler_rt/floatuntidf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatuntidf_test.zig b/lib/std/special/compiler_rt/floatuntidf_test.zig
index 735b5bcdbb..5fc6a47150 100644
--- a/lib/std/special/compiler_rt/floatuntidf_test.zig
+++ b/lib/std/special/compiler_rt/floatuntidf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatuntisf.zig b/lib/std/special/compiler_rt/floatuntisf.zig
index dd173945ba..33e6e41a84 100644
--- a/lib/std/special/compiler_rt/floatuntisf.zig
+++ b/lib/std/special/compiler_rt/floatuntisf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatuntisf_test.zig b/lib/std/special/compiler_rt/floatuntisf_test.zig
index 5657db1c82..dd06b7e3d7 100644
--- a/lib/std/special/compiler_rt/floatuntisf_test.zig
+++ b/lib/std/special/compiler_rt/floatuntisf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/floatuntitf.zig b/lib/std/special/compiler_rt/floatuntitf.zig
index 9759268b93..0b96076206 100644
--- a/lib/std/special/compiler_rt/floatuntitf.zig
+++ b/lib/std/special/compiler_rt/floatuntitf.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
diff --git a/lib/std/special/compiler_rt/floatuntitf_test.zig b/lib/std/special/compiler_rt/floatuntitf_test.zig
index 41057aa38c..5afbf348c6 100644
--- a/lib/std/special/compiler_rt/floatuntitf_test.zig
+++ b/lib/std/special/compiler_rt/floatuntitf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/int.zig b/lib/std/special/compiler_rt/int.zig
index 4533d10ab9..e4d9df7a22 100644
--- a/lib/std/special/compiler_rt/int.zig
+++ b/lib/std/special/compiler_rt/int.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Builtin functions that operate on integer types
const builtin = @import("builtin");
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/lshrdi3_test.zig b/lib/std/special/compiler_rt/lshrdi3_test.zig
index 1e3270711e..acae7a999a 100644
--- a/lib/std/special/compiler_rt/lshrdi3_test.zig
+++ b/lib/std/special/compiler_rt/lshrdi3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __lshrdi3 = @import("shift.zig").__lshrdi3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/lshrti3_test.zig b/lib/std/special/compiler_rt/lshrti3_test.zig
index 3cb134f777..a7db70024e 100644
--- a/lib/std/special/compiler_rt/lshrti3_test.zig
+++ b/lib/std/special/compiler_rt/lshrti3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __lshrti3 = @import("shift.zig").__lshrti3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/modti3.zig b/lib/std/special/compiler_rt/modti3.zig
index 298a488dc2..915b2b9566 100644
--- a/lib/std/special/compiler_rt/modti3.zig
+++ b/lib/std/special/compiler_rt/modti3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
diff --git a/lib/std/special/compiler_rt/modti3_test.zig b/lib/std/special/compiler_rt/modti3_test.zig
index e053941730..c7cee57f8b 100644
--- a/lib/std/special/compiler_rt/modti3_test.zig
+++ b/lib/std/special/compiler_rt/modti3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __modti3 = @import("modti3.zig").__modti3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/mulXf3.zig b/lib/std/special/compiler_rt/mulXf3.zig
index 20828badd3..f050cb1711 100644
--- a/lib/std/special/compiler_rt/mulXf3.zig
+++ b/lib/std/special/compiler_rt/mulXf3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/fp_mul_impl.inc
diff --git a/lib/std/special/compiler_rt/mulXf3_test.zig b/lib/std/special/compiler_rt/mulXf3_test.zig
index 2de681b067..396b69bcd0 100644
--- a/lib/std/special/compiler_rt/mulXf3_test.zig
+++ b/lib/std/special/compiler_rt/mulXf3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Ported from:
//
// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c
diff --git a/lib/std/special/compiler_rt/muldi3.zig b/lib/std/special/compiler_rt/muldi3.zig
index d367721cb2..359484da09 100644
--- a/lib/std/special/compiler_rt/muldi3.zig
+++ b/lib/std/special/compiler_rt/muldi3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const is_test = std.builtin.is_test;
const native_endian = std.Target.current.cpu.arch.endian();
diff --git a/lib/std/special/compiler_rt/muldi3_test.zig b/lib/std/special/compiler_rt/muldi3_test.zig
index 914e42bd15..6e005d67c8 100644
--- a/lib/std/special/compiler_rt/muldi3_test.zig
+++ b/lib/std/special/compiler_rt/muldi3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __muldi3 = @import("muldi3.zig").__muldi3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/mulodi4.zig b/lib/std/special/compiler_rt/mulodi4.zig
index ed90b4d382..94ed6752cc 100644
--- a/lib/std/special/compiler_rt/mulodi4.zig
+++ b/lib/std/special/compiler_rt/mulodi4.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const compiler_rt = @import("../compiler_rt.zig");
const maxInt = std.math.maxInt;
diff --git a/lib/std/special/compiler_rt/mulodi4_test.zig b/lib/std/special/compiler_rt/mulodi4_test.zig
index c865b7a0c5..b9fea2553f 100644
--- a/lib/std/special/compiler_rt/mulodi4_test.zig
+++ b/lib/std/special/compiler_rt/mulodi4_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __mulodi4 = @import("mulodi4.zig").__mulodi4;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/muloti4.zig b/lib/std/special/compiler_rt/muloti4.zig
index 30054ac751..b36a32666a 100644
--- a/lib/std/special/compiler_rt/muloti4.zig
+++ b/lib/std/special/compiler_rt/muloti4.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const compiler_rt = @import("../compiler_rt.zig");
diff --git a/lib/std/special/compiler_rt/muloti4_test.zig b/lib/std/special/compiler_rt/muloti4_test.zig
index 34c1d2daab..08450797fa 100644
--- a/lib/std/special/compiler_rt/muloti4_test.zig
+++ b/lib/std/special/compiler_rt/muloti4_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __muloti4 = @import("muloti4.zig").__muloti4;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/multi3.zig b/lib/std/special/compiler_rt/multi3.zig
index e0e992835f..4734361330 100644
--- a/lib/std/special/compiler_rt/multi3.zig
+++ b/lib/std/special/compiler_rt/multi3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const compiler_rt = @import("../compiler_rt.zig");
const std = @import("std");
const is_test = std.builtin.is_test;
diff --git a/lib/std/special/compiler_rt/multi3_test.zig b/lib/std/special/compiler_rt/multi3_test.zig
index a9ac760099..e9eafc05de 100644
--- a/lib/std/special/compiler_rt/multi3_test.zig
+++ b/lib/std/special/compiler_rt/multi3_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __multi3 = @import("multi3.zig").__multi3;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/negXf2.zig b/lib/std/special/compiler_rt/negXf2.zig
index 8c7010cccb..06528b7570 100644
--- a/lib/std/special/compiler_rt/negXf2.zig
+++ b/lib/std/special/compiler_rt/negXf2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
pub fn __negsf2(a: f32) callconv(.C) f32 {
diff --git a/lib/std/special/compiler_rt/popcountdi2.zig b/lib/std/special/compiler_rt/popcountdi2.zig
index 8495068339..b7e7220c7b 100644
--- a/lib/std/special/compiler_rt/popcountdi2.zig
+++ b/lib/std/special/compiler_rt/popcountdi2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const compiler_rt = @import("../compiler_rt.zig");
diff --git a/lib/std/special/compiler_rt/popcountdi2_test.zig b/lib/std/special/compiler_rt/popcountdi2_test.zig
index 056b9827ef..736d04dac1 100644
--- a/lib/std/special/compiler_rt/popcountdi2_test.zig
+++ b/lib/std/special/compiler_rt/popcountdi2_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __popcountdi2 = @import("popcountdi2.zig").__popcountdi2;
const testing = @import("std").testing;
diff --git a/lib/std/special/compiler_rt/shift.zig b/lib/std/special/compiler_rt/shift.zig
index e1a1a04893..28109ce9cd 100644
--- a/lib/std/special/compiler_rt/shift.zig
+++ b/lib/std/special/compiler_rt/shift.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const Log2Int = std.math.Log2Int;
const native_endian = std.Target.current.cpu.arch.endian();
diff --git a/lib/std/special/compiler_rt/sparc.zig b/lib/std/special/compiler_rt/sparc.zig
index 12c9de888a..3f2cbd86b5 100644
--- a/lib/std/special/compiler_rt/sparc.zig
+++ b/lib/std/special/compiler_rt/sparc.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// SPARC uses a different naming scheme for its support routines so we map it here to the x86 name.
diff --git a/lib/std/special/compiler_rt/stack_probe.zig b/lib/std/special/compiler_rt/stack_probe.zig
index f35afc3a6a..78f8a2f8bf 100644
--- a/lib/std/special/compiler_rt/stack_probe.zig
+++ b/lib/std/special/compiler_rt/stack_probe.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const native_arch = @import("std").Target.current.cpu.arch;
// Zig's own stack-probe routine (available only on x86 and x86_64)
diff --git a/lib/std/special/compiler_rt/truncXfYf2.zig b/lib/std/special/compiler_rt/truncXfYf2.zig
index 9f34812199..737d0e330f 100644
--- a/lib/std/special/compiler_rt/truncXfYf2.zig
+++ b/lib/std/special/compiler_rt/truncXfYf2.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
pub fn __truncsfhf2(a: f32) callconv(.C) u16 {
diff --git a/lib/std/special/compiler_rt/truncXfYf2_test.zig b/lib/std/special/compiler_rt/truncXfYf2_test.zig
index 9e581fd636..23c83afd9f 100644
--- a/lib/std/special/compiler_rt/truncXfYf2_test.zig
+++ b/lib/std/special/compiler_rt/truncXfYf2_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const __truncsfhf2 = @import("truncXfYf2.zig").__truncsfhf2;
fn test__truncsfhf2(a: u32, expected: u16) !void {
diff --git a/lib/std/special/compiler_rt/udivmod.zig b/lib/std/special/compiler_rt/udivmod.zig
index badfd97ad8..3d9618f797 100644
--- a/lib/std/special/compiler_rt/udivmod.zig
+++ b/lib/std/special/compiler_rt/udivmod.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const is_test = builtin.is_test;
const native_endian = @import("std").Target.current.cpu.arch.endian();
diff --git a/lib/std/special/compiler_rt/udivmoddi4_test.zig b/lib/std/special/compiler_rt/udivmoddi4_test.zig
index edc07bc1db..2861d33b3c 100644
--- a/lib/std/special/compiler_rt/udivmoddi4_test.zig
+++ b/lib/std/special/compiler_rt/udivmoddi4_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Disable formatting to avoid unnecessary source repository bloat.
// zig fmt: off
const __udivmoddi4 = @import("int.zig").__udivmoddi4;
diff --git a/lib/std/special/compiler_rt/udivmodti4.zig b/lib/std/special/compiler_rt/udivmodti4.zig
index 310f4dce42..cc1141dbbc 100644
--- a/lib/std/special/compiler_rt/udivmodti4.zig
+++ b/lib/std/special/compiler_rt/udivmodti4.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
const compiler_rt = @import("../compiler_rt.zig");
diff --git a/lib/std/special/compiler_rt/udivmodti4_test.zig b/lib/std/special/compiler_rt/udivmodti4_test.zig
index 5d39470f53..cb05500bee 100644
--- a/lib/std/special/compiler_rt/udivmodti4_test.zig
+++ b/lib/std/special/compiler_rt/udivmodti4_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// Disable formatting to avoid unnecessary source repository bloat.
// zig fmt: off
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
diff --git a/lib/std/special/compiler_rt/udivti3.zig b/lib/std/special/compiler_rt/udivti3.zig
index 8d95624edc..52afa0420f 100644
--- a/lib/std/special/compiler_rt/udivti3.zig
+++ b/lib/std/special/compiler_rt/udivti3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const udivmodti4 = @import("udivmodti4.zig");
const builtin = @import("builtin");
diff --git a/lib/std/special/compiler_rt/umodti3.zig b/lib/std/special/compiler_rt/umodti3.zig
index 98160039a1..29eb572892 100644
--- a/lib/std/special/compiler_rt/umodti3.zig
+++ b/lib/std/special/compiler_rt/umodti3.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const udivmodti4 = @import("udivmodti4.zig");
const builtin = @import("builtin");
const compiler_rt = @import("../compiler_rt.zig");
diff --git a/lib/std/special/ssp.zig b/lib/std/special/ssp.zig
index 6eda11b2e2..7bc5cef813 100644
--- a/lib/std/special/ssp.zig
+++ b/lib/std/special/ssp.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//
// Small Zig reimplementation of gcc's libssp.
//
diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig
index f8411c036b..4ca627d133 100644
--- a/lib/std/special/test_runner.zig
+++ b/lib/std/special/test_runner.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const io = std.io;
const builtin = @import("builtin");
diff --git a/lib/std/start.zig b/lib/std/start.zig
index b8e26869f0..a3035231df 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
// This file is included in the compilation unit when exporting an executable.
const root = @import("root");
diff --git a/lib/std/start_windows_tls.zig b/lib/std/start_windows_tls.zig
index 354a10c261..4b6db8bb48 100644
--- a/lib/std/start_windows_tls.zig
+++ b/lib/std/start_windows_tls.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = @import("builtin");
diff --git a/lib/std/std.zig b/lib/std/std.zig
index 940d1ab42e..39991ce305 100644
--- a/lib/std/std.zig
+++ b/lib/std/std.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
pub const ArrayHashMapUnmanaged = array_hash_map.ArrayHashMapUnmanaged;
pub const ArrayList = @import("array_list.zig").ArrayList;
@@ -13,6 +8,7 @@ pub const AutoArrayHashMap = array_hash_map.AutoArrayHashMap;
pub const AutoArrayHashMapUnmanaged = array_hash_map.AutoArrayHashMapUnmanaged;
pub const AutoHashMap = hash_map.AutoHashMap;
pub const AutoHashMapUnmanaged = hash_map.AutoHashMapUnmanaged;
+pub const BoundedArray = @import("bounded_array.zig").BoundedArray;
pub const BufMap = @import("buf_map.zig").BufMap;
pub const BufSet = @import("buf_set.zig").BufSet;
pub const ChildProcess = @import("child_process.zig").ChildProcess;
diff --git a/lib/std/target.zig b/lib/std/target.zig
index a5a82cbe09..333088887b 100644
--- a/lib/std/target.zig
+++ b/lib/std/target.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const mem = std.mem;
const builtin = std.builtin;
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 3323ee239b..ae3757b513 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const math = std.math;
diff --git a/lib/std/testing/failing_allocator.zig b/lib/std/testing/failing_allocator.zig
index 570050762d..d8b243d0fa 100644
--- a/lib/std/testing/failing_allocator.zig
+++ b/lib/std/testing/failing_allocator.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
diff --git a/lib/std/time.zig b/lib/std/time.zig
index 99304af46a..2306530753 100644
--- a/lib/std/time.zig
+++ b/lib/std/time.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const assert = std.debug.assert;
@@ -92,7 +87,7 @@ pub fn nanoTimestamp() i128 {
if (builtin.os.tag == .wasi and !builtin.link_libc) {
var ns: os.wasi.timestamp_t = undefined;
const err = os.wasi.clock_time_get(os.wasi.CLOCK_REALTIME, 1, &ns);
- assert(err == os.wasi.ESUCCESS);
+ assert(err == .SUCCESS);
return ns;
}
var ts: os.timespec = undefined;
diff --git a/lib/std/time/epoch.zig b/lib/std/time/epoch.zig
index 75bddc71c3..126c4fceb7 100644
--- a/lib/std/time/epoch.zig
+++ b/lib/std/time/epoch.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
//! Epoch reference times in terms of their difference from
//! UTC 1970-01-01 in seconds.
diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig
index eddc2cb7ec..b93b5e361f 100644
--- a/lib/std/unicode.zig
+++ b/lib/std/unicode.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("./std.zig");
const builtin = std.builtin;
const assert = std.debug.assert;
diff --git a/lib/std/unicode/throughput_test.zig b/lib/std/unicode/throughput_test.zig
index e49da8ceaf..2117564961 100644
--- a/lib/std/unicode/throughput_test.zig
+++ b/lib/std/unicode/throughput_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const time = std.time;
diff --git a/lib/std/valgrind.zig b/lib/std/valgrind.zig
index d149e56f49..b8ca05a4c7 100644
--- a/lib/std/valgrind.zig
+++ b/lib/std/valgrind.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("std.zig");
const math = std.math;
diff --git a/lib/std/valgrind/callgrind.zig b/lib/std/valgrind/callgrind.zig
index d29e1903fb..6c7dadf1e1 100644
--- a/lib/std/valgrind/callgrind.zig
+++ b/lib/std/valgrind/callgrind.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const valgrind = std.valgrind;
diff --git a/lib/std/valgrind/memcheck.zig b/lib/std/valgrind/memcheck.zig
index 41657c8a66..489abac2f6 100644
--- a/lib/std/valgrind/memcheck.zig
+++ b/lib/std/valgrind/memcheck.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const testing = std.testing;
const valgrind = std.valgrind;
diff --git a/lib/std/wasm.zig b/lib/std/wasm.zig
index aebbb3b163..b7923fd015 100644
--- a/lib/std/wasm.zig
+++ b/lib/std/wasm.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const testing = @import("std.zig").testing;
// TODO: Add support for multi-byte ops (e.g. table operations)
diff --git a/lib/std/x.zig b/lib/std/x.zig
index 3ac8b10f4a..be0ab25e7a 100644
--- a/lib/std/x.zig
+++ b/lib/std/x.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std.zig");
pub const os = struct {
diff --git a/lib/std/x/net/ip.zig b/lib/std/x/net/ip.zig
index 409a8ebadf..a3f5dfecf6 100644
--- a/lib/std/x/net/ip.zig
+++ b/lib/std/x/net/ip.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const fmt = std.fmt;
diff --git a/lib/std/x/net/tcp.zig b/lib/std/x/net/tcp.zig
index 25efbae673..5e02b68e9c 100644
--- a/lib/std/x/net/tcp.zig
+++ b/lib/std/x/net/tcp.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const io = std.io;
diff --git a/lib/std/x/os/net.zig b/lib/std/x/os/net.zig
index d946926932..cca9bc0ffa 100644
--- a/lib/std/x/os/net.zig
+++ b/lib/std/x/os/net.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const os = std.os;
diff --git a/lib/std/x/os/socket.zig b/lib/std/x/os/socket.zig
index 9da74d5b0e..33fc4971d7 100644
--- a/lib/std/x/os/socket.zig
+++ b/lib/std/x/os/socket.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const net = @import("net.zig");
diff --git a/lib/std/x/os/socket_posix.zig b/lib/std/x/os/socket_posix.zig
index 5deff22317..895d4c8001 100644
--- a/lib/std/x/os/socket_posix.zig
+++ b/lib/std/x/os/socket_posix.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const os = std.os;
@@ -82,32 +76,32 @@ pub fn Mixin(comptime Socket: type) type {
while (true) {
const rc = os.system.sendmsg(self.fd, &msg, @intCast(c_int, flags));
return switch (os.errno(rc)) {
- 0 => return @intCast(usize, rc),
- os.EACCES => error.AccessDenied,
- os.EAGAIN => error.WouldBlock,
- os.EALREADY => error.FastOpenAlreadyInProgress,
- os.EBADF => unreachable, // always a race condition
- os.ECONNRESET => error.ConnectionResetByPeer,
- os.EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
- os.EFAULT => unreachable, // An invalid user space address was specified for an argument.
- os.EINTR => continue,
- os.EINVAL => unreachable, // Invalid argument passed.
- os.EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
- os.EMSGSIZE => error.MessageTooBig,
- os.ENOBUFS => error.SystemResources,
- os.ENOMEM => error.SystemResources,
- os.ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- os.EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
- os.EPIPE => error.BrokenPipe,
- os.EAFNOSUPPORT => error.AddressFamilyNotSupported,
- os.ELOOP => error.SymLinkLoop,
- os.ENAMETOOLONG => error.NameTooLong,
- os.ENOENT => error.FileNotFound,
- os.ENOTDIR => error.NotDir,
- os.EHOSTUNREACH => error.NetworkUnreachable,
- os.ENETUNREACH => error.NetworkUnreachable,
- os.ENOTCONN => error.SocketNotConnected,
- os.ENETDOWN => error.NetworkSubsystemFailed,
+ .SUCCESS => return @intCast(usize, rc),
+ .ACCES => error.AccessDenied,
+ .AGAIN => error.WouldBlock,
+ .ALREADY => error.FastOpenAlreadyInProgress,
+ .BADF => unreachable, // always a race condition
+ .CONNRESET => error.ConnectionResetByPeer,
+ .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
+ .FAULT => unreachable, // An invalid user space address was specified for an argument.
+ .INTR => continue,
+ .INVAL => unreachable, // Invalid argument passed.
+ .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
+ .MSGSIZE => error.MessageTooBig,
+ .NOBUFS => error.SystemResources,
+ .NOMEM => error.SystemResources,
+ .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
+ .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
+ .PIPE => error.BrokenPipe,
+ .AFNOSUPPORT => error.AddressFamilyNotSupported,
+ .LOOP => error.SymLinkLoop,
+ .NAMETOOLONG => error.NameTooLong,
+ .NOENT => error.FileNotFound,
+ .NOTDIR => error.NotDir,
+ .HOSTUNREACH => error.NetworkUnreachable,
+ .NETUNREACH => error.NetworkUnreachable,
+ .NOTCONN => error.SocketNotConnected,
+ .NETDOWN => error.NetworkSubsystemFailed,
else => |err| os.unexpectedErrno(err),
};
}
@@ -120,17 +114,17 @@ pub fn Mixin(comptime Socket: type) type {
while (true) {
const rc = os.system.recvmsg(self.fd, msg, @intCast(c_int, flags));
return switch (os.errno(rc)) {
- 0 => @intCast(usize, rc),
- os.EBADF => unreachable, // always a race condition
- os.EFAULT => unreachable,
- os.EINVAL => unreachable,
- os.ENOTCONN => unreachable,
- os.ENOTSOCK => unreachable,
- os.EINTR => continue,
- os.EAGAIN => error.WouldBlock,
- os.ENOMEM => error.SystemResources,
- os.ECONNREFUSED => error.ConnectionRefused,
- os.ECONNRESET => error.ConnectionResetByPeer,
+ .SUCCESS => @intCast(usize, rc),
+ .BADF => unreachable, // always a race condition
+ .FAULT => unreachable,
+ .INVAL => unreachable,
+ .NOTCONN => unreachable,
+ .NOTSOCK => unreachable,
+ .INTR => continue,
+ .AGAIN => error.WouldBlock,
+ .NOMEM => error.SystemResources,
+ .CONNREFUSED => error.ConnectionRefused,
+ .CONNRESET => error.ConnectionResetByPeer,
else => |err| os.unexpectedErrno(err),
};
}
@@ -164,12 +158,12 @@ pub fn Mixin(comptime Socket: type) type {
const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);
return switch (os.errno(rc)) {
- 0 => value,
- os.EBADF => error.BadFileDescriptor,
- os.EFAULT => error.InvalidAddressSpace,
- os.EINVAL => error.InvalidSocketOption,
- os.ENOPROTOOPT => error.UnknownSocketOption,
- os.ENOTSOCK => error.NotASocket,
+ .SUCCESS => value,
+ .BADF => error.BadFileDescriptor,
+ .FAULT => error.InvalidAddressSpace,
+ .INVAL => error.InvalidSocketOption,
+ .NOPROTOOPT => error.UnknownSocketOption,
+ .NOTSOCK => error.NotASocket,
else => |err| os.unexpectedErrno(err),
};
}
@@ -181,12 +175,12 @@ pub fn Mixin(comptime Socket: type) type {
const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);
return switch (os.errno(rc)) {
- 0 => value,
- os.EBADF => error.BadFileDescriptor,
- os.EFAULT => error.InvalidAddressSpace,
- os.EINVAL => error.InvalidSocketOption,
- os.ENOPROTOOPT => error.UnknownSocketOption,
- os.ENOTSOCK => error.NotASocket,
+ .SUCCESS => value,
+ .BADF => error.BadFileDescriptor,
+ .FAULT => error.InvalidAddressSpace,
+ .INVAL => error.InvalidSocketOption,
+ .NOPROTOOPT => error.UnknownSocketOption,
+ .NOTSOCK => error.NotASocket,
else => |err| os.unexpectedErrno(err),
};
}
diff --git a/lib/std/x/os/socket_windows.zig b/lib/std/x/os/socket_windows.zig
index c08931fedf..bcc722fcfe 100644
--- a/lib/std/x/os/socket_windows.zig
+++ b/lib/std/x/os/socket_windows.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("../../std.zig");
const net = @import("net.zig");
diff --git a/lib/std/zig.zig b/lib/std/zig.zig
index 303c930b93..85ad4d2c81 100644
--- a/lib/std/zig.zig
+++ b/lib/std/zig.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std.zig");
const tokenizer = @import("zig/tokenizer.zig");
const fmt = @import("zig/fmt.zig");
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig
index 61969d9699..535dc99483 100644
--- a/lib/std/zig/ast.zig
+++ b/lib/std/zig/ast.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const testing = std.testing;
@@ -351,10 +346,6 @@ pub const Tree = struct {
.char_literal,
.integer_literal,
.float_literal,
- .false_literal,
- .true_literal,
- .null_literal,
- .undefined_literal,
.unreachable_literal,
.string_literal,
.multiline_string_literal,
@@ -716,10 +707,6 @@ pub const Tree = struct {
.char_literal,
.integer_literal,
.float_literal,
- .false_literal,
- .true_literal,
- .null_literal,
- .undefined_literal,
.unreachable_literal,
.identifier,
.deref,
@@ -2762,14 +2749,6 @@ pub const Node = struct {
/// Both lhs and rhs unused.
float_literal,
/// Both lhs and rhs unused.
- false_literal,
- /// Both lhs and rhs unused.
- true_literal,
- /// Both lhs and rhs unused.
- null_literal,
- /// Both lhs and rhs unused.
- undefined_literal,
- /// Both lhs and rhs unused.
unreachable_literal,
/// Both lhs and rhs unused.
/// Most identifiers will not have explicit AST nodes, however for expressions
diff --git a/lib/std/zig/c_builtins.zig b/lib/std/zig/c_builtins.zig
index 479f7a3b0e..6d7dc52bb8 100644
--- a/lib/std/zig/c_builtins.zig
+++ b/lib/std/zig/c_builtins.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
pub inline fn __builtin_bswap16(val: u16) u16 {
diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig
index 7b21fba93a..bb8a699f69 100644
--- a/lib/std/zig/c_translation.zig
+++ b/lib/std/zig/c_translation.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
const std = @import("std");
const testing = std.testing;
const math = std.math;
diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig
index 4a8879db57..5243d0eb9d 100644
--- a/lib/std/zig/cross_target.zig
+++ b/lib/std/zig/cross_target.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const Target = std.Target;
diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig
index 24c34a9536..5904e1816f 100644
--- a/lib/std/zig/parse.zig
+++ b/lib/std/zig/parse.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
@@ -2231,11 +2226,7 @@ const Parser = struct {
/// / INTEGER
/// / KEYWORD_comptime TypeExpr
/// / KEYWORD_error DOT IDENTIFIER
- /// / KEYWORD_false
- /// / KEYWORD_null
/// / KEYWORD_anyframe
- /// / KEYWORD_true
- /// / KEYWORD_undefined
/// / KEYWORD_unreachable
/// / STRINGLITERAL
/// / SwitchExpr
@@ -2278,38 +2269,6 @@ const Parser = struct {
.rhs = undefined,
},
}),
- .keyword_false => return p.addNode(.{
- .tag = .false_literal,
- .main_token = p.nextToken(),
- .data = .{
- .lhs = undefined,
- .rhs = undefined,
- },
- }),
- .keyword_true => return p.addNode(.{
- .tag = .true_literal,
- .main_token = p.nextToken(),
- .data = .{
- .lhs = undefined,
- .rhs = undefined,
- },
- }),
- .keyword_null => return p.addNode(.{
- .tag = .null_literal,
- .main_token = p.nextToken(),
- .data = .{
- .lhs = undefined,
- .rhs = undefined,
- },
- }),
- .keyword_undefined => return p.addNode(.{
- .tag = .undefined_literal,
- .main_token = p.nextToken(),
- .data = .{
- .lhs = undefined,
- .rhs = undefined,
- },
- }),
.keyword_unreachable => return p.addNode(.{
.tag = .unreachable_literal,
.main_token = p.nextToken(),
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index f67b0c6179..fed63ba21f 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
test "zig fmt: preserves clobbers in inline asm with stray comma" {
try testTransform(
\\fn foo() void {
diff --git a/lib/std/zig/perf_test.zig b/lib/std/zig/perf_test.zig
index 49a19a067c..0029250799 100644
--- a/lib/std/zig/perf_test.zig
+++ b/lib/std/zig/perf_test.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;
diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig
index df91da8a03..71b071d6fb 100644
--- a/lib/std/zig/render.zig
+++ b/lib/std/zig/render.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
const mem = std.mem;
@@ -192,11 +187,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
.integer_literal,
.float_literal,
.char_literal,
- .true_literal,
- .false_literal,
- .null_literal,
.unreachable_literal,
- .undefined_literal,
.anyframe_literal,
.string_literal,
=> return renderToken(ais, tree, main_tokens[node], space),
diff --git a/lib/std/zig/string_literal.zig b/lib/std/zig/string_literal.zig
index b1dc53c47f..64242038d3 100644
--- a/lib/std/zig/string_literal.zig
+++ b/lib/std/zig/string_literal.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const assert = std.debug.assert;
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index c5c62911cc..a2a92b39df 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const elf = std.elf;
const mem = std.mem;
diff --git a/lib/std/zig/system/darwin.zig b/lib/std/zig/system/darwin.zig
index 1e8d9e4b48..30496e7d26 100644
--- a/lib/std/zig/system/darwin.zig
+++ b/lib/std/zig/system/darwin.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const mem = std.mem;
const Allocator = mem.Allocator;
diff --git a/lib/std/zig/system/darwin/macos.zig b/lib/std/zig/system/darwin/macos.zig
index c8f48800c5..509faaef29 100644
--- a/lib/std/zig/system/darwin/macos.zig
+++ b/lib/std/zig/system/darwin/macos.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
diff --git a/lib/std/zig/system/windows.zig b/lib/std/zig/system/windows.zig
index d32b28f607..595dac6278 100644
--- a/lib/std/zig/system/windows.zig
+++ b/lib/std/zig/system/windows.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2020 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
pub const WindowsVersion = std.Target.Os.WindowsVersion;
diff --git a/lib/std/zig/system/x86.zig b/lib/std/zig/system/x86.zig
index 1d9a22d5d2..06a11c81ae 100644
--- a/lib/std/zig/system/x86.zig
+++ b/lib/std/zig/system/x86.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("std");
const Target = std.Target;
const CrossTarget = std.zig.CrossTarget;
diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig
index 3008aecdc3..3fdbb3ec7b 100644
--- a/lib/std/zig/tokenizer.zig
+++ b/lib/std/zig/tokenizer.zig
@@ -1,8 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
const std = @import("../std.zig");
const mem = std.mem;
@@ -37,7 +32,6 @@ pub const Token = struct {
.{ "error", .keyword_error },
.{ "export", .keyword_export },
.{ "extern", .keyword_extern },
- .{ "false", .keyword_false },
.{ "fn", .keyword_fn },
.{ "for", .keyword_for },
.{ "if", .keyword_if },
@@ -45,7 +39,6 @@ pub const Token = struct {
.{ "noalias", .keyword_noalias },
.{ "noinline", .keyword_noinline },
.{ "nosuspend", .keyword_nosuspend },
- .{ "null", .keyword_null },
.{ "opaque", .keyword_opaque },
.{ "or", .keyword_or },
.{ "orelse", .keyword_orelse },
@@ -59,9 +52,7 @@ pub const Token = struct {
.{ "switch", .keyword_switch },
.{ "test", .keyword_test },
.{ "threadlocal", .keyword_threadlocal },
- .{ "true", .keyword_true },
.{ "try", .keyword_try },
- .{ "undefined", .keyword_undefined },
.{ "union", .keyword_union },
.{ "unreachable", .keyword_unreachable },
.{ "usingnamespace", .keyword_usingnamespace },
@@ -162,7 +153,6 @@ pub const Token = struct {
keyword_error,
keyword_export,
keyword_extern,
- keyword_false,
keyword_fn,
keyword_for,
keyword_if,
@@ -170,7 +160,6 @@ pub const Token = struct {
keyword_noalias,
keyword_noinline,
keyword_nosuspend,
- keyword_null,
keyword_opaque,
keyword_or,
keyword_orelse,
@@ -184,9 +173,7 @@ pub const Token = struct {
keyword_switch,
keyword_test,
keyword_threadlocal,
- keyword_true,
keyword_try,
- keyword_undefined,
keyword_union,
keyword_unreachable,
keyword_usingnamespace,
@@ -285,7 +272,6 @@ pub const Token = struct {
.keyword_error => "error",
.keyword_export => "export",
.keyword_extern => "extern",
- .keyword_false => "false",
.keyword_fn => "fn",
.keyword_for => "for",
.keyword_if => "if",
@@ -293,7 +279,6 @@ pub const Token = struct {
.keyword_noalias => "noalias",
.keyword_noinline => "noinline",
.keyword_nosuspend => "nosuspend",
- .keyword_null => "null",
.keyword_opaque => "opaque",
.keyword_or => "or",
.keyword_orelse => "orelse",
@@ -307,9 +292,7 @@ pub const Token = struct {
.keyword_switch => "switch",
.keyword_test => "test",
.keyword_threadlocal => "threadlocal",
- .keyword_true => "true",
.keyword_try => "try",
- .keyword_undefined => "undefined",
.keyword_union => "union",
.keyword_unreachable => "unreachable",
.keyword_usingnamespace => "usingnamespace",
diff --git a/src/Air.zig b/src/Air.zig
index 391683afd5..6e4125be44 100644
--- a/src/Air.zig
+++ b/src/Air.zig
@@ -94,6 +94,12 @@ pub const Inst = struct {
/// Result type is the same as both operands.
/// Uses the `bin_op` field.
bit_or,
+ /// Shift right. `>>`
+ /// Uses the `bin_op` field.
+ shr,
+ /// Shift left. `<<`
+ /// Uses the `bin_op` field.
+ shl,
/// Bitwise XOR. `^`
/// Uses the `bin_op` field.
xor,
@@ -258,6 +264,13 @@ pub const Inst = struct {
/// Given a pointer to a struct and a field index, returns a pointer to the field.
/// Uses the `ty_pl` field, payload is `StructField`.
struct_field_ptr,
+ /// Given a pointer to a struct, returns a pointer to the field.
+ /// The field index is the number at the end of the name.
+ /// Uses `ty_op` field.
+ struct_field_ptr_index_0,
+ struct_field_ptr_index_1,
+ struct_field_ptr_index_2,
+ struct_field_ptr_index_3,
/// Given a byval struct and a field index, returns the field byval.
/// Uses the `ty_pl` field, payload is `StructField`.
struct_field_val,
@@ -280,6 +293,10 @@ pub const Inst = struct {
/// Result type is the element type of the pointer operand.
/// Uses the `bin_op` field.
ptr_elem_val,
+ /// Given a pointer value, and element index, return the element pointer at that index.
+ /// Result type is pointer to the element type of the pointer operand.
+ /// Uses the `ty_pl` field with payload `Bin`.
+ ptr_elem_ptr,
/// Given a pointer to a pointer, and element index, return the element value of the inner
/// pointer at that index.
/// Result type is the element type of the inner pointer operand.
@@ -404,6 +421,11 @@ pub const StructField = struct {
field_index: u32,
};
+pub const Bin = struct {
+ lhs: Inst.Ref,
+ rhs: Inst.Ref,
+};
+
/// Trailing:
/// 0. `Inst.Ref` for every outputs_len
/// 1. `Inst.Ref` for every inputs_len
@@ -445,6 +467,8 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
.xor,
.ptr_add,
.ptr_sub,
+ .shr,
+ .shl,
=> return air.typeOf(datas[inst].bin_op.lhs),
.cmp_lt,
@@ -474,6 +498,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
.constant,
.struct_field_ptr,
.struct_field_val,
+ .ptr_elem_ptr,
=> return air.getRefType(datas[inst].ty_pl.ty),
.not,
@@ -492,6 +517,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
.wrap_errunion_payload,
.wrap_errunion_err,
.slice_ptr,
+ .struct_field_ptr_index_0,
+ .struct_field_ptr_index_1,
+ .struct_field_ptr_index_2,
+ .struct_field_ptr_index_3,
=> return air.getRefType(datas[inst].ty_op.ty),
.loop,
@@ -519,8 +548,8 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
},
.slice_elem_val, .ptr_elem_val => {
- const slice_ty = air.typeOf(datas[inst].bin_op.lhs);
- return slice_ty.elemType();
+ const ptr_ty = air.typeOf(datas[inst].bin_op.lhs);
+ return ptr_ty.elemType();
},
.ptr_slice_elem_val, .ptr_ptr_elem_val => {
const outer_ptr_ty = air.typeOf(datas[inst].bin_op.lhs);
diff --git a/src/AstGen.zig b/src/AstGen.zig
index e3f33ec332..0a34e9a0ca 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -370,10 +370,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Ins
.bool_not,
.address_of,
.float_literal,
- .undefined_literal,
- .true_literal,
- .false_literal,
- .null_literal,
.optional_type,
.block,
.block_semicolon,
@@ -698,7 +694,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
.lhs = lhs,
.start = start,
});
- return rvalue(gz, rl, result, node);
+ switch (rl) {
+ .ref, .none_or_ref => return result,
+ else => {
+ const dereffed = try gz.addUnNode(.load, result, node);
+ return rvalue(gz, rl, dereffed, node);
+ },
+ }
},
.slice => {
const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);
@@ -710,7 +712,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
.start = start,
.end = end,
});
- return rvalue(gz, rl, result, node);
+ switch (rl) {
+ .ref, .none_or_ref => return result,
+ else => {
+ const dereffed = try gz.addUnNode(.load, result, node);
+ return rvalue(gz, rl, dereffed, node);
+ },
+ }
},
.slice_sentinel => {
const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);
@@ -724,7 +732,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
.end = end,
.sentinel = sentinel,
});
- return rvalue(gz, rl, result, node);
+ switch (rl) {
+ .ref, .none_or_ref => return result,
+ else => {
+ const dereffed = try gz.addUnNode(.load, result, node);
+ return rvalue(gz, rl, dereffed, node);
+ },
+ }
},
.deref => {
@@ -741,10 +755,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
const result = try expr(gz, scope, .ref, node_datas[node].lhs);
return rvalue(gz, rl, result, node);
},
- .undefined_literal => return rvalue(gz, rl, .undef, node),
- .true_literal => return rvalue(gz, rl, .bool_true, node),
- .false_literal => return rvalue(gz, rl, .bool_false, node),
- .null_literal => return rvalue(gz, rl, .null_value, node),
.optional_type => {
const operand = try typeExpr(gz, scope, node_datas[node].lhs);
const result = try gz.addUnNode(.optional_type, operand, node);
@@ -2367,7 +2377,7 @@ fn varDecl(
}
const ident_name = try astgen.identAsString(name_token);
- try astgen.detectLocalShadowing(scope, ident_name, name_token);
+ try astgen.detectLocalShadowing(scope, ident_name, name_token, ident_name_raw);
if (var_decl.ast.init_node == 0) {
return astgen.failNode(node, "variables must be initialized", .{});
@@ -2873,7 +2883,7 @@ fn fnDecl(
};
const fn_name_str_index = try astgen.identAsString(fn_name_token);
- try astgen.declareNewName(scope, fn_name_str_index, decl_node);
+ try astgen.declareNewName(scope, fn_name_str_index, decl_node, fn_name_token);
// We insert this at the beginning so that its instruction index marks the
// start of the top level declaration.
@@ -2934,12 +2944,13 @@ fn fnDecl(
} else false;
const param_name: u32 = if (param.name_token) |name_token| blk: {
- if (mem.eql(u8, "_", tree.tokenSlice(name_token)))
+ const name_bytes = tree.tokenSlice(name_token);
+ if (mem.eql(u8, "_", name_bytes))
break :blk 0;
const param_name = try astgen.identAsString(name_token);
if (!is_extern) {
- try astgen.detectLocalShadowing(params_scope, param_name, name_token);
+ try astgen.detectLocalShadowing(params_scope, param_name, name_token, name_bytes);
}
break :blk param_name;
} else if (!is_extern) {
@@ -3142,7 +3153,7 @@ fn globalVarDecl(
const name_token = var_decl.ast.mut_token + 1;
const name_str_index = try astgen.identAsString(name_token);
- try astgen.declareNewName(scope, name_str_index, node);
+ try astgen.declareNewName(scope, name_str_index, node, name_token);
var block_scope: GenZir = .{
.parent = scope,
@@ -5017,7 +5028,7 @@ fn ifExpr(
const token_name_str = tree.tokenSlice(token_name_index);
if (mem.eql(u8, "_", token_name_str))
break :s &then_scope.base;
- try astgen.detectLocalShadowing(&then_scope.base, ident_name, token_name_index);
+ try astgen.detectLocalShadowing(&then_scope.base, ident_name, token_name_index, token_name_str);
payload_val_scope = .{
.parent = &then_scope.base,
.gen_zir = &then_scope,
@@ -5036,11 +5047,12 @@ fn ifExpr(
.optional_payload_unsafe_ptr
else
.optional_payload_unsafe;
- if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
+ const ident_bytes = tree.tokenSlice(ident_token);
+ if (mem.eql(u8, "_", ident_bytes))
break :s &then_scope.base;
const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
const ident_name = try astgen.identAsString(ident_token);
- try astgen.detectLocalShadowing(&then_scope.base, ident_name, ident_token);
+ try astgen.detectLocalShadowing(&then_scope.base, ident_name, ident_token, ident_bytes);
payload_val_scope = .{
.parent = &then_scope.base,
.gen_zir = &then_scope,
@@ -5082,7 +5094,7 @@ fn ifExpr(
const error_token_str = tree.tokenSlice(error_token);
if (mem.eql(u8, "_", error_token_str))
break :s &else_scope.base;
- try astgen.detectLocalShadowing(&else_scope.base, ident_name, error_token);
+ try astgen.detectLocalShadowing(&else_scope.base, ident_name, error_token, error_token_str);
payload_val_scope = .{
.parent = &else_scope.base,
.gen_zir = &else_scope,
@@ -5273,11 +5285,12 @@ fn whileExpr(
.err_union_payload_unsafe;
const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
- if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
+ const ident_bytes = tree.tokenSlice(ident_token);
+ if (mem.eql(u8, "_", ident_bytes))
break :s &then_scope.base;
const payload_name_loc = payload_token + @boolToInt(payload_is_ref);
const ident_name = try astgen.identAsString(payload_name_loc);
- try astgen.detectLocalShadowing(&then_scope.base, ident_name, payload_name_loc);
+ try astgen.detectLocalShadowing(&then_scope.base, ident_name, payload_name_loc, ident_bytes);
payload_val_scope = .{
.parent = &then_scope.base,
.gen_zir = &then_scope,
@@ -5298,9 +5311,10 @@ fn whileExpr(
.optional_payload_unsafe;
const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
const ident_name = try astgen.identAsString(ident_token);
- if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
+ const ident_bytes = tree.tokenSlice(ident_token);
+ if (mem.eql(u8, "_", ident_bytes))
break :s &then_scope.base;
- try astgen.detectLocalShadowing(&then_scope.base, ident_name, ident_token);
+ try astgen.detectLocalShadowing(&then_scope.base, ident_name, ident_token, ident_bytes);
payload_val_scope = .{
.parent = &then_scope.base,
.gen_zir = &then_scope,
@@ -5356,9 +5370,10 @@ fn whileExpr(
.err_union_code;
const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);
const ident_name = try astgen.identAsString(error_token);
- if (mem.eql(u8, tree.tokenSlice(error_token), "_"))
+ const ident_bytes = tree.tokenSlice(error_token);
+ if (mem.eql(u8, ident_bytes, "_"))
break :s &else_scope.base;
- try astgen.detectLocalShadowing(&else_scope.base, ident_name, error_token);
+ try astgen.detectLocalShadowing(&else_scope.base, ident_name, error_token, ident_bytes);
payload_val_scope = .{
.parent = &else_scope.base,
.gen_zir = &else_scope,
@@ -5418,12 +5433,19 @@ fn forExpr(
if (for_full.label_token) |label_token| {
try astgen.checkLabelRedefinition(scope, label_token);
}
+
// Set up variables and constants.
const is_inline = parent_gz.force_comptime or for_full.inline_token != null;
const tree = astgen.tree;
const token_tags = tree.tokens.items(.tag);
- const array_ptr = try expr(parent_gz, scope, .none_or_ref, for_full.ast.cond_expr);
+ const payload_is_ref = if (for_full.payload_token) |payload_token|
+ token_tags[payload_token] == .asterisk
+ else
+ false;
+
+ const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
+ const array_ptr = try expr(parent_gz, scope, cond_rl, for_full.ast.cond_expr);
const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr);
const index_ptr = blk: {
@@ -5498,7 +5520,7 @@ fn forExpr(
const name_str_index = try astgen.identAsString(ident);
const tag: Zir.Inst.Tag = if (is_ptr) .elem_ptr else .elem_val;
const payload_inst = try then_scope.addBin(tag, array_ptr, index);
- try astgen.detectLocalShadowing(&then_scope.base, name_str_index, ident);
+ try astgen.detectLocalShadowing(&then_scope.base, name_str_index, ident, value_name);
payload_val_scope = .{
.parent = &then_scope.base,
.gen_zir = &then_scope,
@@ -5518,11 +5540,12 @@ fn forExpr(
ident + 2
else
break :blk payload_sub_scope;
- if (mem.eql(u8, tree.tokenSlice(index_token), "_")) {
+ const token_bytes = tree.tokenSlice(index_token);
+ if (mem.eql(u8, token_bytes, "_")) {
return astgen.failTok(index_token, "discard of index capture; omit it instead", .{});
}
const index_name = try astgen.identAsString(index_token);
- try astgen.detectLocalShadowing(payload_sub_scope, index_name, index_token);
+ try astgen.detectLocalShadowing(payload_sub_scope, index_name, index_token, token_bytes);
index_scope = .{
.parent = payload_sub_scope,
.gen_zir = &then_scope,
@@ -6294,34 +6317,36 @@ fn identifier(
}
const ident_name = try astgen.identifierTokenString(ident_token);
- if (simple_types.get(ident_name)) |zir_const_ref| {
- return rvalue(gz, rl, zir_const_ref, ident);
- }
+ if (ident_name_raw[0] != '@') {
+ if (simple_types.get(ident_name)) |zir_const_ref| {
+ return rvalue(gz, rl, zir_const_ref, ident);
+ }
- if (ident_name.len >= 2) integer: {
- const first_c = ident_name[0];
- if (first_c == 'i' or first_c == 'u') {
- const signedness: std.builtin.Signedness = switch (first_c == 'i') {
- true => .signed,
- false => .unsigned,
- };
- const bit_count = std.fmt.parseInt(u16, ident_name[1..], 10) catch |err| switch (err) {
- error.Overflow => return astgen.failNode(
- ident,
- "primitive integer type '{s}' exceeds maximum bit width of 65535",
- .{ident_name},
- ),
- error.InvalidCharacter => break :integer,
- };
- const result = try gz.add(.{
- .tag = .int_type,
- .data = .{ .int_type = .{
- .src_node = gz.nodeIndexToRelative(ident),
- .signedness = signedness,
- .bit_count = bit_count,
- } },
- });
- return rvalue(gz, rl, result, ident);
+ if (ident_name.len >= 2) integer: {
+ const first_c = ident_name[0];
+ if (first_c == 'i' or first_c == 'u') {
+ const signedness: std.builtin.Signedness = switch (first_c == 'i') {
+ true => .signed,
+ false => .unsigned,
+ };
+ const bit_count = std.fmt.parseInt(u16, ident_name[1..], 10) catch |err| switch (err) {
+ error.Overflow => return astgen.failNode(
+ ident,
+ "primitive integer type '{s}' exceeds maximum bit width of 65535",
+ .{ident_name},
+ ),
+ error.InvalidCharacter => break :integer,
+ };
+ const result = try gz.add(.{
+ .tag = .int_type,
+ .data = .{ .int_type = .{
+ .src_node = gz.nodeIndexToRelative(ident),
+ .signedness = signedness,
+ .bit_count = bit_count,
+ } },
+ });
+ return rvalue(gz, rl, result, ident);
+ }
}
}
@@ -7102,38 +7127,38 @@ fn builtinCall(
.bit_size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .bit_size_of),
.align_of => return simpleUnOpType(gz, scope, rl, node, params[0], .align_of),
- .ptr_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ptr_to_int),
- .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int),
- .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u16_type }, params[0], .int_to_error),
- .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error),
- .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u32_type }, params[0], .set_eval_branch_quota),
- .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int),
- .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int),
- .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),
- .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),
- .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .panic),
- .set_align_stack => return simpleUnOp(gz, scope, rl, node, align_rl, params[0], .set_align_stack),
- .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold),
- .set_float_mode => return simpleUnOp(gz, scope, rl, node, .{ .ty = .float_mode_type }, params[0], .set_float_mode),
- .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),
- .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),
- .sin => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sin),
- .cos => return simpleUnOp(gz, scope, rl, node, .none, params[0], .cos),
- .exp => return simpleUnOp(gz, scope, rl, node, .none, params[0], .exp),
- .exp2 => return simpleUnOp(gz, scope, rl, node, .none, params[0], .exp2),
- .log => return simpleUnOp(gz, scope, rl, node, .none, params[0], .log),
- .log2 => return simpleUnOp(gz, scope, rl, node, .none, params[0], .log2),
- .log10 => return simpleUnOp(gz, scope, rl, node, .none, params[0], .log10),
- .fabs => return simpleUnOp(gz, scope, rl, node, .none, params[0], .fabs),
- .floor => return simpleUnOp(gz, scope, rl, node, .none, params[0], .floor),
- .ceil => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ceil),
- .trunc => return simpleUnOp(gz, scope, rl, node, .none, params[0], .trunc),
- .round => return simpleUnOp(gz, scope, rl, node, .none, params[0], .round),
- .tag_name => return simpleUnOp(gz, scope, rl, node, .none, params[0], .tag_name),
- .Type => return simpleUnOp(gz, scope, rl, node, .none, params[0], .reify),
- .type_name => return simpleUnOp(gz, scope, rl, node, .none, params[0], .type_name),
- .Frame => return simpleUnOp(gz, scope, rl, node, .none, params[0], .frame_type),
- .frame_size => return simpleUnOp(gz, scope, rl, node, .none, params[0], .frame_size),
+ .ptr_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ptr_to_int),
+ .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int),
+ .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u16_type }, params[0], .int_to_error),
+ .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error),
+ .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u32_type }, params[0], .set_eval_branch_quota),
+ .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int),
+ .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int),
+ .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),
+ .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),
+ .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .panic),
+ .set_align_stack => return simpleUnOp(gz, scope, rl, node, align_rl, params[0], .set_align_stack),
+ .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold),
+ .set_float_mode => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .float_mode_type }, params[0], .set_float_mode),
+ .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),
+ .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),
+ .sin => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sin),
+ .cos => return simpleUnOp(gz, scope, rl, node, .none, params[0], .cos),
+ .exp => return simpleUnOp(gz, scope, rl, node, .none, params[0], .exp),
+ .exp2 => return simpleUnOp(gz, scope, rl, node, .none, params[0], .exp2),
+ .log => return simpleUnOp(gz, scope, rl, node, .none, params[0], .log),
+ .log2 => return simpleUnOp(gz, scope, rl, node, .none, params[0], .log2),
+ .log10 => return simpleUnOp(gz, scope, rl, node, .none, params[0], .log10),
+ .fabs => return simpleUnOp(gz, scope, rl, node, .none, params[0], .fabs),
+ .floor => return simpleUnOp(gz, scope, rl, node, .none, params[0], .floor),
+ .ceil => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ceil),
+ .trunc => return simpleUnOp(gz, scope, rl, node, .none, params[0], .trunc),
+ .round => return simpleUnOp(gz, scope, rl, node, .none, params[0], .round),
+ .tag_name => return simpleUnOp(gz, scope, rl, node, .none, params[0], .tag_name),
+ .Type => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .type_info_type }, params[0], .reify),
+ .type_name => return simpleUnOp(gz, scope, rl, node, .none, params[0], .type_name),
+ .Frame => return simpleUnOp(gz, scope, rl, node, .none, params[0], .frame_type),
+ .frame_size => return simpleUnOp(gz, scope, rl, node, .none, params[0], .frame_size),
.float_to_int => return typeCast(gz, scope, rl, node, params[0], params[1], .float_to_int),
.int_to_float => return typeCast(gz, scope, rl, node, params[0], params[1], .int_to_float),
@@ -7819,10 +7844,6 @@ fn nodeMayNeedMemoryLocation(tree: *const ast.Tree, start_node: ast.Node.Index)
.string_literal,
.multiline_string_literal,
.char_literal,
- .true_literal,
- .false_literal,
- .null_literal,
- .undefined_literal,
.unreachable_literal,
.identifier,
.error_set_decl,
@@ -8059,10 +8080,6 @@ fn nodeMayEvalToError(tree: *const ast.Tree, start_node: ast.Node.Index) enum {
.string_literal,
.multiline_string_literal,
.char_literal,
- .true_literal,
- .false_literal,
- .null_literal,
- .undefined_literal,
.unreachable_literal,
.error_set_decl,
.container_decl,
@@ -8232,10 +8249,6 @@ fn nodeImpliesRuntimeBits(tree: *const ast.Tree, start_node: ast.Node.Index) boo
.string_literal,
.multiline_string_literal,
.char_literal,
- .true_literal,
- .false_literal,
- .null_literal,
- .undefined_literal,
.unreachable_literal,
.identifier,
.error_set_decl,
@@ -10006,8 +10019,21 @@ fn declareNewName(
start_scope: *Scope,
name_index: u32,
node: ast.Node.Index,
+ name_token: ast.TokenIndex,
) !void {
const gpa = astgen.gpa;
+
+ const token_bytes = astgen.tree.tokenSlice(name_token);
+ if (token_bytes[0] != '@' and isPrimitive(token_bytes)) {
+ return astgen.failTokNotes(name_token, "name shadows primitive '{s}'", .{
+ token_bytes,
+ }, &[_]u32{
+ try astgen.errNoteTok(name_token, "consider using @\"{s}\" to disambiguate", .{
+ token_bytes,
+ }),
+ });
+ }
+
var scope = start_scope;
while (true) {
switch (scope.tag) {
@@ -10019,7 +10045,7 @@ fn declareNewName(
const ns = scope.cast(Scope.Namespace).?;
const gop = try ns.decls.getOrPut(gpa, name_index);
if (gop.found_existing) {
- const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(name_index)));
+ const name = try gpa.dupe(u8, mem.span(astgen.nullTerminatedString(name_index)));
defer gpa.free(name);
return astgen.failNodeNotes(node, "redeclaration of '{s}'", .{
name,
@@ -10035,21 +10061,45 @@ fn declareNewName(
}
}
-/// Local variables shadowing detection, including function parameters.
+fn isPrimitive(name: []const u8) bool {
+ if (simple_types.get(name) != null) return true;
+ if (name.len < 2) return false;
+ const first_c = name[0];
+ if (first_c != 'i' and first_c != 'u') return false;
+ if (std.fmt.parseInt(u16, name[1..], 10)) |_| {
+ return true;
+ } else |err| switch (err) {
+ error.Overflow => return true,
+ error.InvalidCharacter => return false,
+ }
+}
+
+/// Local variables shadowing detection, including function parameters and primitives.
fn detectLocalShadowing(
astgen: *AstGen,
scope: *Scope,
ident_name: u32,
name_token: ast.TokenIndex,
+ token_bytes: []const u8,
) !void {
const gpa = astgen.gpa;
+ if (token_bytes[0] != '@' and isPrimitive(token_bytes)) {
+ return astgen.failTokNotes(name_token, "name shadows primitive '{s}'", .{
+ token_bytes,
+ }, &[_]u32{
+ try astgen.errNoteTok(name_token, "consider using @\"{s}\" to disambiguate", .{
+ token_bytes,
+ }),
+ });
+ }
var s = scope;
while (true) switch (s.tag) {
.local_val => {
const local_val = s.cast(Scope.LocalVal).?;
if (local_val.name == ident_name) {
- const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(ident_name)));
+ const name_slice = mem.span(astgen.nullTerminatedString(ident_name));
+ const name = try gpa.dupe(u8, name_slice);
defer gpa.free(name);
return astgen.failTokNotes(name_token, "redeclaration of {s} '{s}'", .{
@tagName(local_val.id_cat), name,
@@ -10066,7 +10116,8 @@ fn detectLocalShadowing(
.local_ptr => {
const local_ptr = s.cast(Scope.LocalPtr).?;
if (local_ptr.name == ident_name) {
- const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(ident_name)));
+ const name_slice = mem.span(astgen.nullTerminatedString(ident_name));
+ const name = try gpa.dupe(u8, name_slice);
defer gpa.free(name);
return astgen.failTokNotes(name_token, "redeclaration of {s} '{s}'", .{
@tagName(local_ptr.id_cat), name,
@@ -10086,7 +10137,8 @@ fn detectLocalShadowing(
s = ns.parent;
continue;
};
- const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(ident_name)));
+ const name_slice = mem.span(astgen.nullTerminatedString(ident_name));
+ const name = try gpa.dupe(u8, name_slice);
defer gpa.free(name);
return astgen.failTokNotes(name_token, "local shadows declaration of '{s}'", .{
name,
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 63475821ab..b830fdc652 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -2557,6 +2557,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
var argv = std.ArrayList([]const u8).init(comp.gpa);
defer argv.deinit();
+ try argv.append(""); // argv[0] is program name, actual args start at [1]
try comp.addTranslateCCArgs(arena, &argv, .c, out_dep_path);
try argv.append(out_h_path);
diff --git a/src/Liveness.zig b/src/Liveness.zig
index 48603fc7c9..6a47bfe597 100644
--- a/src/Liveness.zig
+++ b/src/Liveness.zig
@@ -249,6 +249,8 @@ fn analyzeInst(
.ptr_slice_elem_val,
.ptr_elem_val,
.ptr_ptr_elem_val,
+ .shl,
+ .shr,
=> {
const o = inst_datas[inst].bin_op;
return trackOperands(a, new_set, inst, main_tomb, .{ o.lhs, o.rhs, .none });
@@ -280,6 +282,10 @@ fn analyzeInst(
.wrap_errunion_err,
.slice_ptr,
.slice_len,
+ .struct_field_ptr_index_0,
+ .struct_field_ptr_index_1,
+ .struct_field_ptr_index_2,
+ .struct_field_ptr_index_3,
=> {
const o = inst_datas[inst].ty_op;
return trackOperands(a, new_set, inst, main_tomb, .{ o.operand, .none, .none });
@@ -328,6 +334,10 @@ fn analyzeInst(
const extra = a.air.extraData(Air.StructField, inst_datas[inst].ty_pl.payload).data;
return trackOperands(a, new_set, inst, main_tomb, .{ extra.struct_operand, .none, .none });
},
+ .ptr_elem_ptr => {
+ const extra = a.air.extraData(Air.Bin, inst_datas[inst].ty_pl.payload).data;
+ return trackOperands(a, new_set, inst, main_tomb, .{ extra.lhs, extra.rhs, .none });
+ },
.br => {
const br = inst_datas[inst].br;
return trackOperands(a, new_set, inst, main_tomb, .{ br.operand, .none, .none });
diff --git a/src/Module.zig b/src/Module.zig
index 319363e9b8..4ed39c9954 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -66,6 +66,10 @@ import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{},
/// to the same function.
monomorphed_funcs: MonomorphedFuncsSet = .{},
+/// The set of all comptime function calls that have been cached so that future calls
+/// with the same parameters will get the same return value.
+memoized_calls: MemoizedCallSet = .{},
+
/// We optimize memory usage for a compilation with no compile errors by storing the
/// error messages and mapping outside of `Decl`.
/// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator.
@@ -157,6 +161,60 @@ const MonomorphedFuncsContext = struct {
}
};
+pub const MemoizedCallSet = std.HashMapUnmanaged(
+ MemoizedCall.Key,
+ MemoizedCall.Result,
+ MemoizedCall,
+ std.hash_map.default_max_load_percentage,
+);
+
+pub const MemoizedCall = struct {
+ pub const Key = struct {
+ func: *Fn,
+ args: []TypedValue,
+ };
+
+ pub const Result = struct {
+ val: Value,
+ arena: std.heap.ArenaAllocator.State,
+ };
+
+ pub fn eql(ctx: @This(), a: Key, b: Key) bool {
+ _ = ctx;
+
+ if (a.func != b.func) return false;
+
+ assert(a.args.len == b.args.len);
+ for (a.args) |a_arg, arg_i| {
+ const b_arg = b.args[arg_i];
+ if (!a_arg.eql(b_arg)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /// Must match `Sema.GenericCallAdapter.hash`.
+ pub fn hash(ctx: @This(), key: Key) u64 {
+ _ = ctx;
+
+ var hasher = std.hash.Wyhash.init(0);
+
+ // The generic function Decl is guaranteed to be the first dependency
+ // of each of its instantiations.
+ std.hash.autoHash(&hasher, @ptrToInt(key.func));
+
+ // This logic must be kept in sync with the logic in `analyzeCall` that
+ // computes the hash.
+ for (key.args) |arg| {
+ arg.hash(&hasher);
+ }
+
+ return hasher.final();
+ }
+};
+
/// A `Module` has zero or one of these depending on whether `-femit-h` is enabled.
pub const GlobalEmitH = struct {
/// Where to put the output.
@@ -554,8 +612,8 @@ pub const Decl = struct {
assert(struct_obj.owner_decl == decl);
return &struct_obj.namespace;
},
- .enum_full => {
- const enum_obj = ty.castTag(.enum_full).?.data;
+ .enum_full, .enum_nonexhaustive => {
+ const enum_obj = ty.cast(Type.Payload.EnumFull).?.data;
assert(enum_obj.owner_decl == decl);
return &enum_obj.namespace;
},
@@ -660,6 +718,7 @@ pub const Struct = struct {
/// is necessary to determine whether it has bits at runtime.
known_has_bits: bool,
+ /// The `Type` and `Value` memory is owned by the arena of the Struct's owner_decl.
pub const Field = struct {
/// Uses `noreturn` to indicate `anytype`.
/// undefined until `status` is `have_field_types` or `have_layout`.
@@ -2254,15 +2313,26 @@ pub fn deinit(mod: *Module) void {
}
mod.export_owners.deinit(gpa);
- var it = mod.global_error_set.keyIterator();
- while (it.next()) |key| {
- gpa.free(key.*);
+ {
+ var it = mod.global_error_set.keyIterator();
+ while (it.next()) |key| {
+ gpa.free(key.*);
+ }
+ mod.global_error_set.deinit(gpa);
}
- mod.global_error_set.deinit(gpa);
mod.error_name_list.deinit(gpa);
mod.test_functions.deinit(gpa);
mod.monomorphed_funcs.deinit(gpa);
+
+ {
+ var it = mod.memoized_calls.iterator();
+ while (it.next()) |entry| {
+ gpa.free(entry.key_ptr.args);
+ entry.value_ptr.arena.promote(gpa).deinit();
+ }
+ mod.memoized_calls.deinit(gpa);
+ }
}
fn freeExportList(gpa: *Allocator, export_list: []*Export) void {
@@ -3091,6 +3161,9 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
if (linksection_ref == .none) break :blk Value.initTag(.null_value);
break :blk (try sema.resolveInstConst(&block_scope, src, linksection_ref)).val;
};
+ // Note this resolves the type of the Decl, not the value; if this Decl
+ // is a struct, for example, this resolves `type` (which needs no resolution),
+ // not the struct itself.
try sema.resolveTypeLayout(&block_scope, src, decl_tv.ty);
// We need the memory for the Type to go into the arena for the Decl
@@ -3193,6 +3266,15 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
if (type_changed and mod.emit_h != null) {
try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl });
}
+ } else if (decl_tv.ty.zigTypeTag() == .Type) {
+ // In case this Decl is a struct or union, we need to resolve the fields
+ // while we still have the `Sema` in scope, so that the field type expressions
+ // can use the resolved AIR instructions that they possibly reference.
+ // We do this after the decl is populated and set to `complete` so that a `Decl`
+ // may reference itself.
+ var buffer: Value.ToTypeBuffer = undefined;
+ const ty = decl.val.toType(&buffer);
+ try sema.resolveDeclFields(&block_scope, src, ty);
}
if (decl.is_exported) {
@@ -4024,7 +4106,6 @@ pub fn createAnonymousDeclFromDeclNamed(
new_decl.ty = typed_value.ty;
new_decl.val = typed_value.val;
new_decl.has_tv = true;
- new_decl.owns_tv = true;
new_decl.analysis = .complete;
new_decl.generation = mod.generation;
@@ -4450,309 +4531,6 @@ pub const PeerTypeCandidateSrc = union(enum) {
}
};
-pub fn analyzeStructFields(mod: *Module, struct_obj: *Struct) CompileError!void {
- const tracy = trace(@src());
- defer tracy.end();
-
- const gpa = mod.gpa;
- const zir = struct_obj.owner_decl.namespace.file_scope.zir;
- const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
- assert(extended.opcode == .struct_decl);
- const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
- var extra_index: usize = extended.operand;
-
- const src: LazySrcLoc = .{ .node_offset = struct_obj.node_offset };
- extra_index += @boolToInt(small.has_src_node);
-
- const body_len = if (small.has_body_len) blk: {
- const body_len = zir.extra[extra_index];
- extra_index += 1;
- break :blk body_len;
- } else 0;
-
- const fields_len = if (small.has_fields_len) blk: {
- const fields_len = zir.extra[extra_index];
- extra_index += 1;
- break :blk fields_len;
- } else 0;
-
- const decls_len = if (small.has_decls_len) decls_len: {
- const decls_len = zir.extra[extra_index];
- extra_index += 1;
- break :decls_len decls_len;
- } else 0;
-
- // Skip over decls.
- var decls_it = zir.declIteratorInner(extra_index, decls_len);
- while (decls_it.next()) |_| {}
- extra_index = decls_it.extra_index;
-
- const body = zir.extra[extra_index..][0..body_len];
- if (fields_len == 0) {
- assert(body.len == 0);
- return;
- }
- extra_index += body.len;
-
- var decl_arena = struct_obj.owner_decl.value_arena.?.promote(gpa);
- defer struct_obj.owner_decl.value_arena.?.* = decl_arena.state;
-
- try struct_obj.fields.ensureCapacity(&decl_arena.allocator, fields_len);
-
- // We create a block for the field type instructions because they
- // may need to reference Decls from inside the struct namespace.
- // Within the field type, default value, and alignment expressions, the "owner decl"
- // should be the struct itself. Thus we need a new Sema.
- var sema: Sema = .{
- .mod = mod,
- .gpa = gpa,
- .arena = &decl_arena.allocator,
- .code = zir,
- .owner_decl = struct_obj.owner_decl,
- .namespace = &struct_obj.namespace,
- .owner_func = null,
- .func = null,
- .fn_ret_ty = Type.initTag(.void),
- };
- defer sema.deinit();
-
- var block: Scope.Block = .{
- .parent = null,
- .sema = &sema,
- .src_decl = struct_obj.owner_decl,
- .instructions = .{},
- .inlining = null,
- .is_comptime = true,
- };
- defer assert(block.instructions.items.len == 0); // should all be comptime instructions
-
- if (body.len != 0) {
- _ = try sema.analyzeBody(&block, body);
- }
-
- const bits_per_field = 4;
- const fields_per_u32 = 32 / bits_per_field;
- const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
- var bit_bag_index: usize = extra_index;
- extra_index += bit_bags_count;
- var cur_bit_bag: u32 = undefined;
- var field_i: u32 = 0;
- while (field_i < fields_len) : (field_i += 1) {
- if (field_i % fields_per_u32 == 0) {
- cur_bit_bag = zir.extra[bit_bag_index];
- bit_bag_index += 1;
- }
- const has_align = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- const has_default = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- const is_comptime = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- const unused = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
-
- _ = unused;
-
- const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);
- extra_index += 1;
- const field_type_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
- extra_index += 1;
-
- // This string needs to outlive the ZIR code.
- const field_name = try decl_arena.allocator.dupe(u8, field_name_zir);
- if (field_type_ref == .none) {
- return mod.fail(&block.base, src, "TODO: implement anytype struct field", .{});
- }
- const field_ty: Type = if (field_type_ref == .none)
- Type.initTag(.noreturn)
- else
- // TODO: if we need to report an error here, use a source location
- // that points to this type expression rather than the struct.
- // But only resolve the source location if we need to emit a compile error.
- try sema.resolveType(&block, src, field_type_ref);
-
- const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
- assert(!gop.found_existing);
- gop.value_ptr.* = .{
- .ty = field_ty,
- .abi_align = Value.initTag(.abi_align_default),
- .default_val = Value.initTag(.unreachable_value),
- .is_comptime = is_comptime,
- .offset = undefined,
- };
-
- if (has_align) {
- const align_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
- extra_index += 1;
- // TODO: if we need to report an error here, use a source location
- // that points to this alignment expression rather than the struct.
- // But only resolve the source location if we need to emit a compile error.
- gop.value_ptr.abi_align = (try sema.resolveInstConst(&block, src, align_ref)).val;
- }
- if (has_default) {
- const default_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
- extra_index += 1;
- // TODO: if we need to report an error here, use a source location
- // that points to this default value expression rather than the struct.
- // But only resolve the source location if we need to emit a compile error.
- gop.value_ptr.default_val = (try sema.resolveInstConst(&block, src, default_ref)).val;
- }
- }
-}
-
-pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) CompileError!void {
- const tracy = trace(@src());
- defer tracy.end();
-
- const gpa = mod.gpa;
- const zir = union_obj.owner_decl.namespace.file_scope.zir;
- const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;
- assert(extended.opcode == .union_decl);
- const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
- var extra_index: usize = extended.operand;
-
- const src: LazySrcLoc = .{ .node_offset = union_obj.node_offset };
- extra_index += @boolToInt(small.has_src_node);
-
- if (small.has_tag_type) {
- extra_index += 1;
- }
-
- const body_len = if (small.has_body_len) blk: {
- const body_len = zir.extra[extra_index];
- extra_index += 1;
- break :blk body_len;
- } else 0;
-
- const fields_len = if (small.has_fields_len) blk: {
- const fields_len = zir.extra[extra_index];
- extra_index += 1;
- break :blk fields_len;
- } else 0;
-
- const decls_len = if (small.has_decls_len) decls_len: {
- const decls_len = zir.extra[extra_index];
- extra_index += 1;
- break :decls_len decls_len;
- } else 0;
-
- // Skip over decls.
- var decls_it = zir.declIteratorInner(extra_index, decls_len);
- while (decls_it.next()) |_| {}
- extra_index = decls_it.extra_index;
-
- const body = zir.extra[extra_index..][0..body_len];
- if (fields_len == 0) {
- assert(body.len == 0);
- return;
- }
- extra_index += body.len;
-
- var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa);
- defer union_obj.owner_decl.value_arena.?.* = decl_arena.state;
-
- try union_obj.fields.ensureCapacity(&decl_arena.allocator, fields_len);
-
- // We create a block for the field type instructions because they
- // may need to reference Decls from inside the struct namespace.
- // Within the field type, default value, and alignment expressions, the "owner decl"
- // should be the struct itself. Thus we need a new Sema.
- var sema: Sema = .{
- .mod = mod,
- .gpa = gpa,
- .arena = &decl_arena.allocator,
- .code = zir,
- .owner_decl = union_obj.owner_decl,
- .namespace = &union_obj.namespace,
- .owner_func = null,
- .func = null,
- .fn_ret_ty = Type.initTag(.void),
- };
- defer sema.deinit();
-
- var block: Scope.Block = .{
- .parent = null,
- .sema = &sema,
- .src_decl = union_obj.owner_decl,
- .instructions = .{},
- .inlining = null,
- .is_comptime = true,
- };
- defer assert(block.instructions.items.len == 0); // should all be comptime instructions
-
- if (body.len != 0) {
- _ = try sema.analyzeBody(&block, body);
- }
-
- const bits_per_field = 4;
- const fields_per_u32 = 32 / bits_per_field;
- const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
- var bit_bag_index: usize = extra_index;
- extra_index += bit_bags_count;
- var cur_bit_bag: u32 = undefined;
- var field_i: u32 = 0;
- while (field_i < fields_len) : (field_i += 1) {
- if (field_i % fields_per_u32 == 0) {
- cur_bit_bag = zir.extra[bit_bag_index];
- bit_bag_index += 1;
- }
- const has_type = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- const has_align = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- const has_tag = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- const unused = @truncate(u1, cur_bit_bag) != 0;
- cur_bit_bag >>= 1;
- _ = unused;
-
- const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);
- extra_index += 1;
-
- const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {
- const field_type_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
- extra_index += 1;
- break :blk field_type_ref;
- } else .none;
-
- const align_ref: Zir.Inst.Ref = if (has_align) blk: {
- const align_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
- extra_index += 1;
- break :blk align_ref;
- } else .none;
-
- if (has_tag) {
- extra_index += 1;
- }
-
- // This string needs to outlive the ZIR code.
- const field_name = try decl_arena.allocator.dupe(u8, field_name_zir);
- const field_ty: Type = if (field_type_ref == .none)
- Type.initTag(.void)
- else
- // TODO: if we need to report an error here, use a source location
- // that points to this type expression rather than the union.
- // But only resolve the source location if we need to emit a compile error.
- try sema.resolveType(&block, src, field_type_ref);
-
- const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);
- assert(!gop.found_existing);
- gop.value_ptr.* = .{
- .ty = field_ty,
- .abi_align = Value.initTag(.abi_align_default),
- };
-
- if (align_ref != .none) {
- // TODO: if we need to report an error here, use a source location
- // that points to this alignment expression rather than the struct.
- // But only resolve the source location if we need to emit a compile error.
- gop.value_ptr.abi_align = (try sema.resolveInstConst(&block, src, align_ref)).val;
- }
- }
-
- // TODO resolve the union tag_type_ref
-}
-
/// Called from `performAllTheWork`, after all AstGen workers have finished,
/// and before the main semantic analysis loop begins.
pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {
diff --git a/src/Sema.zig b/src/Sema.zig
index 8b6f6d4a9f..90505c6806 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -649,6 +649,24 @@ fn resolveValue(
return sema.failWithNeededComptime(block, src);
}
+/// Value Tag `variable` will cause a compile error.
+/// Value Tag `undef` may be returned.
+fn resolveConstMaybeUndefVal(
+ sema: *Sema,
+ block: *Scope.Block,
+ src: LazySrcLoc,
+ inst: Air.Inst.Ref,
+) CompileError!Value {
+ if (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) |val| {
+ switch (val.tag()) {
+ .variable => return sema.failWithNeededComptime(block, src),
+ .generic_poison => return error.GenericPoison,
+ else => return val,
+ }
+ }
+ return sema.failWithNeededComptime(block, src);
+}
+
/// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors.
/// See `resolveValue` for an alternative.
fn resolveConstValue(
@@ -866,6 +884,7 @@ fn zirStructDecl(
.ty = Type.initTag(.type),
.val = struct_val,
}, type_name);
+ new_decl.owns_tv = true;
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
struct_obj.* = .{
.owner_decl = new_decl,
@@ -986,6 +1005,7 @@ fn zirEnumDecl(
.ty = Type.initTag(.type),
.val = enum_val,
}, type_name);
+ new_decl.owns_tv = true;
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
enum_obj.* = .{
@@ -1032,25 +1052,27 @@ fn zirEnumDecl(
// We create a block for the field type instructions because they
// may need to reference Decls from inside the enum namespace.
// Within the field type, default value, and alignment expressions, the "owner decl"
- // should be the enum itself. Thus we need a new Sema.
- var enum_sema: Sema = .{
- .mod = mod,
- .gpa = gpa,
- .arena = &new_decl_arena.allocator,
- .code = sema.code,
- .inst_map = sema.inst_map,
- .owner_decl = new_decl,
- .namespace = &enum_obj.namespace,
- .owner_func = null,
- .func = null,
- .fn_ret_ty = Type.initTag(.void),
- .branch_quota = sema.branch_quota,
- .branch_count = sema.branch_count,
- };
+ // should be the enum itself.
+
+ const prev_owner_decl = sema.owner_decl;
+ sema.owner_decl = new_decl;
+ defer sema.owner_decl = prev_owner_decl;
+
+ const prev_namespace = sema.namespace;
+ sema.namespace = &enum_obj.namespace;
+ defer sema.namespace = prev_namespace;
+
+ const prev_owner_func = sema.owner_func;
+ sema.owner_func = null;
+ defer sema.owner_func = prev_owner_func;
+
+ const prev_func = sema.func;
+ sema.func = null;
+ defer sema.func = prev_func;
var enum_block: Scope.Block = .{
.parent = null,
- .sema = &enum_sema,
+ .sema = sema,
.src_decl = new_decl,
.instructions = .{},
.inlining = null,
@@ -1059,11 +1081,8 @@ fn zirEnumDecl(
defer assert(enum_block.instructions.items.len == 0); // should all be comptime instructions
if (body.len != 0) {
- _ = try enum_sema.analyzeBody(&enum_block, body);
+ _ = try sema.analyzeBody(&enum_block, body);
}
-
- sema.branch_count = enum_sema.branch_count;
- sema.branch_quota = enum_sema.branch_quota;
}
var bit_bag_index: usize = body_end;
var cur_bit_bag: u32 = undefined;
@@ -1153,6 +1172,7 @@ fn zirUnionDecl(
.ty = Type.initTag(.type),
.val = union_val,
}, type_name);
+ new_decl.owns_tv = true;
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
union_obj.* = .{
.owner_decl = new_decl,
@@ -1224,6 +1244,7 @@ fn zirErrorSetDecl(
.ty = Type.initTag(.type),
.val = error_set_val,
}, type_name);
+ new_decl.owns_tv = true;
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
const names = try new_decl_arena.allocator.alloc([]const u8, fields.len);
for (fields) |str_index, i| {
@@ -1466,8 +1487,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
const ptr = sema.resolveInst(inst_data.operand);
const ptr_inst = Air.refToIndex(ptr).?;
assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
- const air_datas = sema.air_instructions.items(.data);
- const value_index = air_datas[ptr_inst].ty_pl.payload;
+ const value_index = sema.air_instructions.items(.data)[ptr_inst].ty_pl.payload;
const ptr_val = sema.air_values.items[value_index];
const var_is_mut = switch (sema.typeOf(ptr).tag()) {
.inferred_alloc_const => false,
@@ -1481,7 +1501,8 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
const final_elem_ty = try decl.ty.copy(sema.arena);
const final_ptr_ty = try Module.simplePtrType(sema.arena, final_elem_ty, true, .One);
- air_datas[ptr_inst].ty_pl.ty = try sema.addType(final_ptr_ty);
+ const final_ptr_ty_inst = try sema.addType(final_ptr_ty);
+ sema.air_instructions.items(.data)[ptr_inst].ty_pl.ty = final_ptr_ty_inst;
if (var_is_mut) {
sema.air_values.items[value_index] = try Value.Tag.decl_ref_mut.create(sema.arena, .{
@@ -2562,6 +2583,19 @@ fn analyzeCall(
defer merges.results.deinit(gpa);
defer merges.br_list.deinit(gpa);
+ // If it's a comptime function call, we need to memoize it as long as no external
+ // comptime memory is mutated.
+ var memoized_call_key: Module.MemoizedCall.Key = undefined;
+ var delete_memoized_call_key = false;
+ defer if (delete_memoized_call_key) gpa.free(memoized_call_key.args);
+ if (is_comptime_call) {
+ memoized_call_key = .{
+ .func = module_fn,
+ .args = try gpa.alloc(TypedValue, func_ty_info.param_types.len),
+ };
+ delete_memoized_call_key = true;
+ }
+
try sema.emitBackwardBranch(&child_block, call_src);
// This will have return instructions analyzed as break instructions to
@@ -2586,12 +2620,32 @@ fn analyzeCall(
const arg_src = call_src; // TODO: better source location
const casted_arg = try sema.coerce(&child_block, param_ty, uncasted_args[arg_i], arg_src);
try sema.inst_map.putNoClobber(gpa, inst, casted_arg);
+
+ if (is_comptime_call) {
+ const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, casted_arg);
+ memoized_call_key.args[arg_i] = .{
+ .ty = param_ty,
+ .val = arg_val,
+ };
+ }
+
arg_i += 1;
continue;
},
.param_anytype, .param_anytype_comptime => {
// No coercion needed.
- try sema.inst_map.putNoClobber(gpa, inst, uncasted_args[arg_i]);
+ const uncasted_arg = uncasted_args[arg_i];
+ try sema.inst_map.putNoClobber(gpa, inst, uncasted_arg);
+
+ if (is_comptime_call) {
+ const arg_src = call_src; // TODO: better source location
+ const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, uncasted_arg);
+ memoized_call_key.args[arg_i] = .{
+ .ty = sema.typeOf(uncasted_arg),
+ .val = arg_val,
+ };
+ }
+
arg_i += 1;
continue;
},
@@ -2623,8 +2677,61 @@ fn analyzeCall(
sema.fn_ret_ty = fn_ret_ty;
defer sema.fn_ret_ty = parent_fn_ret_ty;
- _ = try sema.analyzeBody(&child_block, fn_info.body);
- break :res try sema.analyzeBlockBody(block, call_src, &child_block, merges);
+ // This `res2` is here instead of directly breaking from `res` due to a stage1
+ // bug generating invalid LLVM IR.
+ const res2: Air.Inst.Ref = res2: {
+ if (is_comptime_call) {
+ if (mod.memoized_calls.get(memoized_call_key)) |result| {
+ const ty_inst = try sema.addType(fn_ret_ty);
+ try sema.air_values.append(gpa, result.val);
+ sema.air_instructions.set(block_inst, .{
+ .tag = .constant,
+ .data = .{ .ty_pl = .{
+ .ty = ty_inst,
+ .payload = @intCast(u32, sema.air_values.items.len - 1),
+ } },
+ });
+ break :res2 Air.indexToRef(block_inst);
+ }
+ }
+
+ _ = try sema.analyzeBody(&child_block, fn_info.body);
+ const result = try sema.analyzeBlockBody(block, call_src, &child_block, merges);
+
+ if (is_comptime_call) {
+ const result_val = try sema.resolveConstMaybeUndefVal(block, call_src, result);
+
+ // TODO: check whether any external comptime memory was mutated by the
+ // comptime function call. If so, then do not memoize the call here.
+ {
+ var arena_allocator = std.heap.ArenaAllocator.init(gpa);
+ errdefer arena_allocator.deinit();
+ const arena = &arena_allocator.allocator;
+
+ for (memoized_call_key.args) |*arg| {
+ arg.* = try arg.*.copy(arena);
+ }
+
+ try mod.memoized_calls.put(gpa, memoized_call_key, .{
+ .val = result_val,
+ .arena = arena_allocator.state,
+ });
+ delete_memoized_call_key = false;
+ }
+
+ // Much like in `Module.semaDecl`, if the result is a struct or union type,
+ // we need to resolve the field type expressions right here, right now, while
+ // the child `Sema` is still available, with the AIR instruction map intact,
+ // because the field type expressions may reference into it.
+ if (sema.typeOf(result).zigTypeTag() == .Type) {
+ const ty = try sema.analyzeAsType(&child_block, call_src, result);
+ try sema.resolveDeclFields(&child_block, call_src, ty);
+ }
+ }
+
+ break :res2 result;
+ };
+ break :res res2;
} else if (func_ty_info.is_generic) res: {
const func_val = try sema.resolveConstValue(block, func_src, func);
const module_fn = func_val.castTag(.function).?.data;
@@ -3291,31 +3398,9 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
}
if (try sema.resolveMaybeUndefVal(block, operand_src, enum_tag)) |enum_tag_val| {
- if (enum_tag_val.castTag(.enum_field_index)) |enum_field_payload| {
- const field_index = enum_field_payload.data;
- switch (enum_tag_ty.tag()) {
- .enum_full => {
- const enum_full = enum_tag_ty.castTag(.enum_full).?.data;
- if (enum_full.values.count() != 0) {
- const val = enum_full.values.keys()[field_index];
- return sema.addConstant(int_tag_ty, val);
- } else {
- // Field index and integer values are the same.
- const val = try Value.Tag.int_u64.create(arena, field_index);
- return sema.addConstant(int_tag_ty, val);
- }
- },
- .enum_simple => {
- // Field index and integer values are the same.
- const val = try Value.Tag.int_u64.create(arena, field_index);
- return sema.addConstant(int_tag_ty, val);
- },
- else => unreachable,
- }
- } else {
- // Assume it is already an integer and return it directly.
- return sema.addConstant(int_tag_ty, enum_tag_val);
- }
+ var buffer: Value.Payload.U64 = undefined;
+ const val = enum_tag_val.enumToInt(enum_tag_ty, &buffer);
+ return sema.addConstant(int_tag_ty, try val.copy(sema.arena));
}
try sema.requireRuntimeBlock(block, src);
@@ -3400,7 +3485,10 @@ fn zirOptionalPayloadPtr(
return sema.mod.fail(&block.base, src, "unable to unwrap null", .{});
}
// The same Value represents the pointer to the optional and the payload.
- return sema.addConstant(child_pointer, pointer_val);
+ return sema.addConstant(
+ child_pointer,
+ try Value.Tag.opt_payload_ptr.create(sema.arena, pointer_val),
+ );
}
}
@@ -3437,7 +3525,8 @@ fn zirOptionalPayload(
if (val.isNull()) {
return sema.mod.fail(&block.base, src, "unable to unwrap null", .{});
}
- return sema.addConstant(child_type, val);
+ const sub_val = val.castTag(.opt_payload).?.data;
+ return sema.addConstant(child_type, sub_val);
}
try sema.requireRuntimeBlock(block, src);
@@ -5294,17 +5383,56 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
const tracy = trace(@src());
defer tracy.end();
- _ = block;
- _ = inst;
- return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
+ const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
+ const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
+ const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
+ const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
+ const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
+ const lhs = sema.resolveInst(extra.lhs);
+ const rhs = sema.resolveInst(extra.rhs);
+
+ if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| {
+ if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| {
+ if (lhs_val.isUndef() or rhs_val.isUndef()) {
+ return sema.addConstUndef(sema.typeOf(lhs));
+ }
+ return sema.mod.fail(&block.base, src, "TODO implement comptime shl", .{});
+ }
+ }
+
+ try sema.requireRuntimeBlock(block, src);
+ return block.addBinOp(.shl, lhs, rhs);
}
fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const tracy = trace(@src());
defer tracy.end();
- _ = inst;
- return sema.mod.fail(&block.base, sema.src, "TODO implement zirShr", .{});
+ const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
+ const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
+ const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
+ const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
+ const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
+ const lhs = sema.resolveInst(extra.lhs);
+ const rhs = sema.resolveInst(extra.rhs);
+
+ if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| {
+ if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| {
+ const lhs_ty = sema.typeOf(lhs);
+ if (lhs_val.isUndef() or rhs_val.isUndef()) {
+ return sema.addConstUndef(lhs_ty);
+ }
+ // If rhs is 0, return lhs without doing any calculations.
+ if (rhs_val.compareWithZero(.eq)) {
+ return sema.addConstant(lhs_ty, lhs_val);
+ }
+ const val = try lhs_val.shr(rhs_val, sema.arena);
+ return sema.addConstant(lhs_ty, val);
+ }
+ }
+
+ try sema.requireRuntimeBlock(block, src);
+ return block.addBinOp(.shr, lhs, rhs);
}
fn zirBitwise(
@@ -5975,6 +6103,28 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
}),
);
},
+ .Int => {
+ const info = ty.intInfo(target);
+ const field_values = try sema.arena.alloc(Value, 2);
+ // signedness: Signedness,
+ field_values[0] = try Value.Tag.enum_field_index.create(
+ sema.arena,
+ @enumToInt(info.signedness),
+ );
+ // bits: comptime_int,
+ field_values[1] = try Value.Tag.int_u64.create(sema.arena, info.bits);
+
+ return sema.addConstant(
+ type_info_ty,
+ try Value.Tag.@"union".create(sema.arena, .{
+ .tag = try Value.Tag.enum_field_index.create(
+ sema.arena,
+ @enumToInt(@typeInfo(std.builtin.TypeInfo).Union.tag_type.?.Int),
+ ),
+ .val = try Value.Tag.@"struct".create(sema.arena, field_values.ptr),
+ }),
+ );
+ },
else => |t| return sema.mod.fail(&block.base, src, "TODO: implement zirTypeInfo for {s}", .{
@tagName(t),
}),
@@ -6001,13 +6151,37 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();
- return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});
+ const operand = sema.resolveInst(inst_data.operand);
+ const operand_ty = sema.typeOf(operand);
+ return sema.log2IntType(block, operand_ty, src);
}
fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();
- return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});
+ const operand = try sema.resolveType(block, src, inst_data.operand);
+ return sema.log2IntType(block, operand, src);
+}
+
+fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref {
+ switch (operand.zigTypeTag()) {
+ .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
+ .Int => {
+ var count: u16 = 0;
+ var s = operand.bitSize(sema.mod.getTarget()) - 1;
+ while (s != 0) : (s >>= 1) {
+ count += 1;
+ }
+ const res = try Module.makeIntType(sema.arena, .unsigned, count);
+ return sema.addType(res);
+ },
+ else => return sema.mod.fail(
+ &block.base,
+ src,
+ "bit shifting operation expected integer type, found '{}'",
+ .{operand},
+ ),
+ }
}
fn zirTypeofPeer(
@@ -6464,99 +6638,134 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
const first_field_type_data = zir_datas[first_item.field_type].pl_node;
const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
const unresolved_struct_type = try sema.resolveType(block, src, first_field_type_extra.container_type);
- const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_type);
- const struct_obj = struct_ty.castTag(.@"struct").?.data;
+ const resolved_ty = try sema.resolveTypeFields(block, src, unresolved_struct_type);
- // Maps field index to field_type index of where it was already initialized.
- // For making sure all fields are accounted for and no fields are duplicated.
- const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count());
- defer gpa.free(found_fields);
- mem.set(Zir.Inst.Index, found_fields, 0);
+ if (resolved_ty.castTag(.@"struct")) |struct_payload| {
+ const struct_obj = struct_payload.data;
- // The init values to use for the struct instance.
- const field_inits = try gpa.alloc(Air.Inst.Ref, struct_obj.fields.count());
- defer gpa.free(field_inits);
+ // Maps field index to field_type index of where it was already initialized.
+ // For making sure all fields are accounted for and no fields are duplicated.
+ const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count());
+ defer gpa.free(found_fields);
+ mem.set(Zir.Inst.Index, found_fields, 0);
- var field_i: u32 = 0;
- var extra_index = extra.end;
+ // The init values to use for the struct instance.
+ const field_inits = try gpa.alloc(Air.Inst.Ref, struct_obj.fields.count());
+ defer gpa.free(field_inits);
- while (field_i < extra.data.fields_len) : (field_i += 1) {
- const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);
- extra_index = item.end;
+ var field_i: u32 = 0;
+ var extra_index = extra.end;
+
+ while (field_i < extra.data.fields_len) : (field_i += 1) {
+ const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);
+ extra_index = item.end;
+
+ const field_type_data = zir_datas[item.data.field_type].pl_node;
+ const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_type_data.src_node };
+ const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
+ const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
+ const field_index = struct_obj.fields.getIndex(field_name) orelse
+ return sema.failWithBadFieldAccess(block, struct_obj, field_src, field_name);
+ if (found_fields[field_index] != 0) {
+ const other_field_type = found_fields[field_index];
+ const other_field_type_data = zir_datas[other_field_type].pl_node;
+ const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node };
+ const msg = msg: {
+ const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{});
+ errdefer msg.destroy(gpa);
+ try mod.errNote(&block.base, other_field_src, msg, "other field here", .{});
+ break :msg msg;
+ };
+ return mod.failWithOwnedErrorMsg(&block.base, msg);
+ }
+ found_fields[field_index] = item.data.field_type;
+ field_inits[field_index] = sema.resolveInst(item.data.init);
+ }
+
+ var root_msg: ?*Module.ErrorMsg = null;
+
+ for (found_fields) |field_type_inst, i| {
+ if (field_type_inst != 0) continue;
+
+ // Check if the field has a default init.
+ const field = struct_obj.fields.values()[i];
+ if (field.default_val.tag() == .unreachable_value) {
+ const field_name = struct_obj.fields.keys()[i];
+ const template = "missing struct field: {s}";
+ const args = .{field_name};
+ if (root_msg) |msg| {
+ try mod.errNote(&block.base, src, msg, template, args);
+ } else {
+ root_msg = try mod.errMsg(&block.base, src, template, args);
+ }
+ } else {
+ field_inits[i] = try sema.addConstant(field.ty, field.default_val);
+ }
+ }
+ if (root_msg) |msg| {
+ const fqn = try struct_obj.getFullyQualifiedName(gpa);
+ defer gpa.free(fqn);
+ try mod.errNoteNonLazy(
+ struct_obj.srcLoc(),
+ msg,
+ "struct '{s}' declared here",
+ .{fqn},
+ );
+ return mod.failWithOwnedErrorMsg(&block.base, msg);
+ }
+
+ if (is_ref) {
+ return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{});
+ }
+
+ const is_comptime = for (field_inits) |field_init| {
+ if (!(try sema.isComptimeKnown(block, src, field_init))) {
+ break false;
+ }
+ } else true;
+
+ if (is_comptime) {
+ const values = try sema.arena.alloc(Value, field_inits.len);
+ for (field_inits) |field_init, i| {
+ values[i] = (sema.resolveMaybeUndefVal(block, src, field_init) catch unreachable).?;
+ }
+ return sema.addConstant(resolved_ty, try Value.Tag.@"struct".create(sema.arena, values.ptr));
+ }
+
+ return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
+ } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| {
+ const union_obj = union_payload.data;
+
+ if (extra.data.fields_len != 1) {
+ return sema.mod.fail(&block.base, src, "union initialization expects exactly one field", .{});
+ }
+
+ const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
const field_type_data = zir_datas[item.data.field_type].pl_node;
const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_type_data.src_node };
const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
- const field_index = struct_obj.fields.getIndex(field_name) orelse
- return sema.failWithBadFieldAccess(block, struct_obj, field_src, field_name);
- if (found_fields[field_index] != 0) {
- const other_field_type = found_fields[field_index];
- const other_field_type_data = zir_datas[other_field_type].pl_node;
- const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node };
- const msg = msg: {
- const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{});
- errdefer msg.destroy(gpa);
- try mod.errNote(&block.base, other_field_src, msg, "other field here", .{});
- break :msg msg;
- };
- return mod.failWithOwnedErrorMsg(&block.base, msg);
+ const field_index = union_obj.fields.getIndex(field_name) orelse
+ return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
+
+ if (is_ref) {
+ return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true union", .{});
}
- found_fields[field_index] = item.data.field_type;
- field_inits[field_index] = sema.resolveInst(item.data.init);
- }
- var root_msg: ?*Module.ErrorMsg = null;
-
- for (found_fields) |field_type_inst, i| {
- if (field_type_inst != 0) continue;
-
- // Check if the field has a default init.
- const field = struct_obj.fields.values()[i];
- if (field.default_val.tag() == .unreachable_value) {
- const field_name = struct_obj.fields.keys()[i];
- const template = "missing struct field: {s}";
- const args = .{field_name};
- if (root_msg) |msg| {
- try mod.errNote(&block.base, src, msg, template, args);
- } else {
- root_msg = try mod.errMsg(&block.base, src, template, args);
- }
- } else {
- field_inits[i] = try sema.addConstant(field.ty, field.default_val);
+ const init_inst = sema.resolveInst(item.data.init);
+ if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| {
+ return sema.addConstant(
+ resolved_ty,
+ try Value.Tag.@"union".create(sema.arena, .{
+ .tag = try Value.Tag.int_u64.create(sema.arena, field_index),
+ .val = val,
+ }),
+ );
}
+ return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known union values", .{});
}
- if (root_msg) |msg| {
- const fqn = try struct_obj.getFullyQualifiedName(gpa);
- defer gpa.free(fqn);
- try mod.errNoteNonLazy(
- struct_obj.srcLoc(),
- msg,
- "struct '{s}' declared here",
- .{fqn},
- );
- return mod.failWithOwnedErrorMsg(&block.base, msg);
- }
-
- if (is_ref) {
- return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{});
- }
-
- const is_comptime = for (field_inits) |field_init| {
- if (!(try sema.isComptimeKnown(block, src, field_init))) {
- break false;
- }
- } else true;
-
- if (is_comptime) {
- const values = try sema.arena.alloc(Value, field_inits.len);
- for (field_inits) |field_init, i| {
- values[i] = (sema.resolveMaybeUndefVal(block, src, field_init) catch unreachable).?;
- }
- return sema.addConstant(struct_ty, try Value.Tag.@"struct".create(sema.arena, values.ptr));
- }
-
- return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
+ unreachable;
}
fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
@@ -6594,17 +6803,25 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
const src = inst_data.src();
const field_name = sema.code.nullTerminatedString(extra.name_start);
- const unresolved_struct_type = try sema.resolveType(block, src, extra.container_type);
- if (unresolved_struct_type.zigTypeTag() != .Struct) {
- return sema.mod.fail(&block.base, src, "expected struct; found '{}'", .{
- unresolved_struct_type,
- });
+ const unresolved_ty = try sema.resolveType(block, src, extra.container_type);
+ const resolved_ty = try sema.resolveTypeFields(block, src, unresolved_ty);
+ switch (resolved_ty.zigTypeTag()) {
+ .Struct => {
+ const struct_obj = resolved_ty.castTag(.@"struct").?.data;
+ const field = struct_obj.fields.get(field_name) orelse
+ return sema.failWithBadFieldAccess(block, struct_obj, src, field_name);
+ return sema.addType(field.ty);
+ },
+ .Union => {
+ const union_obj = resolved_ty.cast(Type.Payload.Union).?.data;
+ const field = union_obj.fields.get(field_name) orelse
+ return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name);
+ return sema.addType(field.ty);
+ },
+ else => return sema.mod.fail(&block.base, src, "expected struct or union; found '{}'", .{
+ resolved_ty,
+ }),
}
- const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_type);
- const struct_obj = struct_ty.castTag(.@"struct").?.data;
- const field = struct_obj.fields.get(field_name) orelse
- return sema.failWithBadFieldAccess(block, struct_obj, src, field_name);
- return sema.addType(field.ty);
}
fn zirErrorReturnTrace(
@@ -6679,7 +6896,54 @@ fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();
- return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});
+ const type_info_ty = try sema.getBuiltinType(block, src, "TypeInfo");
+ const uncasted_operand = sema.resolveInst(inst_data.operand);
+ const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
+ const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
+ const val = try sema.resolveConstValue(block, operand_src, type_info);
+ const union_val = val.cast(Value.Payload.Union).?.data;
+ const TypeInfoTag = std.meta.Tag(std.builtin.TypeInfo);
+ const tag_index = @intCast(std.meta.Tag(TypeInfoTag), union_val.tag.toUnsignedInt());
+ switch (@intToEnum(std.builtin.TypeId, tag_index)) {
+ .Type => return Air.Inst.Ref.type_type,
+ .Void => return Air.Inst.Ref.void_type,
+ .Bool => return Air.Inst.Ref.bool_type,
+ .NoReturn => return Air.Inst.Ref.noreturn_type,
+ .Int => {
+ const struct_val = union_val.val.castTag(.@"struct").?.data;
+ // TODO use reflection instead of magic numbers here
+ const signedness_val = struct_val[0];
+ const bits_val = struct_val[1];
+
+ const signedness = signedness_val.toEnum(std.builtin.Signedness);
+ const bits = @intCast(u16, bits_val.toUnsignedInt());
+ const ty = switch (signedness) {
+ .signed => try Type.Tag.int_signed.create(sema.arena, bits),
+ .unsigned => try Type.Tag.int_unsigned.create(sema.arena, bits),
+ };
+ return sema.addType(ty);
+ },
+ .Float => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Float", .{}),
+ .Pointer => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Pointer", .{}),
+ .Array => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Array", .{}),
+ .Struct => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Struct", .{}),
+ .ComptimeFloat => return Air.Inst.Ref.comptime_float_type,
+ .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
+ .Undefined => return Air.Inst.Ref.undefined_type,
+ .Null => return Air.Inst.Ref.null_type,
+ .Optional => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Optional", .{}),
+ .ErrorUnion => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorUnion", .{}),
+ .ErrorSet => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorSet", .{}),
+ .Enum => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Enum", .{}),
+ .Union => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Union", .{}),
+ .Fn => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Fn", .{}),
+ .BoundFn => @panic("TODO delete BoundFn from the language"),
+ .Opaque => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Opaque", .{}),
+ .Frame => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Frame", .{}),
+ .AnyFrame => return Air.Inst.Ref.anyframe_type,
+ .Vector => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Vector", .{}),
+ .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
+ }
}
fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@@ -7855,14 +8119,29 @@ fn structFieldPtr(
}
try sema.requireRuntimeBlock(block, src);
+ const tag: Air.Inst.Tag = switch (field_index) {
+ 0 => .struct_field_ptr_index_0,
+ 1 => .struct_field_ptr_index_1,
+ 2 => .struct_field_ptr_index_2,
+ 3 => .struct_field_ptr_index_3,
+ else => {
+ return block.addInst(.{
+ .tag = .struct_field_ptr,
+ .data = .{ .ty_pl = .{
+ .ty = try sema.addType(ptr_field_ty),
+ .payload = try sema.addExtra(Air.StructField{
+ .struct_operand = struct_ptr,
+ .field_index = @intCast(u32, field_index),
+ }),
+ } },
+ });
+ },
+ };
return block.addInst(.{
- .tag = .struct_field_ptr,
- .data = .{ .ty_pl = .{
+ .tag = tag,
+ .data = .{ .ty_op = .{
.ty = try sema.addType(ptr_field_ty),
- .payload = try sema.addExtra(Air.StructField{
- .struct_operand = struct_ptr,
- .field_index = @intCast(u32, field_index),
- }),
+ .operand = struct_ptr,
} },
});
}
@@ -8099,24 +8378,35 @@ fn elemPtrArray(
elem_index: Air.Inst.Ref,
elem_index_src: LazySrcLoc,
) CompileError!Air.Inst.Ref {
+ const array_ptr_ty = sema.typeOf(array_ptr);
+ const pointee_type = array_ptr_ty.elemType().elemType();
+ const result_ty = if (array_ptr_ty.ptrIsMutable())
+ try Type.Tag.single_mut_pointer.create(sema.arena, pointee_type)
+ else
+ try Type.Tag.single_const_pointer.create(sema.arena, pointee_type);
+
if (try sema.resolveDefinedValue(block, src, array_ptr)) |array_ptr_val| {
- if (try sema.resolveDefinedValue(block, src, elem_index)) |index_val| {
+ if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| {
// Both array pointer and index are compile-time known.
const index_u64 = index_val.toUnsignedInt();
// @intCast here because it would have been impossible to construct a value that
// required a larger index.
const elem_ptr = try array_ptr_val.elemPtr(sema.arena, @intCast(usize, index_u64));
- const pointee_type = sema.typeOf(array_ptr).elemType().elemType();
-
- return sema.addConstant(
- try Type.Tag.single_const_pointer.create(sema.arena, pointee_type),
- elem_ptr,
- );
+ return sema.addConstant(result_ty, elem_ptr);
}
}
- _ = elem_index;
- _ = elem_index_src;
- return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr for arrays", .{});
+ // TODO safety check for array bounds
+ try sema.requireRuntimeBlock(block, src);
+ return block.addInst(.{
+ .tag = .ptr_elem_ptr,
+ .data = .{ .ty_pl = .{
+ .ty = try sema.addType(result_ty),
+ .payload = try sema.addExtra(Air.Bin{
+ .lhs = array_ptr,
+ .rhs = elem_index,
+ }),
+ } },
+ });
}
fn coerce(
@@ -8528,9 +8818,12 @@ fn analyzeRef(
try sema.requireRuntimeBlock(block, src);
const ptr_type = try Module.simplePtrType(sema.arena, operand_ty, false, .One);
- const alloc = try block.addTy(.alloc, ptr_type);
+ const mut_ptr_type = try Module.simplePtrType(sema.arena, operand_ty, true, .One);
+ const alloc = try block.addTy(.alloc, mut_ptr_type);
try sema.storePtr(block, src, alloc, operand);
- return alloc;
+
+ // TODO: Replace with sema.coerce when that supports adding pointer constness.
+ return sema.bitcast(block, ptr_type, alloc, src);
}
fn analyzeLoad(
@@ -8895,7 +9188,7 @@ fn wrapOptional(
inst_src: LazySrcLoc,
) !Air.Inst.Ref {
if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
- return sema.addConstant(dest_type, val);
+ return sema.addConstant(dest_type, try Value.Tag.opt_payload.create(sema.arena, val));
}
try sema.requireRuntimeBlock(block, inst_src);
@@ -9124,22 +9417,62 @@ pub fn resolveTypeLayout(
}
}
-fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {
+/// `sema` and `block` are expected to be the same ones used for the `Decl`.
+pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void {
switch (ty.tag()) {
.@"struct" => {
const struct_obj = ty.castTag(.@"struct").?.data;
+ if (struct_obj.owner_decl.namespace != sema.owner_decl.namespace) return;
switch (struct_obj.status) {
.none => {},
.field_types_wip => {
return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});
},
+ .have_field_types, .have_layout, .layout_wip => return,
+ }
+ const prev_namespace = sema.namespace;
+ sema.namespace = &struct_obj.namespace;
+ defer sema.namespace = prev_namespace;
+
+ struct_obj.status = .field_types_wip;
+ try sema.analyzeStructFields(block, struct_obj);
+ struct_obj.status = .have_field_types;
+ },
+ .@"union", .union_tagged => {
+ const union_obj = ty.cast(Type.Payload.Union).?.data;
+ if (union_obj.owner_decl.namespace != sema.owner_decl.namespace) return;
+ switch (union_obj.status) {
+ .none => {},
+ .field_types_wip => {
+ return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty});
+ },
+ .have_field_types, .have_layout, .layout_wip => return,
+ }
+ const prev_namespace = sema.namespace;
+ sema.namespace = &union_obj.namespace;
+ defer sema.namespace = prev_namespace;
+
+ union_obj.status = .field_types_wip;
+ try sema.analyzeUnionFields(block, union_obj);
+ union_obj.status = .have_field_types;
+ },
+ else => return,
+ }
+}
+
+fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {
+ switch (ty.tag()) {
+ .@"struct" => {
+ const struct_obj = ty.castTag(.@"struct").?.data;
+ switch (struct_obj.status) {
+ .none => unreachable,
+ .field_types_wip => {
+ return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});
+ },
.have_field_types, .have_layout, .layout_wip => return ty,
}
- struct_obj.status = .field_types_wip;
- try sema.mod.analyzeStructFields(struct_obj);
- struct_obj.status = .have_field_types;
- return ty;
},
+ .type_info => return sema.resolveBuiltinTypeFields(block, src, "TypeInfo"),
.extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"),
.export_options => return sema.resolveBuiltinTypeFields(block, src, "ExportOptions"),
.atomic_ordering => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrdering"),
@@ -9152,18 +9485,12 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
.@"union", .union_tagged => {
const union_obj = ty.cast(Type.Payload.Union).?.data;
switch (union_obj.status) {
- .none => {},
+ .none => unreachable,
.field_types_wip => {
- return sema.mod.fail(&block.base, src, "union {} depends on itself", .{
- ty,
- });
+ return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty});
},
.have_field_types, .have_layout, .layout_wip => return ty,
}
- union_obj.status = .field_types_wip;
- try sema.mod.analyzeUnionFields(union_obj);
- union_obj.status = .have_field_types;
- return ty;
},
else => return ty,
}
@@ -9179,6 +9506,265 @@ fn resolveBuiltinTypeFields(
return sema.resolveTypeFields(block, src, resolved_ty);
}
+fn analyzeStructFields(
+ sema: *Sema,
+ block: *Scope.Block,
+ struct_obj: *Module.Struct,
+) CompileError!void {
+ const tracy = trace(@src());
+ defer tracy.end();
+
+ const gpa = sema.gpa;
+ const zir = sema.code;
+ const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
+ assert(extended.opcode == .struct_decl);
+ const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
+ var extra_index: usize = extended.operand;
+
+ const src: LazySrcLoc = .{ .node_offset = struct_obj.node_offset };
+ extra_index += @boolToInt(small.has_src_node);
+
+ const body_len = if (small.has_body_len) blk: {
+ const body_len = zir.extra[extra_index];
+ extra_index += 1;
+ break :blk body_len;
+ } else 0;
+
+ const fields_len = if (small.has_fields_len) blk: {
+ const fields_len = zir.extra[extra_index];
+ extra_index += 1;
+ break :blk fields_len;
+ } else 0;
+
+ const decls_len = if (small.has_decls_len) decls_len: {
+ const decls_len = zir.extra[extra_index];
+ extra_index += 1;
+ break :decls_len decls_len;
+ } else 0;
+
+ // Skip over decls.
+ var decls_it = zir.declIteratorInner(extra_index, decls_len);
+ while (decls_it.next()) |_| {}
+ extra_index = decls_it.extra_index;
+
+ const body = zir.extra[extra_index..][0..body_len];
+ if (fields_len == 0) {
+ assert(body.len == 0);
+ return;
+ }
+ extra_index += body.len;
+
+ var decl_arena = struct_obj.owner_decl.value_arena.?.promote(gpa);
+ defer struct_obj.owner_decl.value_arena.?.* = decl_arena.state;
+
+ try struct_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len);
+
+ if (body.len != 0) {
+ _ = try sema.analyzeBody(block, body);
+ }
+
+ const bits_per_field = 4;
+ const fields_per_u32 = 32 / bits_per_field;
+ const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
+ var bit_bag_index: usize = extra_index;
+ extra_index += bit_bags_count;
+ var cur_bit_bag: u32 = undefined;
+ var field_i: u32 = 0;
+ while (field_i < fields_len) : (field_i += 1) {
+ if (field_i % fields_per_u32 == 0) {
+ cur_bit_bag = zir.extra[bit_bag_index];
+ bit_bag_index += 1;
+ }
+ const has_align = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ const has_default = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ const is_comptime = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ const unused = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+
+ _ = unused;
+
+ const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);
+ extra_index += 1;
+ const field_type_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
+ extra_index += 1;
+
+ // This string needs to outlive the ZIR code.
+ const field_name = try decl_arena.allocator.dupe(u8, field_name_zir);
+ const field_ty: Type = if (field_type_ref == .none)
+ Type.initTag(.noreturn)
+ else
+ // TODO: if we need to report an error here, use a source location
+ // that points to this type expression rather than the struct.
+ // But only resolve the source location if we need to emit a compile error.
+ try sema.resolveType(block, src, field_type_ref);
+
+ const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
+ assert(!gop.found_existing);
+ gop.value_ptr.* = .{
+ .ty = try field_ty.copy(&decl_arena.allocator),
+ .abi_align = Value.initTag(.abi_align_default),
+ .default_val = Value.initTag(.unreachable_value),
+ .is_comptime = is_comptime,
+ .offset = undefined,
+ };
+
+ if (has_align) {
+ const align_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
+ extra_index += 1;
+ // TODO: if we need to report an error here, use a source location
+ // that points to this alignment expression rather than the struct.
+ // But only resolve the source location if we need to emit a compile error.
+ const abi_align_val = (try sema.resolveInstConst(block, src, align_ref)).val;
+ gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator);
+ }
+ if (has_default) {
+ const default_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
+ extra_index += 1;
+ const default_inst = sema.resolveInst(default_ref);
+ // TODO: if we need to report an error here, use a source location
+ // that points to this default value expression rather than the struct.
+ // But only resolve the source location if we need to emit a compile error.
+ const default_val = (try sema.resolveMaybeUndefVal(block, src, default_inst)) orelse
+ return sema.failWithNeededComptime(block, src);
+ gop.value_ptr.default_val = try default_val.copy(&decl_arena.allocator);
+ }
+ }
+}
+
+fn analyzeUnionFields(
+ sema: *Sema,
+ block: *Scope.Block,
+ union_obj: *Module.Union,
+) CompileError!void {
+ const tracy = trace(@src());
+ defer tracy.end();
+
+ const gpa = sema.gpa;
+ const zir = sema.code;
+ const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;
+ assert(extended.opcode == .union_decl);
+ const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
+ var extra_index: usize = extended.operand;
+
+ const src: LazySrcLoc = .{ .node_offset = union_obj.node_offset };
+ extra_index += @boolToInt(small.has_src_node);
+
+ if (small.has_tag_type) {
+ extra_index += 1;
+ }
+
+ const body_len = if (small.has_body_len) blk: {
+ const body_len = zir.extra[extra_index];
+ extra_index += 1;
+ break :blk body_len;
+ } else 0;
+
+ const fields_len = if (small.has_fields_len) blk: {
+ const fields_len = zir.extra[extra_index];
+ extra_index += 1;
+ break :blk fields_len;
+ } else 0;
+
+ const decls_len = if (small.has_decls_len) decls_len: {
+ const decls_len = zir.extra[extra_index];
+ extra_index += 1;
+ break :decls_len decls_len;
+ } else 0;
+
+ // Skip over decls.
+ var decls_it = zir.declIteratorInner(extra_index, decls_len);
+ while (decls_it.next()) |_| {}
+ extra_index = decls_it.extra_index;
+
+ const body = zir.extra[extra_index..][0..body_len];
+ if (fields_len == 0) {
+ assert(body.len == 0);
+ return;
+ }
+ extra_index += body.len;
+
+ var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa);
+ defer union_obj.owner_decl.value_arena.?.* = decl_arena.state;
+
+ try union_obj.fields.ensureCapacity(&decl_arena.allocator, fields_len);
+
+ if (body.len != 0) {
+ _ = try sema.analyzeBody(block, body);
+ }
+
+ const bits_per_field = 4;
+ const fields_per_u32 = 32 / bits_per_field;
+ const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
+ var bit_bag_index: usize = extra_index;
+ extra_index += bit_bags_count;
+ var cur_bit_bag: u32 = undefined;
+ var field_i: u32 = 0;
+ while (field_i < fields_len) : (field_i += 1) {
+ if (field_i % fields_per_u32 == 0) {
+ cur_bit_bag = zir.extra[bit_bag_index];
+ bit_bag_index += 1;
+ }
+ const has_type = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ const has_align = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ const has_tag = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ const unused = @truncate(u1, cur_bit_bag) != 0;
+ cur_bit_bag >>= 1;
+ _ = unused;
+
+ const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);
+ extra_index += 1;
+
+ const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {
+ const field_type_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
+ extra_index += 1;
+ break :blk field_type_ref;
+ } else .none;
+
+ const align_ref: Zir.Inst.Ref = if (has_align) blk: {
+ const align_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
+ extra_index += 1;
+ break :blk align_ref;
+ } else .none;
+
+ if (has_tag) {
+ extra_index += 1;
+ }
+
+ // This string needs to outlive the ZIR code.
+ const field_name = try decl_arena.allocator.dupe(u8, field_name_zir);
+ const field_ty: Type = if (field_type_ref == .none)
+ Type.initTag(.void)
+ else
+ // TODO: if we need to report an error here, use a source location
+ // that points to this type expression rather than the union.
+ // But only resolve the source location if we need to emit a compile error.
+ try sema.resolveType(block, src, field_type_ref);
+
+ const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);
+ assert(!gop.found_existing);
+ gop.value_ptr.* = .{
+ .ty = try field_ty.copy(&decl_arena.allocator),
+ .abi_align = Value.initTag(.abi_align_default),
+ };
+
+ if (align_ref != .none) {
+ // TODO: if we need to report an error here, use a source location
+ // that points to this alignment expression rather than the struct.
+ // But only resolve the source location if we need to emit a compile error.
+ const abi_align_val = (try sema.resolveInstConst(block, src, align_ref)).val;
+ gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator);
+ }
+ }
+
+ // TODO resolve the union tag_type_ref
+}
+
fn getBuiltin(
sema: *Sema,
block: *Scope.Block,
@@ -9291,6 +9877,7 @@ fn typeHasOnePossibleValue(
.call_options,
.export_options,
.extern_options,
+ .type_info,
.@"anyframe",
.anyframe_T,
.many_const_pointer,
@@ -9475,6 +10062,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
.call_options => return .call_options_type,
.export_options => return .export_options_type,
.extern_options => return .extern_options_type,
+ .type_info => return .type_info_type,
.manyptr_u8 => return .manyptr_u8_type,
.manyptr_const_u8 => return .manyptr_const_u8_type,
.fn_noreturn_no_args => return .fn_noreturn_no_args_type,
diff --git a/src/TypedValue.zig b/src/TypedValue.zig
index 48b2c04970..83242b5329 100644
--- a/src/TypedValue.zig
+++ b/src/TypedValue.zig
@@ -23,9 +23,18 @@ pub const Managed = struct {
};
/// Assumes arena allocation. Does a recursive copy.
-pub fn copy(self: TypedValue, allocator: *Allocator) error{OutOfMemory}!TypedValue {
+pub fn copy(self: TypedValue, arena: *Allocator) error{OutOfMemory}!TypedValue {
return TypedValue{
- .ty = try self.ty.copy(allocator),
- .val = try self.val.copy(allocator),
+ .ty = try self.ty.copy(arena),
+ .val = try self.val.copy(arena),
};
}
+
+pub fn eql(a: TypedValue, b: TypedValue) bool {
+ if (!a.ty.eql(b.ty)) return false;
+ return a.val.eql(b.val, a.ty);
+}
+
+pub fn hash(tv: TypedValue, hasher: *std.hash.Wyhash) void {
+ return tv.val.hash(tv.ty, hasher);
+}
diff --git a/src/Zir.zig b/src/Zir.zig
index 1aed609de9..2092a7b5e4 100644
--- a/src/Zir.zig
+++ b/src/Zir.zig
@@ -495,12 +495,15 @@ pub const Inst = struct {
/// Uses the `ptr_type` union field.
ptr_type,
/// Slice operation `lhs[rhs..]`. No sentinel and no end offset.
+ /// Returns a pointer to the subslice.
/// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceStart`.
slice_start,
/// Slice operation `array_ptr[start..end]`. No sentinel.
+ /// Returns a pointer to the subslice.
/// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceEnd`.
slice_end,
/// Slice operation `array_ptr[start..end:sentinel]`.
+ /// Returns a pointer to the subslice.
/// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceSentinel`.
slice_sentinel,
/// Write a value to a pointer. For loading, see `load`.
@@ -687,14 +690,14 @@ pub const Inst = struct {
/// A struct literal with a specified type, with no fields.
/// Uses the `un_node` field.
struct_init_empty,
- /// Given a struct, union, or enum, and a field name as a string index,
+ /// Given a struct or union, and a field name as a string index,
/// returns the field type. Uses the `pl_node` field. Payload is `FieldType`.
field_type,
- /// Given a struct, union, or enum, and a field name as a Ref,
+ /// Given a struct or union, and a field name as a Ref,
/// returns the field type. Uses the `pl_node` field. Payload is `FieldTypeRef`.
field_type_ref,
- /// Finalizes a typed struct initialization, performs validation, and returns the
- /// struct value.
+ /// Finalizes a typed struct or union initialization, performs validation, and returns the
+ /// struct or union value.
/// Uses the `pl_node` field. Payload is `StructInit`.
struct_init,
/// Struct initialization syntax, make the result a pointer.
@@ -1703,6 +1706,7 @@ pub const Inst = struct {
call_options_type,
export_options_type,
extern_options_type,
+ type_info_type,
manyptr_u8_type,
manyptr_const_u8_type,
fn_noreturn_no_args_type,
@@ -1973,6 +1977,10 @@ pub const Inst = struct {
.ty = Type.initTag(.type),
.val = Value.initTag(.extern_options_type),
},
+ .type_info_type = .{
+ .ty = Type.initTag(.type),
+ .val = Value.initTag(.type_info_type),
+ },
.undef = .{
.ty = Type.initTag(.@"undefined"),
diff --git a/src/codegen.zig b/src/codegen.zig
index 11c007dbed..9103c7ad17 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -822,6 +822,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.bit_and => try self.airBitAnd(inst),
.bit_or => try self.airBitOr(inst),
.xor => try self.airXor(inst),
+ .shr => try self.airShr(inst),
+ .shl => try self.airShl(inst),
.alloc => try self.airAlloc(inst),
.arg => try self.airArg(inst),
@@ -853,6 +855,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.store => try self.airStore(inst),
.struct_field_ptr=> try self.airStructFieldPtr(inst),
.struct_field_val=> try self.airStructFieldVal(inst),
+
+ .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
+ .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),
+ .struct_field_ptr_index_2 => try self.airStructFieldPtrIndex(inst, 2),
+ .struct_field_ptr_index_3 => try self.airStructFieldPtrIndex(inst, 3),
+
.switch_br => try self.airSwitch(inst),
.slice_ptr => try self.airSlicePtr(inst),
.slice_len => try self.airSliceLen(inst),
@@ -860,6 +868,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.slice_elem_val => try self.airSliceElemVal(inst),
.ptr_slice_elem_val => try self.airPtrSliceElemVal(inst),
.ptr_elem_val => try self.airPtrElemVal(inst),
+ .ptr_elem_ptr => try self.airPtrElemPtr(inst),
.ptr_ptr_elem_val => try self.airPtrPtrElemVal(inst),
.constant => unreachable, // excluded from function bodies
@@ -970,6 +979,20 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
log.debug("%{d} => {}", .{ inst, result });
const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
branch.inst_table.putAssumeCapacityNoClobber(inst, result);
+
+ switch (result) {
+ .register => |reg| {
+ // In some cases (such as bitcast), an operand
+ // may be the same MCValue as the result. If
+ // that operand died and was a register, it
+ // was freed by processDeath. We have to
+ // "re-allocate" the register.
+ if (self.register_manager.isRegFree(reg)) {
+ self.register_manager.getRegAssumeFree(reg, inst);
+ }
+ },
+ else => {},
+ }
}
self.finishAirBookkeeping();
}
@@ -1272,6 +1295,24 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
}
+ fn airShl(self: *Self, inst: Air.Inst.Index) !void {
+ const bin_op = self.air.instructions.items(.data)[inst].bin_op;
+ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) {
+ .arm, .armeb => try self.genArmBinOp(inst, bin_op.lhs, bin_op.rhs, .shl),
+ else => return self.fail("TODO implement shl for {}", .{self.target.cpu.arch}),
+ };
+ return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
+ }
+
+ fn airShr(self: *Self, inst: Air.Inst.Index) !void {
+ const bin_op = self.air.instructions.items(.data)[inst].bin_op;
+ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) {
+ .arm, .armeb => try self.genArmBinOp(inst, bin_op.lhs, bin_op.rhs, .shr),
+ else => return self.fail("TODO implement shr for {}", .{self.target.cpu.arch}),
+ };
+ return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
+ }
+
fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) {
@@ -1399,6 +1440,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
}
+ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
+ const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
+ const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
+ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) {
+ else => return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch}),
+ };
+ return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
+ }
+
fn airPtrPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
const is_volatile = false; // TODO
const bin_op = self.air.instructions.items(.data)[inst].bin_op;
@@ -1439,7 +1489,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
return true;
}
- fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) !void {
+ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
const elem_ty = ptr_ty.elemType();
switch (ptr) {
.none => unreachable,
@@ -1456,11 +1506,25 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.embedded_in_code => {
return self.fail("TODO implement loading from MCValue.embedded_in_code", .{});
},
- .register => {
- return self.fail("TODO implement loading from MCValue.register", .{});
+ .register => |reg| {
+ switch (arch) {
+ .arm, .armeb => switch (dst_mcv) {
+ .dead => unreachable,
+ .undef => unreachable,
+ .compare_flags_signed, .compare_flags_unsigned => unreachable,
+ .embedded_in_code => unreachable,
+ .register => |dst_reg| {
+ writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, dst_reg, reg, .{ .offset = Instruction.Offset.none }).toU32());
+ },
+ else => return self.fail("TODO load from register into {}", .{dst_mcv}),
+ },
+ else => return self.fail("TODO implement loading from MCValue.register for {}", .{arch}),
+ }
},
- .memory => {
- return self.fail("TODO implement loading from MCValue.memory", .{});
+ .memory => |addr| {
+ const reg = try self.register_manager.allocReg(null, &.{});
+ try self.genSetReg(ptr_ty, reg, .{ .memory = addr });
+ try self.load(dst_mcv, .{ .register = reg }, ptr_ty);
},
.stack_offset => {
return self.fail("TODO implement loading from MCValue.stack_offset", .{});
@@ -1534,7 +1598,18 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
- _ = extra;
+ return self.structFieldPtr(extra.struct_operand, ty_pl.ty, extra.field_index);
+ }
+
+ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ return self.structFieldPtr(ty_op.operand, ty_op.ty, index);
+ }
+ fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u32) !void {
+ _ = self;
+ _ = operand;
+ _ = ty;
+ _ = index;
return self.fail("TODO implement codegen struct_field_ptr", .{});
//return self.finishAir(inst, result, .{ extra.struct_ptr, .none, .none });
}
@@ -1572,15 +1647,53 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
fn genArmBinOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_rhs: Air.Inst.Ref, op: Air.Inst.Tag) !MCValue {
+ // In the case of bitshifts, the type of rhs is different
+ // from the resulting type
+ const ty = self.air.typeOf(op_lhs);
+
+ switch (ty.zigTypeTag()) {
+ .Float => return self.fail("TODO ARM binary operations on floats", .{}),
+ .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
+ .Bool => {
+ return self.genArmBinIntOp(inst, op_lhs, op_rhs, op, 1, .unsigned);
+ },
+ .Int => {
+ const int_info = ty.intInfo(self.target.*);
+ return self.genArmBinIntOp(inst, op_lhs, op_rhs, op, int_info.bits, int_info.signedness);
+ },
+ else => unreachable,
+ }
+ }
+
+ fn genArmBinIntOp(
+ self: *Self,
+ inst: Air.Inst.Index,
+ op_lhs: Air.Inst.Ref,
+ op_rhs: Air.Inst.Ref,
+ op: Air.Inst.Tag,
+ bits: u16,
+ signedness: std.builtin.Signedness,
+ ) !MCValue {
+ if (bits > 32) {
+ return self.fail("TODO ARM binary operations on integers > u32/i32", .{});
+ }
+
const lhs = try self.resolveInst(op_lhs);
const rhs = try self.resolveInst(op_rhs);
const lhs_is_register = lhs == .register;
const rhs_is_register = rhs == .register;
- const lhs_should_be_register = try self.armOperandShouldBeRegister(lhs);
+ const lhs_should_be_register = switch (op) {
+ .shr, .shl => true,
+ else => try self.armOperandShouldBeRegister(lhs),
+ };
const rhs_should_be_register = try self.armOperandShouldBeRegister(rhs);
const reuse_lhs = lhs_is_register and self.reuseOperand(inst, op_lhs, 0, lhs);
const reuse_rhs = !reuse_lhs and rhs_is_register and self.reuseOperand(inst, op_rhs, 1, rhs);
+ const can_swap_lhs_and_rhs = switch (op) {
+ .shr, .shl => false,
+ else => true,
+ };
// Destination must be a register
var dst_mcv: MCValue = undefined;
@@ -1597,7 +1710,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
branch.inst_table.putAssumeCapacity(Air.refToIndex(op_rhs).?, rhs_mcv);
}
dst_mcv = lhs;
- } else if (reuse_rhs) {
+ } else if (reuse_rhs and can_swap_lhs_and_rhs) {
// Allocate 0 or 1 registers
if (!lhs_is_register and lhs_should_be_register) {
lhs_mcv = MCValue{ .register = try self.register_manager.allocReg(Air.refToIndex(op_lhs).?, &.{rhs.register}) };
@@ -1636,7 +1749,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
dst_mcv = MCValue{ .register = try self.register_manager.allocReg(inst, &.{}) };
lhs_mcv = dst_mcv;
}
- } else if (rhs_should_be_register) {
+ } else if (rhs_should_be_register and can_swap_lhs_and_rhs) {
// LHS is immediate
if (rhs_is_register) {
dst_mcv = MCValue{ .register = try self.register_manager.allocReg(inst, &.{rhs.register}) };
@@ -1663,6 +1776,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
rhs_mcv,
swap_lhs_and_rhs,
op,
+ signedness,
);
return dst_mcv;
}
@@ -1674,6 +1788,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
rhs_mcv: MCValue,
swap_lhs_and_rhs: bool,
op: Air.Inst.Tag,
+ signedness: std.builtin.Signedness,
) !void {
assert(lhs_mcv == .register or rhs_mcv == .register);
@@ -1719,6 +1834,27 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.cmp_eq => {
writeInt(u32, try self.code.addManyAsArray(4), Instruction.cmp(.al, op1, operand).toU32());
},
+ .shl => {
+ assert(!swap_lhs_and_rhs);
+ const shift_amout = switch (operand) {
+ .Register => |reg_op| Instruction.ShiftAmount.reg(@intToEnum(Register, reg_op.rm)),
+ .Immediate => |imm_op| Instruction.ShiftAmount.imm(@intCast(u5, imm_op.imm)),
+ };
+ writeInt(u32, try self.code.addManyAsArray(4), Instruction.lsl(.al, dst_reg, op1, shift_amout).toU32());
+ },
+ .shr => {
+ assert(!swap_lhs_and_rhs);
+ const shift_amout = switch (operand) {
+ .Register => |reg_op| Instruction.ShiftAmount.reg(@intToEnum(Register, reg_op.rm)),
+ .Immediate => |imm_op| Instruction.ShiftAmount.imm(@intCast(u5, imm_op.imm)),
+ };
+
+ const shr = switch (signedness) {
+ .signed => Instruction.asr,
+ .unsigned => Instruction.lsr,
+ };
+ writeInt(u32, try self.code.addManyAsArray(4), shr(.al, dst_reg, op1, shift_amout).toU32());
+ },
else => unreachable, // not a binary instruction
}
}
@@ -2969,7 +3105,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
// The destination register is not present in the cmp instruction
- try self.genArmBinOpCode(undefined, lhs_mcv, rhs_mcv, false, .cmp_eq);
+ // The signedness of the integer does not matter for the cmp instruction
+ try self.genArmBinOpCode(undefined, lhs_mcv, rhs_mcv, false, .cmp_eq, undefined);
break :result switch (ty.isSignedInt()) {
true => MCValue{ .compare_flags_signed = op },
@@ -3792,15 +3929,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
else => return self.fail("TODO implement memset", .{}),
}
},
- .compare_flags_unsigned => |op| {
- _ = op;
- return self.fail("TODO implement set stack variable with compare flags value (unsigned)", .{});
- },
- .compare_flags_signed => |op| {
- _ = op;
- return self.fail("TODO implement set stack variable with compare flags value (signed)", .{});
- },
- .immediate => {
+ .compare_flags_unsigned,
+ .compare_flags_signed,
+ .immediate,
+ => {
const reg = try self.copyToTmpRegister(ty, mcv);
return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
},
@@ -3968,15 +4100,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
else => return self.fail("TODO implement memset", .{}),
}
},
- .compare_flags_unsigned => |op| {
- _ = op;
- return self.fail("TODO implement set stack variable with compare flags value (unsigned)", .{});
- },
- .compare_flags_signed => |op| {
- _ = op;
- return self.fail("TODO implement set stack variable with compare flags value (signed)", .{});
- },
- .immediate => {
+ .compare_flags_unsigned,
+ .compare_flags_signed,
+ .immediate,
+ => {
const reg = try self.copyToTmpRegister(ty, mcv);
return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
},
diff --git a/src/codegen/arm.zig b/src/codegen/arm.zig
index 891a9e100b..3743afd50f 100644
--- a/src/codegen/arm.zig
+++ b/src/codegen/arm.zig
@@ -192,7 +192,7 @@ pub const c_abi_int_return_regs = [_]Register{ .r0, .r1 };
/// Represents an instruction in the ARM instruction set architecture
pub const Instruction = union(enum) {
- DataProcessing: packed struct {
+ data_processing: packed struct {
// Note to self: The order of the fields top-to-bottom is
// right-to-left in the actual 32-bit int representation
op2: u12,
@@ -204,7 +204,7 @@ pub const Instruction = union(enum) {
fixed: u2 = 0b00,
cond: u4,
},
- Multiply: packed struct {
+ multiply: packed struct {
rn: u4,
fixed_1: u4 = 0b1001,
rm: u4,
@@ -215,7 +215,7 @@ pub const Instruction = union(enum) {
fixed_2: u6 = 0b000000,
cond: u4,
},
- MultiplyLong: packed struct {
+ multiply_long: packed struct {
rn: u4,
fixed_1: u4 = 0b1001,
rm: u4,
@@ -227,7 +227,17 @@ pub const Instruction = union(enum) {
fixed_2: u5 = 0b00001,
cond: u4,
},
- SingleDataTransfer: packed struct {
+ integer_saturating_arithmetic: packed struct {
+ rm: u4,
+ fixed_1: u8 = 0b0000_0101,
+ rd: u4,
+ rn: u4,
+ fixed_2: u1 = 0b0,
+ opc: u2,
+ fixed_3: u5 = 0b00010,
+ cond: u4,
+ },
+ single_data_transfer: packed struct {
offset: u12,
rd: u4,
rn: u4,
@@ -240,7 +250,7 @@ pub const Instruction = union(enum) {
fixed: u2 = 0b01,
cond: u4,
},
- ExtraLoadStore: packed struct {
+ extra_load_store: packed struct {
imm4l: u4,
fixed_1: u1 = 0b1,
op2: u2,
@@ -256,7 +266,7 @@ pub const Instruction = union(enum) {
fixed_3: u3 = 0b000,
cond: u4,
},
- BlockDataTransfer: packed struct {
+ block_data_transfer: packed struct {
register_list: u16,
rn: u4,
load_store: u1,
@@ -267,25 +277,25 @@ pub const Instruction = union(enum) {
fixed: u3 = 0b100,
cond: u4,
},
- Branch: packed struct {
+ branch: packed struct {
offset: u24,
link: u1,
fixed: u3 = 0b101,
cond: u4,
},
- BranchExchange: packed struct {
+ branch_exchange: packed struct {
rn: u4,
fixed_1: u1 = 0b1,
link: u1,
fixed_2: u22 = 0b0001_0010_1111_1111_1111_00,
cond: u4,
},
- SupervisorCall: packed struct {
+ supervisor_call: packed struct {
comment: u24,
fixed: u4 = 0b1111,
cond: u4,
},
- Breakpoint: packed struct {
+ breakpoint: packed struct {
imm4: u4,
fixed_1: u4 = 0b0111,
imm12: u12,
@@ -293,7 +303,7 @@ pub const Instruction = union(enum) {
},
/// Represents the possible operations which can be performed by a
- /// DataProcessing instruction
+ /// Data Processing instruction
const Opcode = enum(u4) {
// Rd := Op1 AND Op2
@"and",
@@ -530,16 +540,17 @@ pub const Instruction = union(enum) {
pub fn toU32(self: Instruction) u32 {
return switch (self) {
- .DataProcessing => |v| @bitCast(u32, v),
- .Multiply => |v| @bitCast(u32, v),
- .MultiplyLong => |v| @bitCast(u32, v),
- .SingleDataTransfer => |v| @bitCast(u32, v),
- .ExtraLoadStore => |v| @bitCast(u32, v),
- .BlockDataTransfer => |v| @bitCast(u32, v),
- .Branch => |v| @bitCast(u32, v),
- .BranchExchange => |v| @bitCast(u32, v),
- .SupervisorCall => |v| @bitCast(u32, v),
- .Breakpoint => |v| @intCast(u32, v.imm4) | (@intCast(u32, v.fixed_1) << 4) | (@intCast(u32, v.imm12) << 8) | (@intCast(u32, v.fixed_2_and_cond) << 20),
+ .data_processing => |v| @bitCast(u32, v),
+ .multiply => |v| @bitCast(u32, v),
+ .multiply_long => |v| @bitCast(u32, v),
+ .integer_saturating_arithmetic => |v| @bitCast(u32, v),
+ .single_data_transfer => |v| @bitCast(u32, v),
+ .extra_load_store => |v| @bitCast(u32, v),
+ .block_data_transfer => |v| @bitCast(u32, v),
+ .branch => |v| @bitCast(u32, v),
+ .branch_exchange => |v| @bitCast(u32, v),
+ .supervisor_call => |v| @bitCast(u32, v),
+ .breakpoint => |v| @intCast(u32, v.imm4) | (@intCast(u32, v.fixed_1) << 4) | (@intCast(u32, v.imm12) << 8) | (@intCast(u32, v.fixed_2_and_cond) << 20),
};
}
@@ -554,7 +565,7 @@ pub const Instruction = union(enum) {
op2: Operand,
) Instruction {
return Instruction{
- .DataProcessing = .{
+ .data_processing = .{
.cond = @enumToInt(cond),
.i = @boolToInt(op2 == .Immediate),
.opcode = @enumToInt(opcode),
@@ -573,7 +584,7 @@ pub const Instruction = union(enum) {
top: bool,
) Instruction {
return Instruction{
- .DataProcessing = .{
+ .data_processing = .{
.cond = @enumToInt(cond),
.i = 1,
.opcode = if (top) 0b1010 else 0b1000,
@@ -594,7 +605,7 @@ pub const Instruction = union(enum) {
ra: ?Register,
) Instruction {
return Instruction{
- .Multiply = .{
+ .multiply = .{
.cond = @enumToInt(cond),
.accumulate = @boolToInt(ra != null),
.set_cond = set_cond,
@@ -617,7 +628,7 @@ pub const Instruction = union(enum) {
rn: Register,
) Instruction {
return Instruction{
- .MultiplyLong = .{
+ .multiply_long = .{
.cond = @enumToInt(cond),
.unsigned = signed,
.accumulate = accumulate,
@@ -630,6 +641,24 @@ pub const Instruction = union(enum) {
};
}
+ fn integerSaturationArithmetic(
+ cond: Condition,
+ rd: Register,
+ rm: Register,
+ rn: Register,
+ opc: u2,
+ ) Instruction {
+ return Instruction{
+ .integer_saturating_arithmetic = .{
+ .rm = rm.id(),
+ .rd = rd.id(),
+ .rn = rn.id(),
+ .opc = opc,
+ .cond = @enumToInt(cond),
+ },
+ };
+ }
+
fn singleDataTransfer(
cond: Condition,
rd: Register,
@@ -642,7 +671,7 @@ pub const Instruction = union(enum) {
load_store: u1,
) Instruction {
return Instruction{
- .SingleDataTransfer = .{
+ .single_data_transfer = .{
.cond = @enumToInt(cond),
.rn = rn.id(),
.rd = rd.id(),
@@ -678,7 +707,7 @@ pub const Instruction = union(enum) {
};
return Instruction{
- .ExtraLoadStore = .{
+ .extra_load_store = .{
.imm4l = imm4l,
.op2 = op2,
.imm4h = imm4h,
@@ -705,7 +734,7 @@ pub const Instruction = union(enum) {
load_store: u1,
) Instruction {
return Instruction{
- .BlockDataTransfer = .{
+ .block_data_transfer = .{
.register_list = @bitCast(u16, reg_list),
.rn = rn.id(),
.load_store = load_store,
@@ -720,7 +749,7 @@ pub const Instruction = union(enum) {
fn branch(cond: Condition, offset: i26, link: u1) Instruction {
return Instruction{
- .Branch = .{
+ .branch = .{
.cond = @enumToInt(cond),
.link = link,
.offset = @bitCast(u24, @intCast(i24, offset >> 2)),
@@ -730,7 +759,7 @@ pub const Instruction = union(enum) {
fn branchExchange(cond: Condition, rn: Register, link: u1) Instruction {
return Instruction{
- .BranchExchange = .{
+ .branch_exchange = .{
.cond = @enumToInt(cond),
.link = link,
.rn = rn.id(),
@@ -740,7 +769,7 @@ pub const Instruction = union(enum) {
fn supervisorCall(cond: Condition, comment: u24) Instruction {
return Instruction{
- .SupervisorCall = .{
+ .supervisor_call = .{
.cond = @enumToInt(cond),
.comment = comment,
},
@@ -749,7 +778,7 @@ pub const Instruction = union(enum) {
fn breakpoint(imm: u16) Instruction {
return Instruction{
- .Breakpoint = .{
+ .breakpoint = .{
.imm12 = @truncate(u12, imm >> 4),
.imm4 = @truncate(u4, imm),
},
@@ -873,6 +902,24 @@ pub const Instruction = union(enum) {
return dataProcessing(cond, .mvn, 1, rd, .r0, op2);
}
+ // Integer Saturating Arithmetic
+
+ pub fn qadd(cond: Condition, rd: Register, rm: Register, rn: Register) Instruction {
+ return integerSaturationArithmetic(cond, rd, rm, rn, 0b00);
+ }
+
+ pub fn qsub(cond: Condition, rd: Register, rm: Register, rn: Register) Instruction {
+ return integerSaturationArithmetic(cond, rd, rm, rn, 0b01);
+ }
+
+ pub fn qdadd(cond: Condition, rd: Register, rm: Register, rn: Register) Instruction {
+ return integerSaturationArithmetic(cond, rd, rm, rn, 0b10);
+ }
+
+ pub fn qdsub(cond: Condition, rd: Register, rm: Register, rn: Register) Instruction {
+ return integerSaturationArithmetic(cond, rd, rm, rn, 0b11);
+ }
+
// movw and movt
pub fn movw(cond: Condition, rd: Register, imm: u16) Instruction {
@@ -887,7 +934,7 @@ pub const Instruction = union(enum) {
pub fn mrs(cond: Condition, rd: Register, psr: Psr) Instruction {
return Instruction{
- .DataProcessing = .{
+ .data_processing = .{
.cond = @enumToInt(cond),
.i = 0,
.opcode = if (psr == .spsr) 0b1010 else 0b1000,
@@ -901,7 +948,7 @@ pub const Instruction = union(enum) {
pub fn msr(cond: Condition, psr: Psr, op: Operand) Instruction {
return Instruction{
- .DataProcessing = .{
+ .data_processing = .{
.cond = @enumToInt(cond),
.i = 0,
.opcode = if (psr == .spsr) 0b1011 else 0b1001,
@@ -1142,6 +1189,79 @@ pub const Instruction = union(enum) {
return stmdb(cond, .sp, true, @bitCast(RegisterList, register_list));
}
}
+
+ pub const ShiftAmount = union(enum) {
+ immediate: u5,
+ register: Register,
+
+ pub fn imm(immediate: u5) ShiftAmount {
+ return .{
+ .immediate = immediate,
+ };
+ }
+
+ pub fn reg(register: Register) ShiftAmount {
+ return .{
+ .register = register,
+ };
+ }
+ };
+
+ pub fn lsl(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| mov(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .logical_left))),
+ .register => |reg| mov(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .logical_left))),
+ };
+ }
+
+ pub fn lsr(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| mov(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .logical_right))),
+ .register => |reg| mov(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .logical_right))),
+ };
+ }
+
+ pub fn asr(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| mov(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .arithmetic_right))),
+ .register => |reg| mov(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .arithmetic_right))),
+ };
+ }
+
+ pub fn ror(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| mov(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .rotate_right))),
+ .register => |reg| mov(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .rotate_right))),
+ };
+ }
+
+ pub fn lsls(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| movs(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .logical_left))),
+ .register => |reg| movs(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .logical_left))),
+ };
+ }
+
+ pub fn lsrs(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| movs(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .logical_right))),
+ .register => |reg| movs(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .logical_right))),
+ };
+ }
+
+ pub fn asrs(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| movs(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .arithmetic_right))),
+ .register => |reg| movs(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .arithmetic_right))),
+ };
+ }
+
+ pub fn rors(cond: Condition, rd: Register, rm: Register, shift: ShiftAmount) Instruction {
+ return switch (shift) {
+ .immediate => |imm| movs(cond, rd, Operand.reg(rm, Operand.Shift.imm(imm, .rotate_right))),
+ .register => |reg| movs(cond, rd, Operand.reg(rm, Operand.Shift.reg(reg, .rotate_right))),
+ };
+ }
};
test "serialize instructions" {
@@ -1221,6 +1341,10 @@ test "serialize instructions" {
.inst = Instruction.ldmea(.al, .r4, true, .{ .r2 = true, .r5 = true }),
.expected = 0b1110_100_1_0_0_1_1_0100_0000000000100100,
},
+ .{ // qadd r0, r7, r8
+ .inst = Instruction.qadd(.al, .r0, .r7, .r8),
+ .expected = 0b1110_00010_00_0_1000_0000_0000_0101_0111,
+ },
};
for (testcases) |case| {
@@ -1262,6 +1386,20 @@ test "aliases" {
.actual = Instruction.push(.al, .{ .r0, .r2 }),
.expected = Instruction.stmdb(.al, .sp, true, .{ .r0 = true, .r2 = true }),
},
+ .{ // lsl r4, r5, #5
+ .actual = Instruction.lsl(.al, .r4, .r5, Instruction.ShiftAmount.imm(5)),
+ .expected = Instruction.mov(.al, .r4, Instruction.Operand.reg(
+ .r5,
+ Instruction.Operand.Shift.imm(5, .logical_left),
+ )),
+ },
+ .{ // asrs r1, r1, r3
+ .actual = Instruction.asrs(.al, .r1, .r1, Instruction.ShiftAmount.reg(.r3)),
+ .expected = Instruction.movs(.al, .r1, Instruction.Operand.reg(
+ .r1,
+ Instruction.Operand.Shift.reg(.r3, .arithmetic_right),
+ )),
+ },
};
for (testcases) |case| {
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index a67e2438c2..2084b1e1ce 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -319,18 +319,20 @@ pub const DeclGen = struct {
.Bool => return writer.print("{}", .{val.toBool()}),
.Optional => {
var opt_buf: Type.Payload.ElemType = undefined;
- const child_type = t.optionalChild(&opt_buf);
+ const payload_type = t.optionalChild(&opt_buf);
if (t.isPtrLikeOptional()) {
- return dg.renderValue(writer, child_type, val);
+ return dg.renderValue(writer, payload_type, val);
}
try writer.writeByte('(');
try dg.renderType(writer, t);
- if (val.tag() == .null_value) {
- try writer.writeAll("){ .is_null = true }");
- } else {
- try writer.writeAll("){ .is_null = false, .payload = ");
- try dg.renderValue(writer, child_type, val);
+ try writer.writeAll("){");
+ if (val.castTag(.opt_payload)) |pl| {
+ const payload_val = pl.data;
+ try writer.writeAll(" .is_null = false, .payload = ");
+ try dg.renderValue(writer, payload_type, payload_val);
try writer.writeAll(" }");
+ } else {
+ try writer.writeAll(" .is_null = true }");
}
},
.ErrorSet => {
@@ -871,6 +873,9 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM
.bit_or => try airBinOp(o, inst, " | "),
.xor => try airBinOp(o, inst, " ^ "),
+ .shr => try airBinOp(o, inst, " >> "),
+ .shl => try airBinOp(o, inst, " << "),
+
.not => try airNot( o, inst),
.optional_payload => try airOptionalPayload(o, inst),
@@ -904,12 +909,19 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM
.switch_br => try airSwitchBr(o, inst),
.wrap_optional => try airWrapOptional(o, inst),
.struct_field_ptr => try airStructFieldPtr(o, inst),
+
+ .struct_field_ptr_index_0 => try airStructFieldPtrIndex(o, inst, 0),
+ .struct_field_ptr_index_1 => try airStructFieldPtrIndex(o, inst, 1),
+ .struct_field_ptr_index_2 => try airStructFieldPtrIndex(o, inst, 2),
+ .struct_field_ptr_index_3 => try airStructFieldPtrIndex(o, inst, 3),
+
.struct_field_val => try airStructFieldVal(o, inst),
.slice_ptr => try airSliceField(o, inst, ".ptr;\n"),
.slice_len => try airSliceField(o, inst, ".len;\n"),
.ptr_elem_val => try airPtrElemVal(o, inst, "["),
.ptr_ptr_elem_val => try airPtrElemVal(o, inst, "[0]["),
+ .ptr_elem_ptr => try airPtrElemPtr(o, inst),
.slice_elem_val => try airSliceElemVal(o, inst, "["),
.ptr_slice_elem_val => try airSliceElemVal(o, inst, "[0]["),
@@ -957,6 +969,13 @@ fn airPtrElemVal(o: *Object, inst: Air.Inst.Index, prefix: []const u8) !CValue {
return o.dg.fail("TODO: C backend: airPtrElemVal", .{});
}
+fn airPtrElemPtr(o: *Object, inst: Air.Inst.Index) !CValue {
+ if (o.liveness.isUnused(inst))
+ return CValue.none;
+
+ return o.dg.fail("TODO: C backend: airPtrElemPtr", .{});
+}
+
fn airSliceElemVal(o: *Object, inst: Air.Inst.Index, prefix: []const u8) !CValue {
const is_volatile = false; // TODO
if (!is_volatile and o.liveness.isUnused(inst))
@@ -1638,15 +1657,31 @@ fn airOptionalPayload(o: *Object, inst: Air.Inst.Index) !CValue {
fn airStructFieldPtr(o: *Object, inst: Air.Inst.Index) !CValue {
if (o.liveness.isUnused(inst))
- return CValue.none;
+ // TODO this @as is needed because of a stage1 bug
+ return @as(CValue, CValue.none);
const ty_pl = o.air.instructions.items(.data)[inst].ty_pl;
const extra = o.air.extraData(Air.StructField, ty_pl.payload).data;
- const writer = o.writer();
const struct_ptr = try o.resolveInst(extra.struct_operand);
const struct_ptr_ty = o.air.typeOf(extra.struct_operand);
+ return structFieldPtr(o, inst, struct_ptr_ty, struct_ptr, extra.field_index);
+}
+
+fn airStructFieldPtrIndex(o: *Object, inst: Air.Inst.Index, index: u8) !CValue {
+ if (o.liveness.isUnused(inst))
+ // TODO this @as is needed because of a stage1 bug
+ return @as(CValue, CValue.none);
+
+ const ty_op = o.air.instructions.items(.data)[inst].ty_op;
+ const struct_ptr = try o.resolveInst(ty_op.operand);
+ const struct_ptr_ty = o.air.typeOf(ty_op.operand);
+ return structFieldPtr(o, inst, struct_ptr_ty, struct_ptr, index);
+}
+
+fn structFieldPtr(o: *Object, inst: Air.Inst.Index, struct_ptr_ty: Type, struct_ptr: CValue, index: u32) !CValue {
+ const writer = o.writer();
const struct_obj = struct_ptr_ty.elemType().castTag(.@"struct").?.data;
- const field_name = struct_obj.fields.keys()[extra.field_index];
+ const field_name = struct_obj.fields.keys()[index];
const inst_ty = o.air.typeOfIndex(inst);
const local = try o.allocLocal(inst_ty, .Const);
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 2b678b0a69..0a715edbfd 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -434,6 +434,8 @@ pub const Object = struct {
},
else => |e| return e,
};
+ const decl_exports = module.decl_exports.get(decl) orelse &[0]*Module.Export{};
+ try self.updateDeclExports(module, decl, decl_exports);
}
pub fn updateDeclExports(
@@ -442,7 +444,9 @@ pub const Object = struct {
decl: *const Module.Decl,
exports: []const *Module.Export,
) !void {
- const llvm_fn = self.llvm_module.getNamedFunction(decl.name).?;
+ // If the module does not already have the function, we ignore this function call
+ // because we call `updateDeclExports` at the end of `updateFunc` and `updateDecl`.
+ const llvm_fn = self.llvm_module.getNamedFunction(decl.name) orelse return;
const is_extern = decl.val.tag() == .extern_fn;
if (is_extern or exports.len != 0) {
llvm_fn.setLinkage(.External);
@@ -808,27 +812,22 @@ pub const DeclGen = struct {
return self.todo("handle more array values", .{});
},
.Optional => {
- if (!tv.ty.isPtrLikeOptional()) {
- var buf: Type.Payload.ElemType = undefined;
- const child_type = tv.ty.optionalChild(&buf);
- const llvm_child_type = try self.llvmType(child_type);
-
- if (tv.val.tag() == .null_value) {
- var optional_values: [2]*const llvm.Value = .{
- llvm_child_type.constNull(),
- self.context.intType(1).constNull(),
- };
- return self.context.constStruct(&optional_values, optional_values.len, .False);
- } else {
- var optional_values: [2]*const llvm.Value = .{
- try self.genTypedValue(.{ .ty = child_type, .val = tv.val }),
- self.context.intType(1).constAllOnes(),
- };
- return self.context.constStruct(&optional_values, optional_values.len, .False);
- }
- } else {
+ if (tv.ty.isPtrLikeOptional()) {
return self.todo("implement const of optional pointer", .{});
}
+ var buf: Type.Payload.ElemType = undefined;
+ const payload_type = tv.ty.optionalChild(&buf);
+ const is_pl = !tv.val.isNull();
+ const llvm_i1 = self.context.intType(1);
+
+ const fields: [2]*const llvm.Value = .{
+ try self.genTypedValue(.{
+ .ty = payload_type,
+ .val = if (tv.val.castTag(.opt_payload)) |pl| pl.data else Value.initTag(.undef),
+ }),
+ if (is_pl) llvm_i1.constAllOnes() else llvm_i1.constNull(),
+ };
+ return self.context.constStruct(&fields, fields.len, .False);
},
.Fn => {
const fn_decl = switch (tv.val.tag()) {
@@ -995,6 +994,9 @@ pub const FuncGen = struct {
.bit_or, .bool_or => try self.airOr(inst),
.xor => try self.airXor(inst),
+ .shl => try self.airShl(inst),
+ .shr => try self.airShr(inst),
+
.cmp_eq => try self.airCmp(inst, .eq),
.cmp_gt => try self.airCmp(inst, .gt),
.cmp_gte => try self.airCmp(inst, .gte),
@@ -1037,9 +1039,15 @@ pub const FuncGen = struct {
.struct_field_ptr => try self.airStructFieldPtr(inst),
.struct_field_val => try self.airStructFieldVal(inst),
+ .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
+ .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),
+ .struct_field_ptr_index_2 => try self.airStructFieldPtrIndex(inst, 2),
+ .struct_field_ptr_index_3 => try self.airStructFieldPtrIndex(inst, 3),
+
.slice_elem_val => try self.airSliceElemVal(inst),
.ptr_slice_elem_val => try self.airPtrSliceElemVal(inst),
.ptr_elem_val => try self.airPtrElemVal(inst),
+ .ptr_elem_ptr => try self.airPtrElemPtr(inst),
.ptr_ptr_elem_val => try self.airPtrPtrElemVal(inst),
.optional_payload => try self.airOptionalPayload(inst, false),
@@ -1295,11 +1303,35 @@ pub const FuncGen = struct {
const bin_op = self.air.instructions.items(.data)[inst].bin_op;
const base_ptr = try self.resolveInst(bin_op.lhs);
const rhs = try self.resolveInst(bin_op.rhs);
- const indices: [1]*const llvm.Value = .{rhs};
- const ptr = self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
+ const ptr = if (self.air.typeOf(bin_op.lhs).isSinglePointer()) ptr: {
+ // If this is a single-item pointer to an array, we need another index in the GEP.
+ const indices: [2]*const llvm.Value = .{ self.context.intType(32).constNull(), rhs };
+ break :ptr self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
+ } else ptr: {
+ const indices: [1]*const llvm.Value = .{rhs};
+ break :ptr self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
+ };
return self.builder.buildLoad(ptr, "");
}
+ fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst))
+ return null;
+
+ const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
+ const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
+ const base_ptr = try self.resolveInst(bin_op.lhs);
+ const rhs = try self.resolveInst(bin_op.rhs);
+ if (self.air.typeOf(bin_op.lhs).isSinglePointer()) {
+ // If this is a single-item pointer to an array, we need another index in the GEP.
+ const indices: [2]*const llvm.Value = .{ self.context.intType(32).constNull(), rhs };
+ return self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
+ } else {
+ const indices: [1]*const llvm.Value = .{rhs};
+ return self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, "");
+ }
+ }
+
fn airPtrPtrElemVal(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
const is_volatile = false; // TODO
if (!is_volatile and self.liveness.isUnused(inst))
@@ -1325,6 +1357,15 @@ pub const FuncGen = struct {
return self.builder.buildStructGEP(struct_ptr, field_index, "");
}
+ fn airStructFieldPtrIndex(self: *FuncGen, inst: Air.Inst.Index, field_index: c_uint) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst))
+ return null;
+
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ const struct_ptr = try self.resolveInst(ty_op.operand);
+ return self.builder.buildStructGEP(struct_ptr, field_index, "");
+ }
+
fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
if (self.liveness.isUnused(inst))
return null;
@@ -1739,6 +1780,41 @@ pub const FuncGen = struct {
return self.builder.buildXor(lhs, rhs, "");
}
+ fn airShl(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst))
+ return null;
+ const bin_op = self.air.instructions.items(.data)[inst].bin_op;
+ const lhs = try self.resolveInst(bin_op.lhs);
+ const rhs = try self.resolveInst(bin_op.rhs);
+ const lhs_type = self.air.typeOf(bin_op.lhs);
+ const tg = self.dg.module.getTarget();
+ const casted_rhs = if (self.air.typeOf(bin_op.rhs).bitSize(tg) < lhs_type.bitSize(tg))
+ self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_type), "")
+ else
+ rhs;
+ return self.builder.buildShl(lhs, casted_rhs, "");
+ }
+
+ fn airShr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst))
+ return null;
+ const bin_op = self.air.instructions.items(.data)[inst].bin_op;
+ const lhs = try self.resolveInst(bin_op.lhs);
+ const rhs = try self.resolveInst(bin_op.rhs);
+ const lhs_type = self.air.typeOf(bin_op.lhs);
+ const tg = self.dg.module.getTarget();
+ const casted_rhs = if (self.air.typeOf(bin_op.rhs).bitSize(tg) < lhs_type.bitSize(tg))
+ self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_type), "")
+ else
+ rhs;
+
+ if (self.air.typeOfIndex(inst).isSignedInt()) {
+ return self.builder.buildAShr(lhs, casted_rhs, "");
+ } else {
+ return self.builder.buildLShr(lhs, casted_rhs, "");
+ }
+ }
+
fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
if (self.liveness.isUnused(inst))
return null;
diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig
index fc97dfb81f..fe0c211df3 100644
--- a/src/codegen/llvm/bindings.zig
+++ b/src/codegen/llvm/bindings.zig
@@ -291,6 +291,14 @@ pub const Builder = opaque {
pub const getInsertBlock = LLVMGetInsertBlock;
extern fn LLVMGetInsertBlock(Builder: *const Builder) *const BasicBlock;
+ pub const buildZExt = LLVMBuildZExt;
+ extern fn LLVMBuildZExt(
+ *const Builder,
+ Value: *const Value,
+ DestTy: *const Type,
+ Name: [*:0]const u8,
+ ) *const Value;
+
pub const buildCall = LLVMBuildCall;
extern fn LLVMBuildCall(
*const Builder,
@@ -382,6 +390,15 @@ pub const Builder = opaque {
pub const buildAnd = LLVMBuildAnd;
extern fn LLVMBuildAnd(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;
+ pub const buildLShr = LLVMBuildLShr;
+ extern fn LLVMBuildLShr(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;
+
+ pub const buildAShr = LLVMBuildAShr;
+ extern fn LLVMBuildAShr(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;
+
+ pub const buildShl = LLVMBuildShl;
+ extern fn LLVMBuildShl(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;
+
pub const buildOr = LLVMBuildOr;
extern fn LLVMBuildOr(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;
diff --git a/src/codegen/wasm.zig b/src/codegen/wasm.zig
index 4814ba0b55..bb05567236 100644
--- a/src/codegen/wasm.zig
+++ b/src/codegen/wasm.zig
@@ -862,6 +862,10 @@ pub const Context = struct {
.ret => self.airRet(inst),
.store => self.airStore(inst),
.struct_field_ptr => self.airStructFieldPtr(inst),
+ .struct_field_ptr_index_0 => self.airStructFieldPtrIndex(inst, 0),
+ .struct_field_ptr_index_1 => self.airStructFieldPtrIndex(inst, 1),
+ .struct_field_ptr_index_2 => self.airStructFieldPtrIndex(inst, 2),
+ .struct_field_ptr_index_3 => self.airStructFieldPtrIndex(inst, 3),
.switch_br => self.airSwitchBr(inst),
.unreach => self.airUnreachable(inst),
.wrap_optional => self.airWrapOptional(inst),
@@ -1198,7 +1202,12 @@ pub const Context = struct {
// When constant has value 'null', set is_null local to '1'
// and payload to '0'
- if (val.tag() == .null_value) {
+ if (val.castTag(.opt_payload)) |pl| {
+ const payload_val = pl.data;
+ try writer.writeByte(wasm.opcode(.i32_const));
+ try leb.writeILEB128(writer, @as(i32, 0));
+ try self.emitConstant(payload_val, payload_type);
+ } else {
try writer.writeByte(wasm.opcode(.i32_const));
try leb.writeILEB128(writer, @as(i32, 1));
@@ -1208,10 +1217,6 @@ pub const Context = struct {
});
try writer.writeByte(wasm.opcode(opcode));
try leb.writeULEB128(writer, @as(u32, 0));
- } else {
- try writer.writeByte(wasm.opcode(.i32_const));
- try leb.writeILEB128(writer, @as(i32, 0));
- try self.emitConstant(val, payload_type);
}
},
else => |zig_type| return self.fail("Wasm TODO: emitConstant for zigTypeTag {s}", .{zig_type}),
@@ -1440,8 +1445,15 @@ pub const Context = struct {
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
const extra = self.air.extraData(Air.StructField, ty_pl.payload);
const struct_ptr = self.resolveInst(extra.data.struct_operand);
-
- return WValue{ .local = struct_ptr.multi_value.index + @intCast(u32, extra.data.field_index) };
+ return structFieldPtr(struct_ptr, extra.data.field_index);
+ }
+ fn airStructFieldPtrIndex(self: *Context, inst: Air.Inst.Index, index: u32) InnerError!WValue {
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ const struct_ptr = self.resolveInst(ty_op.operand);
+ return structFieldPtr(struct_ptr, index);
+ }
+ fn structFieldPtr(struct_ptr: WValue, index: u32) InnerError!WValue {
+ return WValue{ .local = struct_ptr.multi_value.index + index };
}
fn airSwitchBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index 3c3cd4eef3..fc559948c4 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -765,12 +765,8 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
if (self.base.options.wasi_exec_model == .reactor) {
// Reactor execution model does not have _start so lld doesn't look for it.
try argv.append("--no-entry");
- // Make sure "_initialize" is exported even if this is pure Zig WASI reactor
- // where WASM_SYMBOL_EXPORTED flag in LLVM is not set on _initialize.
- try argv.appendSlice(&[_][]const u8{
- "--export",
- "_initialize",
- });
+ // Make sure "_initialize" and other used-defined functions are exported if this is WASI reactor.
+ try argv.append("--export-dynamic");
}
} else {
try argv.append("--no-entry"); // So lld doesn't look for _start.
diff --git a/src/main.zig b/src/main.zig
index 285b6d2316..44b3a0515c 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2492,6 +2492,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
const digest = if (try man.hit()) man.final() else digest: {
var argv = std.ArrayList([]const u8).init(arena);
+ try argv.append(""); // argv[0] is program name, actual args start at [1]
var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{});
defer zig_cache_tmp_dir.close();
diff --git a/src/mingw.zig b/src/mingw.zig
index 42d1ac47db..529025c517 100644
--- a/src/mingw.zig
+++ b/src/mingw.zig
@@ -187,27 +187,25 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
};
}
} else if (target.cpu.arch.isARM()) {
- if (target.cpu.arch.ptrBitWidth() == 32) {
- for (mingwex_arm32_src) |dep| {
- (try c_source_files.addOne()).* = .{
- .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
- "libc", "mingw", dep,
- }),
- .extra_flags = extra_flags,
- };
- }
- } else {
- for (mingwex_arm64_src) |dep| {
- (try c_source_files.addOne()).* = .{
- .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
- "libc", "mingw", dep,
- }),
- .extra_flags = extra_flags,
- };
- }
+ for (mingwex_arm32_src) |dep| {
+ (try c_source_files.addOne()).* = .{
+ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
+ "libc", "mingw", dep,
+ }),
+ .extra_flags = extra_flags,
+ };
+ }
+ } else if (target.cpu.arch.isAARCH64()) {
+ for (mingwex_arm64_src) |dep| {
+ (try c_source_files.addOne()).* = .{
+ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
+ "libc", "mingw", dep,
+ }),
+ .extra_flags = extra_flags,
+ };
}
} else {
- unreachable;
+ @panic("unsupported arch");
}
return comp.build_crt_file("mingwex", .Lib, c_source_files.items);
},
diff --git a/src/print_air.zig b/src/print_air.zig
index 66490b6512..276158f720 100644
--- a/src/print_air.zig
+++ b/src/print_air.zig
@@ -127,6 +127,8 @@ const Writer = struct {
.ptr_slice_elem_val,
.ptr_elem_val,
.ptr_ptr_elem_val,
+ .shl,
+ .shr,
=> try w.writeBinOp(s, inst),
.is_null,
@@ -167,12 +169,17 @@ const Writer = struct {
.wrap_errunion_err,
.slice_ptr,
.slice_len,
+ .struct_field_ptr_index_0,
+ .struct_field_ptr_index_1,
+ .struct_field_ptr_index_2,
+ .struct_field_ptr_index_3,
=> try w.writeTyOp(s, inst),
.block,
.loop,
=> try w.writeBlock(s, inst),
+ .ptr_elem_ptr => try w.writePtrElemPtr(s, inst),
.struct_field_ptr => try w.writeStructField(s, inst),
.struct_field_val => try w.writeStructField(s, inst),
.constant => try w.writeConstant(s, inst),
@@ -237,10 +244,19 @@ const Writer = struct {
fn writeStructField(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
- const extra = w.air.extraData(Air.StructField, ty_pl.payload);
+ const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;
- try w.writeOperand(s, inst, 0, extra.data.struct_operand);
- try s.print(", {d}", .{extra.data.field_index});
+ try w.writeOperand(s, inst, 0, extra.struct_operand);
+ try s.print(", {d}", .{extra.field_index});
+ }
+
+ fn writePtrElemPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
+ const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
+ const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;
+
+ try w.writeOperand(s, inst, 0, extra.lhs);
+ try s.writeAll(", ");
+ try w.writeOperand(s, inst, 0, extra.rhs);
}
fn writeConstant(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp
index dfebc66cfd..fc3b00d6db 100644
--- a/src/stage1/all_types.hpp
+++ b/src/stage1/all_types.hpp
@@ -1125,6 +1125,7 @@ struct AstNodeContainerInitExpr {
struct AstNodeIdentifier {
Buf *name;
+ bool is_at_syntax;
};
struct AstNodeEnumLiteral {
diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp
index cf61bf79b7..2eb609ef1a 100644
--- a/src/stage1/analyze.cpp
+++ b/src/stage1/analyze.cpp
@@ -3918,12 +3918,6 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition here"));
return;
}
-
- ZigType *type;
- if (get_primitive_type(g, tld->name, &type) != ErrorPrimitiveTypeNotFound) {
- add_node_error(g, tld->source_node,
- buf_sprintf("declaration shadows primitive type '%s'", buf_ptr(tld->name)));
- }
}
}
@@ -4170,48 +4164,6 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
variable_entry->var_type = g->builtin_types.entry_invalid;
} else {
variable_entry->align_bytes = get_abi_alignment(g, var_type);
-
- ZigVar *existing_var = find_variable(g, parent_scope, name, nullptr);
- if (existing_var && !existing_var->shadowable) {
- if (existing_var->var_type == nullptr || !type_is_invalid(existing_var->var_type)) {
- ErrorMsg *msg = add_node_error(g, source_node,
- buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
- add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration here"));
- }
- variable_entry->var_type = g->builtin_types.entry_invalid;
- } else {
- ZigType *type;
- if (get_primitive_type(g, name, &type) != ErrorPrimitiveTypeNotFound) {
- add_node_error(g, source_node,
- buf_sprintf("variable shadows primitive type '%s'", buf_ptr(name)));
- variable_entry->var_type = g->builtin_types.entry_invalid;
- } else {
- Scope *search_scope = nullptr;
- if (src_tld == nullptr) {
- search_scope = parent_scope;
- } else if (src_tld->parent_scope != nullptr && src_tld->parent_scope->parent != nullptr) {
- search_scope = src_tld->parent_scope->parent;
- }
- if (search_scope != nullptr) {
- Tld *tld = find_decl(g, search_scope, name);
- if (tld != nullptr && tld != src_tld) {
- bool want_err_msg = true;
- if (tld->id == TldIdVar) {
- ZigVar *var = reinterpret_cast(tld)->var;
- if (var != nullptr && var->var_type != nullptr && type_is_invalid(var->var_type)) {
- want_err_msg = false;
- }
- }
- if (want_err_msg) {
- ErrorMsg *msg = add_node_error(g, source_node,
- buf_sprintf("redefinition of '%s'", buf_ptr(name)));
- add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition here"));
- }
- variable_entry->var_type = g->builtin_types.entry_invalid;
- }
- }
- }
- }
}
Scope *child_scope;
diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp
index 44dc1080c2..367fd8ac08 100644
--- a/src/stage1/astgen.cpp
+++ b/src/stage1/astgen.cpp
@@ -3194,30 +3194,6 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration here"));
}
variable_entry->var_type = codegen->builtin_types.entry_invalid;
- } else {
- ZigType *type;
- if (get_primitive_type(codegen, name, &type) != ErrorPrimitiveTypeNotFound) {
- add_node_error(codegen, node,
- buf_sprintf("variable shadows primitive type '%s'", buf_ptr(name)));
- variable_entry->var_type = codegen->builtin_types.entry_invalid;
- } else {
- Tld *tld = find_decl(codegen, parent_scope, name);
- if (tld != nullptr) {
- bool want_err_msg = true;
- if (tld->id == TldIdVar) {
- ZigVar *var = reinterpret_cast(tld)->var;
- if (var != nullptr && var->var_type != nullptr && type_is_invalid(var->var_type)) {
- want_err_msg = false;
- }
- }
- if (want_err_msg) {
- ErrorMsg *msg = add_node_error(codegen, node,
- buf_sprintf("redefinition of '%s'", buf_ptr(name)));
- add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition here"));
- }
- variable_entry->var_type = codegen->builtin_types.entry_invalid;
- }
- }
}
}
} else {
@@ -3832,35 +3808,38 @@ static Stage1ZirInst *astgen_identifier(Stage1AstGen *ag, Scope *scope, AstNode
Error err;
assert(node->type == NodeTypeIdentifier);
- Buf *variable_name = node_identifier_buf(node);
+ bool is_at_syntax;
+ Buf *variable_name = node_identifier_buf2(node, &is_at_syntax);
- if (buf_eql_str(variable_name, "_")) {
- if (lval == LValAssign) {
- Stage1ZirInstConst *const_instruction = ir_build_instruction(ag, scope, node);
- const_instruction->value = ag->codegen->pass1_arena->create();
- const_instruction->value->type = get_pointer_to_type(ag->codegen,
- ag->codegen->builtin_types.entry_void, false);
- const_instruction->value->special = ConstValSpecialStatic;
- const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
- return &const_instruction->base;
+ if (!is_at_syntax) {
+ if (buf_eql_str(variable_name, "_")) {
+ if (lval == LValAssign) {
+ Stage1ZirInstConst *const_instruction = ir_build_instruction(ag, scope, node);
+ const_instruction->value = ag->codegen->pass1_arena->create();
+ const_instruction->value->type = get_pointer_to_type(ag->codegen,
+ ag->codegen->builtin_types.entry_void, false);
+ const_instruction->value->special = ConstValSpecialStatic;
+ const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
+ return &const_instruction->base;
+ }
}
- }
- ZigType *primitive_type;
- if ((err = get_primitive_type(ag->codegen, variable_name, &primitive_type))) {
- if (err == ErrorOverflow) {
- add_node_error(ag->codegen, node,
- buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
- buf_ptr(variable_name)));
- return ag->codegen->invalid_inst_src;
- }
- assert(err == ErrorPrimitiveTypeNotFound);
- } else {
- Stage1ZirInst *value = ir_build_const_type(ag, scope, node, primitive_type);
- if (lval == LValPtr || lval == LValAssign) {
- return ir_build_ref_src(ag, scope, node, value);
+ ZigType *primitive_type;
+ if ((err = get_primitive_type(ag->codegen, variable_name, &primitive_type))) {
+ if (err == ErrorOverflow) {
+ add_node_error(ag->codegen, node,
+ buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
+ buf_ptr(variable_name)));
+ return ag->codegen->invalid_inst_src;
+ }
+ assert(err == ErrorPrimitiveTypeNotFound);
} else {
- return ir_expr_wrap(ag, scope, value, result_loc);
+ Stage1ZirInst *value = ir_build_const_type(ag, scope, node, primitive_type);
+ if (lval == LValPtr || lval == LValAssign) {
+ return ir_build_ref_src(ag, scope, node, value);
+ } else {
+ return ir_expr_wrap(ag, scope, value, result_loc);
+ }
}
}
@@ -3875,7 +3854,31 @@ static Stage1ZirInst *astgen_identifier(Stage1AstGen *ag, Scope *scope, AstNode
}
}
- Tld *tld = find_decl(ag->codegen, scope, variable_name);
+ Tld *tld = nullptr;
+ {
+ Scope *s = scope;
+ while (s) {
+ if (s->id == ScopeIdDecls) {
+ ScopeDecls *decls_scope = (ScopeDecls *)s;
+
+ Tld *result = find_container_decl(ag->codegen, decls_scope, variable_name);
+ if (result != nullptr) {
+ if (tld != nullptr && tld != result) {
+ ErrorMsg *msg = add_node_error(ag->codegen, node,
+ buf_sprintf("ambiguous reference"));
+ add_error_note(ag->codegen, msg, tld->source_node,
+ buf_sprintf("declared here"));
+ add_error_note(ag->codegen, msg, result->source_node,
+ buf_sprintf("also declared here"));
+ return ag->codegen->invalid_inst_src;
+ }
+ tld = result;
+ }
+ }
+ s = s->parent;
+ }
+ }
+
if (tld) {
Stage1ZirInst *decl_ref = ir_build_decl_ref(ag, scope, node, tld, lval);
if (lval == LValPtr || lval == LValAssign) {
@@ -4653,17 +4656,17 @@ static Stage1ZirInst *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, Ast
AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
Stage1ZirInst *arg1_value = astgen_node(ag, arg1_node, scope);
- if (arg0_value == ag->codegen->invalid_inst_src)
+ if (arg1_value == ag->codegen->invalid_inst_src)
return arg1_value;
AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
Stage1ZirInst *arg2_value = astgen_node(ag, arg2_node, scope);
- if (arg1_value == ag->codegen->invalid_inst_src)
+ if (arg2_value == ag->codegen->invalid_inst_src)
return arg2_value;
AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
Stage1ZirInst *arg3_value = astgen_node(ag, arg3_node, scope);
- if (arg2_value == ag->codegen->invalid_inst_src)
+ if (arg3_value == ag->codegen->invalid_inst_src)
return arg3_value;
Stage1ZirInst *select = ir_build_select(ag, scope, node,
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp
index b1583cc6b4..830ce76708 100644
--- a/src/stage1/ir.cpp
+++ b/src/stage1/ir.cpp
@@ -20007,29 +20007,24 @@ static Stage1AirInst *ir_analyze_instruction_truncate(IrAnalyze *ira, Stage1ZirI
return ir_build_truncate_gen(ira, instruction->base.scope, instruction->base.source_node, dest_type, target);
}
-static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirInstIntCast *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
- if (type_is_invalid(dest_type))
- return ira->codegen->invalid_inst_gen;
-
+static Stage1AirInst *ir_analyze_int_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
+ ZigType *dest_type, AstNode *dest_type_src_node,
+ Stage1AirInst *target, AstNode *target_src_node)
+{
ZigType *scalar_dest_type = (dest_type->id == ZigTypeIdVector) ?
dest_type->data.vector.elem_type : dest_type;
if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) {
- ir_add_error_node(ira, instruction->dest_type->source_node,
+ ir_add_error_node(ira, dest_type_src_node,
buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name)));
return ira->codegen->invalid_inst_gen;
}
- Stage1AirInst *target = instruction->target->child;
- if (type_is_invalid(target->value->type))
- return ira->codegen->invalid_inst_gen;
-
ZigType *scalar_target_type = (target->value->type->id == ZigTypeIdVector) ?
target->value->type->data.vector.elem_type : target->value->type;
if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) {
- ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected integer type, found '%s'",
+ ir_add_error_node(ira, target_src_node, buf_sprintf("expected integer type, found '%s'",
buf_ptr(&scalar_target_type->name)));
return ira->codegen->invalid_inst_gen;
}
@@ -20039,10 +20034,24 @@ static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirI
if (val == nullptr)
return ira->codegen->invalid_inst_gen;
- return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type);
+ return ir_implicit_cast2(ira, scope, target_src_node, target, dest_type);
}
- return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
+ return ir_analyze_widen_or_shorten(ira, scope, source_node, target, dest_type);
+}
+
+static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirInstIntCast *instruction) {
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
+ if (type_is_invalid(dest_type))
+ return ira->codegen->invalid_inst_gen;
+
+ Stage1AirInst *target = instruction->target->child;
+ if (type_is_invalid(target->value->type))
+ return ira->codegen->invalid_inst_gen;
+
+ return ir_analyze_int_cast(ira, instruction->base.scope, instruction->base.source_node,
+ dest_type, instruction->dest_type->source_node,
+ target, instruction->target->source_node);
}
static Stage1AirInst *ir_analyze_instruction_float_cast(IrAnalyze *ira, Stage1ZirInstFloatCast *instruction) {
@@ -24282,7 +24291,9 @@ static Stage1AirInst *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, Stage1Z
if (type_is_invalid(target->value->type))
return ira->codegen->invalid_inst_gen;
- Stage1AirInst *casted_target = ir_implicit_cast(ira, target, tag_type);
+ Stage1AirInst *casted_target = ir_analyze_int_cast(ira, instruction->base.scope,
+ instruction->base.source_node, tag_type, instruction->dest_type->source_node,
+ target, instruction->target->source_node);
if (type_is_invalid(casted_target->value->type))
return ira->codegen->invalid_inst_gen;
diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp
index 9a429364b1..b06a944172 100644
--- a/src/stage1/parser.cpp
+++ b/src/stage1/parser.cpp
@@ -3482,8 +3482,7 @@ Error source_char_literal(const char *source, uint32_t *result, size_t *bad_inde
}
}
-
-Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
+static Buf *token_identifier_buf2(RootStruct *root_struct, TokenIndex token, bool *is_at_syntax) {
Error err;
const char *source = buf_ptr(root_struct->source_code);
size_t byte_offset = root_struct->token_locs[token].offset;
@@ -3495,6 +3494,7 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
assert(source[byte_offset] != '.'); // wrong token index
if (source[byte_offset] == '@') {
+ *is_at_syntax = true;
size_t bad_index;
Buf *str = buf_alloc();
if ((err = source_string_literal_buf(source + byte_offset + 1, str, &bad_index))) {
@@ -3503,6 +3503,7 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
}
return str;
} else {
+ *is_at_syntax = false;
size_t start = byte_offset;
for (;; byte_offset += 1) {
if (source[byte_offset] == 0) break;
@@ -3519,7 +3520,17 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
}
}
+Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) {
+ bool trash;
+ return token_identifier_buf2(root_struct, token, &trash);
+}
+
Buf *node_identifier_buf(AstNode *node) {
+ bool trash;
+ return node_identifier_buf2(node, &trash);
+}
+
+Buf *node_identifier_buf2(AstNode *node, bool *is_at_syntax) {
assert(node->type == NodeTypeIdentifier);
// Currently, stage1 runs astgen for every comptime function call,
// resulting the allocation here wasting memory. As a workaround until
@@ -3527,8 +3538,10 @@ Buf *node_identifier_buf(AstNode *node) {
// we memoize the result into the AST here.
if (node->data.identifier.name == nullptr) {
RootStruct *root_struct = node->owner->data.structure.root_struct;
- node->data.identifier.name = token_identifier_buf(root_struct, node->main_token);
+ node->data.identifier.name = token_identifier_buf2(root_struct, node->main_token,
+ &node->data.identifier.is_at_syntax);
}
+ *is_at_syntax = node->data.identifier.is_at_syntax;
return node->data.identifier.name;
}
diff --git a/src/stage1/parser.hpp b/src/stage1/parser.hpp
index 9f73444cb8..8ac8ce6de1 100644
--- a/src/stage1/parser.hpp
+++ b/src/stage1/parser.hpp
@@ -19,6 +19,7 @@ void ast_print(AstNode *node, int indent);
void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *context), void *context);
Buf *node_identifier_buf(AstNode *node);
+Buf *node_identifier_buf2(AstNode *node, bool *is_at_syntax);
Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token);
diff --git a/src/stage1/target.cpp b/src/stage1/target.cpp
index 9c95be3d5a..85ea2f1d3d 100644
--- a/src/stage1/target.cpp
+++ b/src/stage1/target.cpp
@@ -925,7 +925,7 @@ bool target_has_valgrind_support(const ZigTarget *target) {
case ZigLLVM_UnknownArch:
zig_unreachable();
case ZigLLVM_x86_64:
- return (target->os == OsLinux || target_os_is_darwin(target->os) || target->os == OsSolaris ||
+ return (target->os == OsLinux || target->os == OsSolaris ||
(target->os == OsWindows && target->abi != ZigLLVM_MSVC));
default:
return false;
diff --git a/src/target.zig b/src/target.zig
index 0958f1d00f..6f50c8d5e9 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -166,7 +166,7 @@ pub fn isSingleThreaded(target: std.Target) bool {
pub fn hasValgrindSupport(target: std.Target) bool {
switch (target.cpu.arch) {
.x86_64 => {
- return target.os.tag == .linux or target.isDarwin() or target.os.tag == .solaris or
+ return target.os.tag == .linux or target.os.tag == .solaris or
(target.os.tag == .windows and target.abi != .msvc);
},
else => return false,
diff --git a/src/translate_c.zig b/src/translate_c.zig
index e11fc5b736..0cc40cdfd4 100644
--- a/src/translate_c.zig
+++ b/src/translate_c.zig
@@ -719,6 +719,30 @@ fn transQualTypeMaybeInitialized(c: *Context, scope: *Scope, qt: clang.QualType,
transQualType(c, scope, qt, loc);
}
+/// This is used in global scope to convert a string literal `S` to [*c]u8:
+/// &(struct {
+/// var static = S.*;
+/// }).static;
+fn stringLiteralToCharStar(c: *Context, str: Node) Error!Node {
+ const var_name = Scope.Block.StaticInnerName;
+
+ const variables = try c.arena.alloc(Node, 1);
+ variables[0] = try Tag.mut_str.create(c.arena, .{ .name = var_name, .init = str });
+
+ const anon_struct = try Tag.@"struct".create(c.arena, .{
+ .layout = .none,
+ .fields = &.{},
+ .functions = &.{},
+ .variables = variables,
+ });
+
+ const member_access = try Tag.field_access.create(c.arena, .{
+ .lhs = anon_struct,
+ .field_name = var_name,
+ });
+ return Tag.address_of.create(c.arena, member_access);
+}
+
/// if mangled_name is not null, this var decl was declared in a block scope.
fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]const u8) Error!void {
const var_name = mangled_name orelse try c.str(@ptrCast(*const clang.NamedDecl, var_decl).getName_bytes_begin());
@@ -779,6 +803,8 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
};
if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node.?)) {
init_node = try Tag.bool_to_int.create(c.arena, init_node.?);
+ } else if (init_node.?.tag() == .string_literal and qualTypeIsCharStar(qual_type)) {
+ init_node = try stringLiteralToCharStar(c, init_node.?);
}
} else {
init_node = Tag.undefined_literal.init();
@@ -1101,9 +1127,10 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
record_payload.* = .{
.base = .{ .tag = ([2]Tag{ .@"struct", .@"union" })[@boolToInt(is_union)] },
.data = .{
- .is_packed = is_packed,
+ .layout = if (is_packed) .@"packed" else .@"extern",
.fields = try c.arena.dupe(ast.Payload.Record.Field, fields.items),
.functions = try c.arena.dupe(Node, functions.items),
+ .variables = &.{},
},
};
break :blk Node.initPayload(&record_payload.base);
@@ -1805,6 +1832,9 @@ fn transDeclStmtOne(
Tag.undefined_literal.init();
if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node)) {
init_node = try Tag.bool_to_int.create(c.arena, init_node);
+ } else if (init_node.tag() == .string_literal and qualTypeIsCharStar(qual_type)) {
+ const dst_type_node = try transQualType(c, scope, qual_type, loc);
+ init_node = try removeCVQualifiers(c, dst_type_node, init_node);
}
const var_name: []const u8 = if (is_static_local) Scope.Block.StaticInnerName else mangled_name;
@@ -2522,9 +2552,19 @@ fn transInitListExprRecord(
raw_name = try mem.dupe(c.arena, u8, name);
}
+ var init_expr = try transExpr(c, scope, elem_expr, .used);
+ const field_qt = field_decl.getType();
+ if (init_expr.tag() == .string_literal and qualTypeIsCharStar(field_qt)) {
+ if (scope.id == .root) {
+ init_expr = try stringLiteralToCharStar(c, init_expr);
+ } else {
+ const dst_type_node = try transQualType(c, scope, field_qt, loc);
+ init_expr = try removeCVQualifiers(c, dst_type_node, init_expr);
+ }
+ }
try field_inits.append(.{
.name = raw_name,
- .value = try transExpr(c, scope, elem_expr, .used),
+ .value = init_expr,
});
}
if (ty_node.castTag(.identifier)) |ident_node| {
@@ -3459,6 +3499,10 @@ fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result
const param_qt = fn_proto.getParamType(@intCast(c_uint, i));
if (isBoolRes(arg) and cIsNativeInt(param_qt)) {
arg = try Tag.bool_to_int.create(c.arena, arg);
+ } else if (arg.tag() == .string_literal and qualTypeIsCharStar(param_qt)) {
+ const loc = @ptrCast(*const clang.Stmt, stmt).getBeginLoc();
+ const dst_type_node = try transQualType(c, scope, param_qt, loc);
+ arg = try removeCVQualifiers(c, dst_type_node, arg);
}
}
},
@@ -3835,6 +3879,12 @@ fn transCreateCompoundAssign(
return block_scope.complete(c);
}
+// Casting away const or volatile requires us to use @intToPtr
+fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node {
+ const ptr_to_int = try Tag.ptr_to_int.create(c.arena, expr);
+ return Tag.int_to_ptr.create(c.arena, .{ .lhs = dst_type_node, .rhs = ptr_to_int });
+}
+
fn transCPtrCast(
c: *Context,
scope: *Scope,
@@ -3854,10 +3904,7 @@ fn transCPtrCast(
(src_child_type.isVolatileQualified() and
!child_type.isVolatileQualified())))
{
- // Casting away const or volatile requires us to use @intToPtr
- const ptr_to_int = try Tag.ptr_to_int.create(c.arena, expr);
- const int_to_ptr = try Tag.int_to_ptr.create(c.arena, .{ .lhs = dst_type_node, .rhs = ptr_to_int });
- return int_to_ptr;
+ return removeCVQualifiers(c, dst_type_node, expr);
} else {
// Implicit downcasting from higher to lower alignment values is forbidden,
// use @alignCast to side-step this problem
@@ -4217,6 +4264,26 @@ fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) b
}
}
+/// plain `char *` (not const; not explicitly signed or unsigned)
+fn qualTypeIsCharStar(qt: clang.QualType) bool {
+ if (qualTypeIsPtr(qt)) {
+ const child_qt = qualTypeCanon(qt).getPointeeType();
+ return cIsUnqualifiedChar(child_qt) and !child_qt.isConstQualified();
+ }
+ return false;
+}
+
+/// C `char` without explicit signed or unsigned qualifier
+fn cIsUnqualifiedChar(qt: clang.QualType) bool {
+ const c_type = qualTypeCanon(qt);
+ if (c_type.getTypeClass() != .Builtin) return false;
+ const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
+ return switch (builtin_ty.getKind()) {
+ .Char_S, .Char_U => true,
+ else => false,
+ };
+}
+
fn cIsInteger(qt: clang.QualType) bool {
return cIsSignedInteger(qt) or cIsUnsignedInteger(qt);
}
diff --git a/src/translate_c/ast.zig b/src/translate_c/ast.zig
index fa6b749589..1058936191 100644
--- a/src/translate_c/ast.zig
+++ b/src/translate_c/ast.zig
@@ -62,6 +62,8 @@ pub const Node = extern union {
var_decl,
/// const name = struct { init }
static_local_var,
+ /// var name = init.*
+ mut_str,
func,
warning,
@"struct",
@@ -361,7 +363,7 @@ pub const Node = extern union {
.array_type, .null_sentinel_array_type => Payload.Array,
.arg_redecl, .alias, .fail_decl => Payload.ArgRedecl,
.log2_int_type => Payload.Log2IntType,
- .var_simple, .pub_var_simple, .static_local_var => Payload.SimpleVarDecl,
+ .var_simple, .pub_var_simple, .static_local_var, .mut_str => Payload.SimpleVarDecl,
.enum_constant => Payload.EnumConstant,
.array_filler => Payload.ArrayFiller,
.pub_inline_fn => Payload.PubInlineFn,
@@ -558,9 +560,10 @@ pub const Payload = struct {
pub const Record = struct {
base: Payload,
data: struct {
- is_packed: bool,
+ layout: enum { @"packed", @"extern", none },
fields: []Field,
functions: []Node,
+ variables: []Node,
},
pub const Field = struct {
@@ -925,23 +928,23 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
return renderCall(c, lhs, payload.args);
},
.null_literal => return c.addNode(.{
- .tag = .null_literal,
- .main_token = try c.addToken(.keyword_null, "null"),
+ .tag = .identifier,
+ .main_token = try c.addToken(.identifier, "null"),
.data = undefined,
}),
.undefined_literal => return c.addNode(.{
- .tag = .undefined_literal,
- .main_token = try c.addToken(.keyword_undefined, "undefined"),
+ .tag = .identifier,
+ .main_token = try c.addToken(.identifier, "undefined"),
.data = undefined,
}),
.true_literal => return c.addNode(.{
- .tag = .true_literal,
- .main_token = try c.addToken(.keyword_true, "true"),
+ .tag = .identifier,
+ .main_token = try c.addToken(.identifier, "true"),
.data = undefined,
}),
.false_literal => return c.addNode(.{
- .tag = .false_literal,
- .main_token = try c.addToken(.keyword_false, "false"),
+ .tag = .identifier,
+ .main_token = try c.addToken(.identifier, "false"),
.data = undefined,
}),
.zero_literal => return c.addNode(.{
@@ -1229,6 +1232,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
},
});
_ = try c.addToken(.r_brace, "}");
+ _ = try c.addToken(.semicolon, ";");
return c.addNode(.{
.tag = .simple_var_decl,
@@ -1239,6 +1243,29 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
},
});
},
+ .mut_str => {
+ const payload = node.castTag(.mut_str).?.data;
+
+ const var_tok = try c.addToken(.keyword_var, "var");
+ _ = try c.addIdentifier(payload.name);
+ _ = try c.addToken(.equal, "=");
+
+ const deref = try c.addNode(.{
+ .tag = .deref,
+ .data = .{
+ .lhs = try renderNodeGrouped(c, payload.init),
+ .rhs = undefined,
+ },
+ .main_token = try c.addToken(.period_asterisk, ".*"),
+ });
+ _ = try c.addToken(.semicolon, ";");
+
+ return c.addNode(.{
+ .tag = .simple_var_decl,
+ .main_token = var_tok,
+ .data = .{ .lhs = 0, .rhs = deref },
+ });
+ },
.var_decl => return renderVar(c, node),
.arg_redecl, .alias => {
const payload = @fieldParentPtr(Payload.ArgRedecl, "base", node.ptr_otherwise).data;
@@ -1572,8 +1599,8 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
const while_tok = try c.addToken(.keyword_while, "while");
_ = try c.addToken(.l_paren, "(");
const cond = try c.addNode(.{
- .tag = .true_literal,
- .main_token = try c.addToken(.keyword_true, "true"),
+ .tag = .identifier,
+ .main_token = try c.addToken(.identifier, "true"),
.data = undefined,
});
_ = try c.addToken(.r_paren, ")");
@@ -1952,9 +1979,9 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
fn renderRecord(c: *Context, node: Node) !NodeIndex {
const payload = @fieldParentPtr(Payload.Record, "base", node.ptr_otherwise).data;
- if (payload.is_packed)
+ if (payload.layout == .@"packed")
_ = try c.addToken(.keyword_packed, "packed")
- else
+ else if (payload.layout == .@"extern")
_ = try c.addToken(.keyword_extern, "extern");
const kind_tok = if (node.tag() == .@"struct")
try c.addToken(.keyword_struct, "struct")
@@ -1963,8 +1990,9 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex {
_ = try c.addToken(.l_brace, "{");
+ const num_vars = payload.variables.len;
const num_funcs = payload.functions.len;
- const total_members = payload.fields.len + num_funcs;
+ const total_members = payload.fields.len + num_vars + num_funcs;
const members = try c.gpa.alloc(NodeIndex, std.math.max(total_members, 2));
defer c.gpa.free(members);
members[0] = 0;
@@ -2006,8 +2034,11 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex {
});
_ = try c.addToken(.comma, ",");
}
+ for (payload.variables) |variable, i| {
+ members[payload.fields.len + i] = try renderNode(c, variable);
+ }
for (payload.functions) |function, i| {
- members[payload.fields.len + i] = try renderNode(c, function);
+ members[payload.fields.len + num_vars + i] = try renderNode(c, function);
}
_ = try c.addToken(.r_brace, "}");
@@ -2140,7 +2171,7 @@ fn renderNullSentinelArrayType(c: *Context, len: usize, elem_type: Node) !NodeIn
fn addSemicolonIfNeeded(c: *Context, node: Node) !void {
switch (node.tag()) {
.warning => unreachable,
- .var_decl, .var_simple, .arg_redecl, .alias, .block, .empty_block, .block_single, .@"switch" => {},
+ .var_decl, .var_simple, .arg_redecl, .alias, .block, .empty_block, .block_single, .@"switch", .static_local_var, .mut_str => {},
.while_true => {
const payload = node.castTag(.while_true).?.data;
return addSemicolonIfNotBlock(c, payload);
@@ -2235,6 +2266,7 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
.offset_of,
.shuffle,
.static_local_var,
+ .mut_str,
=> {
// no grouping needed
return renderNode(c, node);
diff --git a/src/type.zig b/src/type.zig
index 41f392c04a..467e9c931b 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -133,6 +133,7 @@ pub const Type = extern union {
.@"union",
.union_tagged,
+ .type_info,
=> return .Union,
.var_args_param => unreachable, // can be any type
@@ -248,6 +249,30 @@ pub const Type = extern union {
};
}
+ pub fn ptrIsMutable(ty: Type) bool {
+ return switch (ty.tag()) {
+ .single_const_pointer_to_comptime_int,
+ .const_slice_u8,
+ .single_const_pointer,
+ .many_const_pointer,
+ .manyptr_const_u8,
+ .c_const_pointer,
+ .const_slice,
+ => false,
+
+ .single_mut_pointer,
+ .many_mut_pointer,
+ .manyptr_u8,
+ .c_mut_pointer,
+ .mut_slice,
+ => true,
+
+ .pointer => ty.castTag(.pointer).?.data.mutable,
+
+ else => unreachable,
+ };
+ }
+
pub fn ptrInfo(self: Type) Payload.Pointer {
switch (self.tag()) {
.single_const_pointer_to_comptime_int => return .{ .data = .{
@@ -717,6 +742,7 @@ pub const Type = extern union {
.call_options,
.export_options,
.extern_options,
+ .type_info,
.@"anyframe",
.generic_poison,
=> unreachable,
@@ -928,6 +954,7 @@ pub const Type = extern union {
.call_options => return writer.writeAll("std.builtin.CallOptions"),
.export_options => return writer.writeAll("std.builtin.ExportOptions"),
.extern_options => return writer.writeAll("std.builtin.ExternOptions"),
+ .type_info => return writer.writeAll("std.builtin.TypeInfo"),
.function => {
const payload = ty.castTag(.function).?.data;
try writer.writeAll("fn(");
@@ -1178,6 +1205,7 @@ pub const Type = extern union {
.comptime_int,
.comptime_float,
.enum_literal,
+ .type_info,
=> true,
.var_args_param => unreachable,
@@ -1269,6 +1297,7 @@ pub const Type = extern union {
.call_options => return Value.initTag(.call_options_type),
.export_options => return Value.initTag(.export_options_type),
.extern_options => return Value.initTag(.extern_options_type),
+ .type_info => return Value.initTag(.type_info_type),
.inferred_alloc_const => unreachable,
.inferred_alloc_mut => unreachable,
else => return Value.Tag.ty.create(allocator, self),
@@ -1409,6 +1438,7 @@ pub const Type = extern union {
.empty_struct,
.empty_struct_literal,
.@"opaque",
+ .type_info,
=> false,
.inferred_alloc_const => unreachable,
@@ -1636,6 +1666,7 @@ pub const Type = extern union {
.inferred_alloc_mut,
.@"opaque",
.var_args_param,
+ .type_info,
=> unreachable,
.generic_poison => unreachable,
@@ -1667,6 +1698,7 @@ pub const Type = extern union {
.@"opaque" => unreachable,
.var_args_param => unreachable,
.generic_poison => unreachable,
+ .type_info => unreachable,
.@"struct" => {
const s = self.castTag(.@"struct").?.data;
@@ -1978,6 +2010,7 @@ pub const Type = extern union {
.call_options,
.export_options,
.extern_options,
+ .type_info,
=> @panic("TODO at some point we gotta resolve builtin types"),
};
}
@@ -2691,6 +2724,7 @@ pub const Type = extern union {
.call_options,
.export_options,
.extern_options,
+ .type_info,
.@"anyframe",
.anyframe_T,
.many_const_pointer,
@@ -2778,6 +2812,7 @@ pub const Type = extern union {
return switch (self.tag()) {
.@"struct" => &self.castTag(.@"struct").?.data.namespace,
.enum_full => &self.castTag(.enum_full).?.data.namespace,
+ .enum_nonexhaustive => &self.castTag(.enum_nonexhaustive).?.data.namespace,
.empty_struct => self.castTag(.empty_struct).?.data,
.@"opaque" => &self.castTag(.@"opaque").?.data,
.@"union" => &self.castTag(.@"union").?.data.namespace,
@@ -3022,6 +3057,7 @@ pub const Type = extern union {
.call_options,
.export_options,
.extern_options,
+ .type_info,
=> @panic("TODO resolve std.builtin types"),
else => unreachable,
}
@@ -3058,6 +3094,7 @@ pub const Type = extern union {
.call_options,
.export_options,
.extern_options,
+ .type_info,
=> @panic("TODO resolve std.builtin types"),
else => unreachable,
}
@@ -3167,6 +3204,7 @@ pub const Type = extern union {
call_options,
export_options,
extern_options,
+ type_info,
manyptr_u8,
manyptr_const_u8,
fn_noreturn_no_args,
@@ -3289,6 +3327,7 @@ pub const Type = extern union {
.call_options,
.export_options,
.extern_options,
+ .type_info,
.@"anyframe",
=> @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),
diff --git a/src/value.zig b/src/value.zig
index 562d7171e8..5ac9f142c4 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -68,6 +68,7 @@ pub const Value = extern union {
call_options_type,
export_options_type,
extern_options_type,
+ type_info_type,
manyptr_u8_type,
manyptr_const_u8_type,
fn_noreturn_no_args_type,
@@ -132,12 +133,21 @@ pub const Value = extern union {
/// When the type is error union:
/// * If the tag is `.@"error"`, the error union is an error.
/// * If the tag is `.eu_payload`, the error union is a payload.
- /// * A nested error such as `((anyerror!T1)!T2)` in which the the outer error union
+ /// * A nested error such as `anyerror!(anyerror!T)` in which the the outer error union
/// is non-error, but the inner error union is an error, is represented as
/// a tag of `.eu_payload`, with a sub-tag of `.@"error"`.
eu_payload,
/// A pointer to the payload of an error union, based on a pointer to an error union.
eu_payload_ptr,
+ /// When the type is optional:
+ /// * If the tag is `.null_value`, the optional is null.
+ /// * If the tag is `.opt_payload`, the optional is a payload.
+ /// * A nested optional such as `??T` in which the the outer optional
+ /// is non-null, but the inner optional is null, is represented as
+ /// a tag of `.opt_payload`, with a sub-tag of `.null_value`.
+ opt_payload,
+ /// A pointer to the payload of an optional, based on a pointer to an optional.
+ opt_payload_ptr,
/// An instance of a struct.
@"struct",
/// An instance of a union.
@@ -221,6 +231,7 @@ pub const Value = extern union {
.call_options_type,
.export_options_type,
.extern_options_type,
+ .type_info_type,
.generic_poison,
=> @compileError("Value Tag " ++ @tagName(t) ++ " has no payload"),
@@ -236,6 +247,8 @@ pub const Value = extern union {
.repeated,
.eu_payload,
.eu_payload_ptr,
+ .opt_payload,
+ .opt_payload_ptr,
=> Payload.SubValue,
.bytes,
@@ -402,6 +415,7 @@ pub const Value = extern union {
.call_options_type,
.export_options_type,
.extern_options_type,
+ .type_info_type,
.generic_poison,
=> unreachable,
@@ -456,7 +470,12 @@ pub const Value = extern union {
return Value{ .ptr_otherwise = &new_payload.base };
},
.bytes => return self.copyPayloadShallow(allocator, Payload.Bytes),
- .repeated, .eu_payload, .eu_payload_ptr => {
+ .repeated,
+ .eu_payload,
+ .eu_payload_ptr,
+ .opt_payload,
+ .opt_payload_ptr,
+ => {
const payload = self.cast(Payload.SubValue).?;
const new_payload = try allocator.create(Payload.SubValue);
new_payload.* = .{
@@ -585,6 +604,7 @@ pub const Value = extern union {
.call_options_type => return out_stream.writeAll("std.builtin.CallOptions"),
.export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"),
.extern_options_type => return out_stream.writeAll("std.builtin.ExternOptions"),
+ .type_info_type => return out_stream.writeAll("std.builtin.TypeInfo"),
.abi_align_default => return out_stream.writeAll("(default ABI alignment)"),
.empty_struct_value => return out_stream.writeAll("struct {}{}"),
@@ -652,12 +672,20 @@ pub const Value = extern union {
try out_stream.writeAll("(eu_payload) ");
val = val.castTag(.eu_payload).?.data;
},
+ .opt_payload => {
+ try out_stream.writeAll("(opt_payload) ");
+ val = val.castTag(.opt_payload).?.data;
+ },
.inferred_alloc => return out_stream.writeAll("(inferred allocation value)"),
.inferred_alloc_comptime => return out_stream.writeAll("(inferred comptime allocation value)"),
.eu_payload_ptr => {
try out_stream.writeAll("(eu_payload_ptr)");
val = val.castTag(.eu_payload_ptr).?.data;
},
+ .opt_payload_ptr => {
+ try out_stream.writeAll("(opt_payload_ptr)");
+ val = val.castTag(.opt_payload_ptr).?.data;
+ },
};
}
@@ -743,6 +771,7 @@ pub const Value = extern union {
.call_options_type => Type.initTag(.call_options),
.export_options_type => Type.initTag(.export_options),
.extern_options_type => Type.initTag(.extern_options),
+ .type_info_type => Type.initTag(.type_info),
.int_type => {
const payload = self.castTag(.int_type).?.data;
@@ -771,6 +800,38 @@ pub const Value = extern union {
}
}
+ pub fn enumToInt(val: Value, ty: Type, buffer: *Payload.U64) Value {
+ if (val.castTag(.enum_field_index)) |enum_field_payload| {
+ const field_index = enum_field_payload.data;
+ switch (ty.tag()) {
+ .enum_full, .enum_nonexhaustive => {
+ const enum_full = ty.cast(Type.Payload.EnumFull).?.data;
+ if (enum_full.values.count() != 0) {
+ return enum_full.values.keys()[field_index];
+ } else {
+ // Field index and integer values are the same.
+ buffer.* = .{
+ .base = .{ .tag = .int_u64 },
+ .data = field_index,
+ };
+ return Value.initPayload(&buffer.base);
+ }
+ },
+ .enum_simple => {
+ // Field index and integer values are the same.
+ buffer.* = .{
+ .base = .{ .tag = .int_u64 },
+ .data = field_index,
+ };
+ return Value.initPayload(&buffer.base);
+ },
+ else => unreachable,
+ }
+ }
+ // Assume it is already an integer and return it directly.
+ return val;
+ }
+
/// Asserts the value is an integer.
pub fn toBigInt(self: Value, space: *BigIntSpace) BigIntConst {
switch (self.tag()) {
@@ -1127,7 +1188,10 @@ pub const Value = extern union {
}
pub fn hash(val: Value, ty: Type, hasher: *std.hash.Wyhash) void {
- switch (ty.zigTypeTag()) {
+ const zig_ty_tag = ty.zigTypeTag();
+ std.hash.autoHash(hasher, zig_ty_tag);
+
+ switch (zig_ty_tag) {
.BoundFn => unreachable, // TODO remove this from the language
.Void,
@@ -1152,7 +1216,10 @@ pub const Value = extern union {
}
},
.Float, .ComptimeFloat => {
- @panic("TODO implement hashing float values");
+ // TODO double check the lang spec. should we to bitwise hashing here,
+ // or a hash that normalizes the float value?
+ const float = val.toFloat(f128);
+ std.hash.autoHash(hasher, @bitCast(u128, float));
},
.Pointer => {
@panic("TODO implement hashing pointer values");
@@ -1164,7 +1231,15 @@ pub const Value = extern union {
@panic("TODO implement hashing struct values");
},
.Optional => {
- @panic("TODO implement hashing optional values");
+ if (val.castTag(.opt_payload)) |payload| {
+ std.hash.autoHash(hasher, true); // non-null
+ const sub_val = payload.data;
+ var buffer: Type.Payload.ElemType = undefined;
+ const sub_ty = ty.optionalChild(&buffer);
+ sub_val.hash(sub_ty, hasher);
+ } else {
+ std.hash.autoHash(hasher, false); // non-null
+ }
},
.ErrorUnion => {
@panic("TODO implement hashing error union values");
@@ -1173,7 +1248,16 @@ pub const Value = extern union {
@panic("TODO implement hashing error set values");
},
.Enum => {
- @panic("TODO implement hashing enum values");
+ var enum_space: Payload.U64 = undefined;
+ const int_val = val.enumToInt(ty, &enum_space);
+
+ var space: BigIntSpace = undefined;
+ const big = int_val.toBigInt(&space);
+
+ std.hash.autoHash(hasher, big.positive);
+ for (big.limbs) |limb| {
+ std.hash.autoHash(hasher, limb);
+ }
},
.Union => {
@panic("TODO implement hashing union values");
@@ -1252,6 +1336,11 @@ pub const Value = extern union {
const err_union_val = (try err_union_ptr.pointerDeref(allocator)) orelse return null;
break :blk err_union_val.castTag(.eu_payload).?.data;
},
+ .opt_payload_ptr => blk: {
+ const opt_ptr = self.castTag(.opt_payload_ptr).?.data;
+ const opt_val = (try opt_ptr.pointerDeref(allocator)) orelse return null;
+ break :blk opt_val.castTag(.opt_payload).?.data;
+ },
.zero,
.one,
@@ -1349,13 +1438,14 @@ pub const Value = extern union {
/// Valid for all types. Asserts the value is not undefined and not unreachable.
pub fn isNull(self: Value) bool {
return switch (self.tag()) {
+ .null_value => true,
+ .opt_payload => false,
+
.undef => unreachable,
.unreachable_value => unreachable,
.inferred_alloc => unreachable,
.inferred_alloc_comptime => unreachable,
- .null_value => true,
-
- else => false,
+ else => unreachable,
};
}
@@ -1385,6 +1475,10 @@ pub const Value = extern union {
return switch (val.tag()) {
.eu_payload => true,
else => false,
+
+ .undef => unreachable,
+ .inferred_alloc => unreachable,
+ .inferred_alloc_comptime => unreachable,
};
}
@@ -1514,6 +1608,31 @@ pub const Value = extern union {
return Tag.int_u64.create(arena, truncated);
}
+ pub fn shr(lhs: Value, rhs: Value, allocator: *Allocator) !Value {
+ // TODO is this a performance issue? maybe we should try the operation without
+ // resorting to BigInt first.
+ var lhs_space: Value.BigIntSpace = undefined;
+ const lhs_bigint = lhs.toBigInt(&lhs_space);
+ const shift = rhs.toUnsignedInt();
+ const limbs = try allocator.alloc(
+ std.math.big.Limb,
+ lhs_bigint.limbs.len - (shift / (@sizeOf(std.math.big.Limb) * 8)),
+ );
+ var result_bigint = BigIntMutable{
+ .limbs = limbs,
+ .positive = undefined,
+ .len = undefined,
+ };
+ result_bigint.shiftRight(lhs_bigint, shift);
+ const result_limbs = result_bigint.limbs[0..result_bigint.len];
+
+ if (result_bigint.positive) {
+ return Value.Tag.int_big_positive.create(allocator, result_limbs);
+ } else {
+ return Value.Tag.int_big_negative.create(allocator, result_limbs);
+ }
+ }
+
pub fn floatAdd(
lhs: Value,
rhs: Value,
diff --git a/test/behavior.zig b/test/behavior.zig
index bb55ec83f1..7836380c13 100644
--- a/test/behavior.zig
+++ b/test/behavior.zig
@@ -9,12 +9,13 @@ test {
_ = @import("behavior/pointers.zig");
_ = @import("behavior/if.zig");
_ = @import("behavior/cast.zig");
+ _ = @import("behavior/array.zig");
if (!builtin.zig_is_stage2) {
// Tests that only pass for stage1.
_ = @import("behavior/align.zig");
_ = @import("behavior/alignof.zig");
- _ = @import("behavior/array.zig");
+ _ = @import("behavior/array_stage1.zig");
if (builtin.os.tag != .wasi) {
_ = @import("behavior/asm.zig");
_ = @import("behavior/async_fn.zig");
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index 84a2cdb36c..232ba87f55 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -3,487 +3,3 @@ const testing = std.testing;
const mem = std.mem;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
-
-test "arrays" {
- var array: [5]u32 = undefined;
-
- var i: u32 = 0;
- while (i < 5) {
- array[i] = i + 1;
- i = array[i];
- }
-
- i = 0;
- var accumulator = @as(u32, 0);
- while (i < 5) {
- accumulator += array[i];
-
- i += 1;
- }
-
- try expect(accumulator == 15);
- try expect(getArrayLen(&array) == 5);
-}
-fn getArrayLen(a: []const u32) usize {
- return a.len;
-}
-
-test "array with sentinels" {
- const S = struct {
- fn doTheTest(is_ct: bool) !void {
- if (is_ct) {
- var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
- // Disabled at runtime because of
- // https://github.com/ziglang/zig/issues/4372
- try expectEqual(@as(u8, 0xde), zero_sized[0]);
- var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
- try expectEqual(@as(u8, 0xde), reinterpreted[0]);
- }
- var arr: [3:0x55]u8 = undefined;
- // Make sure the sentinel pointer is pointing after the last element
- if (!is_ct) {
- const sentinel_ptr = @ptrToInt(&arr[3]);
- const last_elem_ptr = @ptrToInt(&arr[2]);
- try expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
- }
- // Make sure the sentinel is writeable
- arr[3] = 0x55;
- }
- };
-
- try S.doTheTest(false);
- comptime try S.doTheTest(true);
-}
-
-test "void arrays" {
- var array: [4]void = undefined;
- array[0] = void{};
- array[1] = array[2];
- try expect(@sizeOf(@TypeOf(array)) == 0);
- try expect(array.len == 4);
-}
-
-test "array literal" {
- const hex_mult = [_]u16{
- 4096,
- 256,
- 16,
- 1,
- };
-
- try expect(hex_mult.len == 4);
- try expect(hex_mult[1] == 256);
-}
-
-test "array dot len const expr" {
- try expect(comptime x: {
- break :x some_array.len == 4;
- });
-}
-
-const ArrayDotLenConstExpr = struct {
- y: [some_array.len]u8,
-};
-const some_array = [_]u8{
- 0,
- 1,
- 2,
- 3,
-};
-
-test "nested arrays" {
- const array_of_strings = [_][]const u8{
- "hello",
- "this",
- "is",
- "my",
- "thing",
- };
- for (array_of_strings) |s, i| {
- if (i == 0) try expect(mem.eql(u8, s, "hello"));
- if (i == 1) try expect(mem.eql(u8, s, "this"));
- if (i == 2) try expect(mem.eql(u8, s, "is"));
- if (i == 3) try expect(mem.eql(u8, s, "my"));
- if (i == 4) try expect(mem.eql(u8, s, "thing"));
- }
-}
-
-var s_array: [8]Sub = undefined;
-const Sub = struct {
- b: u8,
-};
-const Str = struct {
- a: []Sub,
-};
-test "set global var array via slice embedded in struct" {
- var s = Str{ .a = s_array[0..] };
-
- s.a[0].b = 1;
- s.a[1].b = 2;
- s.a[2].b = 3;
-
- try expect(s_array[0].b == 1);
- try expect(s_array[1].b == 2);
- try expect(s_array[2].b == 3);
-}
-
-test "array literal with specified size" {
- var array = [2]u8{
- 1,
- 2,
- };
- try expect(array[0] == 1);
- try expect(array[1] == 2);
-}
-
-test "array len field" {
- var arr = [4]u8{ 0, 0, 0, 0 };
- var ptr = &arr;
- try expect(arr.len == 4);
- comptime try expect(arr.len == 4);
- try expect(ptr.len == 4);
- comptime try expect(ptr.len == 4);
-}
-
-test "single-item pointer to array indexing and slicing" {
- try testSingleItemPtrArrayIndexSlice();
- comptime try testSingleItemPtrArrayIndexSlice();
-}
-
-fn testSingleItemPtrArrayIndexSlice() !void {
- {
- var array: [4]u8 = "aaaa".*;
- doSomeMangling(&array);
- try expect(mem.eql(u8, "azya", &array));
- }
- {
- var array = "aaaa".*;
- doSomeMangling(&array);
- try expect(mem.eql(u8, "azya", &array));
- }
-}
-
-fn doSomeMangling(array: *[4]u8) void {
- array[1] = 'z';
- array[2..3][0] = 'y';
-}
-
-test "implicit cast single-item pointer" {
- try testImplicitCastSingleItemPtr();
- comptime try testImplicitCastSingleItemPtr();
-}
-
-fn testImplicitCastSingleItemPtr() !void {
- var byte: u8 = 100;
- const slice = @as(*[1]u8, &byte)[0..];
- slice[0] += 1;
- try expect(byte == 101);
-}
-
-fn testArrayByValAtComptime(b: [2]u8) u8 {
- return b[0];
-}
-
-test "comptime evalutating function that takes array by value" {
- const arr = [_]u8{ 0, 1 };
- _ = comptime testArrayByValAtComptime(arr);
- _ = comptime testArrayByValAtComptime(arr);
-}
-
-test "implicit comptime in array type size" {
- var arr: [plusOne(10)]bool = undefined;
- try expect(arr.len == 11);
-}
-
-fn plusOne(x: u32) u32 {
- return x + 1;
-}
-
-test "runtime initialize array elem and then implicit cast to slice" {
- var two: i32 = 2;
- const x: []const i32 = &[_]i32{two};
- try expect(x[0] == 2);
-}
-
-test "array literal as argument to function" {
- const S = struct {
- fn entry(two: i32) !void {
- try foo(&[_]i32{
- 1,
- 2,
- 3,
- });
- try foo(&[_]i32{
- 1,
- two,
- 3,
- });
- try foo2(true, &[_]i32{
- 1,
- 2,
- 3,
- });
- try foo2(true, &[_]i32{
- 1,
- two,
- 3,
- });
- }
- fn foo(x: []const i32) !void {
- try expect(x[0] == 1);
- try expect(x[1] == 2);
- try expect(x[2] == 3);
- }
- fn foo2(trash: bool, x: []const i32) !void {
- try expect(trash);
- try expect(x[0] == 1);
- try expect(x[1] == 2);
- try expect(x[2] == 3);
- }
- };
- try S.entry(2);
- comptime try S.entry(2);
-}
-
-test "double nested array to const slice cast in array literal" {
- const S = struct {
- fn entry(two: i32) !void {
- const cases = [_][]const []const i32{
- &[_][]const i32{&[_]i32{1}},
- &[_][]const i32{&[_]i32{ 2, 3 }},
- &[_][]const i32{
- &[_]i32{4},
- &[_]i32{ 5, 6, 7 },
- },
- };
- try check(&cases);
-
- const cases2 = [_][]const i32{
- &[_]i32{1},
- &[_]i32{ two, 3 },
- };
- try expect(cases2.len == 2);
- try expect(cases2[0].len == 1);
- try expect(cases2[0][0] == 1);
- try expect(cases2[1].len == 2);
- try expect(cases2[1][0] == 2);
- try expect(cases2[1][1] == 3);
-
- const cases3 = [_][]const []const i32{
- &[_][]const i32{&[_]i32{1}},
- &[_][]const i32{&[_]i32{ two, 3 }},
- &[_][]const i32{
- &[_]i32{4},
- &[_]i32{ 5, 6, 7 },
- },
- };
- try check(&cases3);
- }
-
- fn check(cases: []const []const []const i32) !void {
- try expect(cases.len == 3);
- try expect(cases[0].len == 1);
- try expect(cases[0][0].len == 1);
- try expect(cases[0][0][0] == 1);
- try expect(cases[1].len == 1);
- try expect(cases[1][0].len == 2);
- try expect(cases[1][0][0] == 2);
- try expect(cases[1][0][1] == 3);
- try expect(cases[2].len == 2);
- try expect(cases[2][0].len == 1);
- try expect(cases[2][0][0] == 4);
- try expect(cases[2][1].len == 3);
- try expect(cases[2][1][0] == 5);
- try expect(cases[2][1][1] == 6);
- try expect(cases[2][1][2] == 7);
- }
- };
- try S.entry(2);
- comptime try S.entry(2);
-}
-
-test "read/write through global variable array of struct fields initialized via array mult" {
- const S = struct {
- fn doTheTest() !void {
- try expect(storage[0].term == 1);
- storage[0] = MyStruct{ .term = 123 };
- try expect(storage[0].term == 123);
- }
-
- pub const MyStruct = struct {
- term: usize,
- };
-
- var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
- };
- try S.doTheTest();
-}
-
-test "implicit cast zero sized array ptr to slice" {
- {
- var b = "".*;
- const c: []const u8 = &b;
- try expect(c.len == 0);
- }
- {
- var b: [0]u8 = "".*;
- const c: []const u8 = &b;
- try expect(c.len == 0);
- }
-}
-
-test "anonymous list literal syntax" {
- const S = struct {
- fn doTheTest() !void {
- var array: [4]u8 = .{ 1, 2, 3, 4 };
- try expect(array[0] == 1);
- try expect(array[1] == 2);
- try expect(array[2] == 3);
- try expect(array[3] == 4);
- }
- };
- try S.doTheTest();
- comptime try S.doTheTest();
-}
-
-test "anonymous literal in array" {
- const S = struct {
- const Foo = struct {
- a: usize = 2,
- b: usize = 4,
- };
- fn doTheTest() !void {
- var array: [2]Foo = .{
- .{ .a = 3 },
- .{ .b = 3 },
- };
- try expect(array[0].a == 3);
- try expect(array[0].b == 4);
- try expect(array[1].a == 2);
- try expect(array[1].b == 3);
- }
- };
- try S.doTheTest();
- comptime try S.doTheTest();
-}
-
-test "access the null element of a null terminated array" {
- const S = struct {
- fn doTheTest() !void {
- var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
- try expect(array[4] == 0);
- var len: usize = 4;
- try expect(array[len] == 0);
- }
- };
- try S.doTheTest();
- comptime try S.doTheTest();
-}
-
-test "type deduction for array subscript expression" {
- const S = struct {
- fn doTheTest() !void {
- var array = [_]u8{ 0x55, 0xAA };
- var v0 = true;
- try expectEqual(@as(u8, 0xAA), array[if (v0) 1 else 0]);
- var v1 = false;
- try expectEqual(@as(u8, 0x55), array[if (v1) 1 else 0]);
- }
- };
- try S.doTheTest();
- comptime try S.doTheTest();
-}
-
-test "sentinel element count towards the ABI size calculation" {
- const S = struct {
- fn doTheTest() !void {
- const T = packed struct {
- fill_pre: u8 = 0x55,
- data: [0:0]u8 = undefined,
- fill_post: u8 = 0xAA,
- };
- var x = T{};
- var as_slice = mem.asBytes(&x);
- try expectEqual(@as(usize, 3), as_slice.len);
- try expectEqual(@as(u8, 0x55), as_slice[0]);
- try expectEqual(@as(u8, 0xAA), as_slice[2]);
- }
- };
-
- try S.doTheTest();
- comptime try S.doTheTest();
-}
-
-test "zero-sized array with recursive type definition" {
- const U = struct {
- fn foo(comptime T: type, comptime n: usize) type {
- return struct {
- s: [n]T,
- x: usize = n,
- };
- }
- };
-
- const S = struct {
- list: U.foo(@This(), 0),
- };
-
- var t: S = .{ .list = .{ .s = undefined } };
- try expectEqual(@as(usize, 0), t.list.x);
-}
-
-test "type coercion of anon struct literal to array" {
- const S = struct {
- const U = union {
- a: u32,
- b: bool,
- c: []const u8,
- };
-
- fn doTheTest() !void {
- var x1: u8 = 42;
- const t1 = .{ x1, 56, 54 };
- var arr1: [3]u8 = t1;
- try expect(arr1[0] == 42);
- try expect(arr1[1] == 56);
- try expect(arr1[2] == 54);
-
- var x2: U = .{ .a = 42 };
- const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
- var arr2: [3]U = t2;
- try expect(arr2[0].a == 42);
- try expect(arr2[1].b == true);
- try expect(mem.eql(u8, arr2[2].c, "hello"));
- }
- };
- try S.doTheTest();
- comptime try S.doTheTest();
-}
-
-test "type coercion of pointer to anon struct literal to pointer to array" {
- const S = struct {
- const U = union {
- a: u32,
- b: bool,
- c: []const u8,
- };
-
- fn doTheTest() !void {
- var x1: u8 = 42;
- const t1 = &.{ x1, 56, 54 };
- var arr1: *const [3]u8 = t1;
- try expect(arr1[0] == 42);
- try expect(arr1[1] == 56);
- try expect(arr1[2] == 54);
-
- var x2: U = .{ .a = 42 };
- const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
- var arr2: *const [3]U = t2;
- try expect(arr2[0].a == 42);
- try expect(arr2[1].b == true);
- try expect(mem.eql(u8, arr2[2].c, "hello"));
- }
- };
- try S.doTheTest();
- comptime try S.doTheTest();
-}
diff --git a/test/behavior/array_stage1.zig b/test/behavior/array_stage1.zig
new file mode 100644
index 0000000000..84a2cdb36c
--- /dev/null
+++ b/test/behavior/array_stage1.zig
@@ -0,0 +1,489 @@
+const std = @import("std");
+const testing = std.testing;
+const mem = std.mem;
+const expect = testing.expect;
+const expectEqual = testing.expectEqual;
+
+test "arrays" {
+ var array: [5]u32 = undefined;
+
+ var i: u32 = 0;
+ while (i < 5) {
+ array[i] = i + 1;
+ i = array[i];
+ }
+
+ i = 0;
+ var accumulator = @as(u32, 0);
+ while (i < 5) {
+ accumulator += array[i];
+
+ i += 1;
+ }
+
+ try expect(accumulator == 15);
+ try expect(getArrayLen(&array) == 5);
+}
+fn getArrayLen(a: []const u32) usize {
+ return a.len;
+}
+
+test "array with sentinels" {
+ const S = struct {
+ fn doTheTest(is_ct: bool) !void {
+ if (is_ct) {
+ var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
+ // Disabled at runtime because of
+ // https://github.com/ziglang/zig/issues/4372
+ try expectEqual(@as(u8, 0xde), zero_sized[0]);
+ var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
+ try expectEqual(@as(u8, 0xde), reinterpreted[0]);
+ }
+ var arr: [3:0x55]u8 = undefined;
+ // Make sure the sentinel pointer is pointing after the last element
+ if (!is_ct) {
+ const sentinel_ptr = @ptrToInt(&arr[3]);
+ const last_elem_ptr = @ptrToInt(&arr[2]);
+ try expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
+ }
+ // Make sure the sentinel is writeable
+ arr[3] = 0x55;
+ }
+ };
+
+ try S.doTheTest(false);
+ comptime try S.doTheTest(true);
+}
+
+test "void arrays" {
+ var array: [4]void = undefined;
+ array[0] = void{};
+ array[1] = array[2];
+ try expect(@sizeOf(@TypeOf(array)) == 0);
+ try expect(array.len == 4);
+}
+
+test "array literal" {
+ const hex_mult = [_]u16{
+ 4096,
+ 256,
+ 16,
+ 1,
+ };
+
+ try expect(hex_mult.len == 4);
+ try expect(hex_mult[1] == 256);
+}
+
+test "array dot len const expr" {
+ try expect(comptime x: {
+ break :x some_array.len == 4;
+ });
+}
+
+const ArrayDotLenConstExpr = struct {
+ y: [some_array.len]u8,
+};
+const some_array = [_]u8{
+ 0,
+ 1,
+ 2,
+ 3,
+};
+
+test "nested arrays" {
+ const array_of_strings = [_][]const u8{
+ "hello",
+ "this",
+ "is",
+ "my",
+ "thing",
+ };
+ for (array_of_strings) |s, i| {
+ if (i == 0) try expect(mem.eql(u8, s, "hello"));
+ if (i == 1) try expect(mem.eql(u8, s, "this"));
+ if (i == 2) try expect(mem.eql(u8, s, "is"));
+ if (i == 3) try expect(mem.eql(u8, s, "my"));
+ if (i == 4) try expect(mem.eql(u8, s, "thing"));
+ }
+}
+
+var s_array: [8]Sub = undefined;
+const Sub = struct {
+ b: u8,
+};
+const Str = struct {
+ a: []Sub,
+};
+test "set global var array via slice embedded in struct" {
+ var s = Str{ .a = s_array[0..] };
+
+ s.a[0].b = 1;
+ s.a[1].b = 2;
+ s.a[2].b = 3;
+
+ try expect(s_array[0].b == 1);
+ try expect(s_array[1].b == 2);
+ try expect(s_array[2].b == 3);
+}
+
+test "array literal with specified size" {
+ var array = [2]u8{
+ 1,
+ 2,
+ };
+ try expect(array[0] == 1);
+ try expect(array[1] == 2);
+}
+
+test "array len field" {
+ var arr = [4]u8{ 0, 0, 0, 0 };
+ var ptr = &arr;
+ try expect(arr.len == 4);
+ comptime try expect(arr.len == 4);
+ try expect(ptr.len == 4);
+ comptime try expect(ptr.len == 4);
+}
+
+test "single-item pointer to array indexing and slicing" {
+ try testSingleItemPtrArrayIndexSlice();
+ comptime try testSingleItemPtrArrayIndexSlice();
+}
+
+fn testSingleItemPtrArrayIndexSlice() !void {
+ {
+ var array: [4]u8 = "aaaa".*;
+ doSomeMangling(&array);
+ try expect(mem.eql(u8, "azya", &array));
+ }
+ {
+ var array = "aaaa".*;
+ doSomeMangling(&array);
+ try expect(mem.eql(u8, "azya", &array));
+ }
+}
+
+fn doSomeMangling(array: *[4]u8) void {
+ array[1] = 'z';
+ array[2..3][0] = 'y';
+}
+
+test "implicit cast single-item pointer" {
+ try testImplicitCastSingleItemPtr();
+ comptime try testImplicitCastSingleItemPtr();
+}
+
+fn testImplicitCastSingleItemPtr() !void {
+ var byte: u8 = 100;
+ const slice = @as(*[1]u8, &byte)[0..];
+ slice[0] += 1;
+ try expect(byte == 101);
+}
+
+fn testArrayByValAtComptime(b: [2]u8) u8 {
+ return b[0];
+}
+
+test "comptime evalutating function that takes array by value" {
+ const arr = [_]u8{ 0, 1 };
+ _ = comptime testArrayByValAtComptime(arr);
+ _ = comptime testArrayByValAtComptime(arr);
+}
+
+test "implicit comptime in array type size" {
+ var arr: [plusOne(10)]bool = undefined;
+ try expect(arr.len == 11);
+}
+
+fn plusOne(x: u32) u32 {
+ return x + 1;
+}
+
+test "runtime initialize array elem and then implicit cast to slice" {
+ var two: i32 = 2;
+ const x: []const i32 = &[_]i32{two};
+ try expect(x[0] == 2);
+}
+
+test "array literal as argument to function" {
+ const S = struct {
+ fn entry(two: i32) !void {
+ try foo(&[_]i32{
+ 1,
+ 2,
+ 3,
+ });
+ try foo(&[_]i32{
+ 1,
+ two,
+ 3,
+ });
+ try foo2(true, &[_]i32{
+ 1,
+ 2,
+ 3,
+ });
+ try foo2(true, &[_]i32{
+ 1,
+ two,
+ 3,
+ });
+ }
+ fn foo(x: []const i32) !void {
+ try expect(x[0] == 1);
+ try expect(x[1] == 2);
+ try expect(x[2] == 3);
+ }
+ fn foo2(trash: bool, x: []const i32) !void {
+ try expect(trash);
+ try expect(x[0] == 1);
+ try expect(x[1] == 2);
+ try expect(x[2] == 3);
+ }
+ };
+ try S.entry(2);
+ comptime try S.entry(2);
+}
+
+test "double nested array to const slice cast in array literal" {
+ const S = struct {
+ fn entry(two: i32) !void {
+ const cases = [_][]const []const i32{
+ &[_][]const i32{&[_]i32{1}},
+ &[_][]const i32{&[_]i32{ 2, 3 }},
+ &[_][]const i32{
+ &[_]i32{4},
+ &[_]i32{ 5, 6, 7 },
+ },
+ };
+ try check(&cases);
+
+ const cases2 = [_][]const i32{
+ &[_]i32{1},
+ &[_]i32{ two, 3 },
+ };
+ try expect(cases2.len == 2);
+ try expect(cases2[0].len == 1);
+ try expect(cases2[0][0] == 1);
+ try expect(cases2[1].len == 2);
+ try expect(cases2[1][0] == 2);
+ try expect(cases2[1][1] == 3);
+
+ const cases3 = [_][]const []const i32{
+ &[_][]const i32{&[_]i32{1}},
+ &[_][]const i32{&[_]i32{ two, 3 }},
+ &[_][]const i32{
+ &[_]i32{4},
+ &[_]i32{ 5, 6, 7 },
+ },
+ };
+ try check(&cases3);
+ }
+
+ fn check(cases: []const []const []const i32) !void {
+ try expect(cases.len == 3);
+ try expect(cases[0].len == 1);
+ try expect(cases[0][0].len == 1);
+ try expect(cases[0][0][0] == 1);
+ try expect(cases[1].len == 1);
+ try expect(cases[1][0].len == 2);
+ try expect(cases[1][0][0] == 2);
+ try expect(cases[1][0][1] == 3);
+ try expect(cases[2].len == 2);
+ try expect(cases[2][0].len == 1);
+ try expect(cases[2][0][0] == 4);
+ try expect(cases[2][1].len == 3);
+ try expect(cases[2][1][0] == 5);
+ try expect(cases[2][1][1] == 6);
+ try expect(cases[2][1][2] == 7);
+ }
+ };
+ try S.entry(2);
+ comptime try S.entry(2);
+}
+
+test "read/write through global variable array of struct fields initialized via array mult" {
+ const S = struct {
+ fn doTheTest() !void {
+ try expect(storage[0].term == 1);
+ storage[0] = MyStruct{ .term = 123 };
+ try expect(storage[0].term == 123);
+ }
+
+ pub const MyStruct = struct {
+ term: usize,
+ };
+
+ var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
+ };
+ try S.doTheTest();
+}
+
+test "implicit cast zero sized array ptr to slice" {
+ {
+ var b = "".*;
+ const c: []const u8 = &b;
+ try expect(c.len == 0);
+ }
+ {
+ var b: [0]u8 = "".*;
+ const c: []const u8 = &b;
+ try expect(c.len == 0);
+ }
+}
+
+test "anonymous list literal syntax" {
+ const S = struct {
+ fn doTheTest() !void {
+ var array: [4]u8 = .{ 1, 2, 3, 4 };
+ try expect(array[0] == 1);
+ try expect(array[1] == 2);
+ try expect(array[2] == 3);
+ try expect(array[3] == 4);
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "anonymous literal in array" {
+ const S = struct {
+ const Foo = struct {
+ a: usize = 2,
+ b: usize = 4,
+ };
+ fn doTheTest() !void {
+ var array: [2]Foo = .{
+ .{ .a = 3 },
+ .{ .b = 3 },
+ };
+ try expect(array[0].a == 3);
+ try expect(array[0].b == 4);
+ try expect(array[1].a == 2);
+ try expect(array[1].b == 3);
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "access the null element of a null terminated array" {
+ const S = struct {
+ fn doTheTest() !void {
+ var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
+ try expect(array[4] == 0);
+ var len: usize = 4;
+ try expect(array[len] == 0);
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "type deduction for array subscript expression" {
+ const S = struct {
+ fn doTheTest() !void {
+ var array = [_]u8{ 0x55, 0xAA };
+ var v0 = true;
+ try expectEqual(@as(u8, 0xAA), array[if (v0) 1 else 0]);
+ var v1 = false;
+ try expectEqual(@as(u8, 0x55), array[if (v1) 1 else 0]);
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "sentinel element count towards the ABI size calculation" {
+ const S = struct {
+ fn doTheTest() !void {
+ const T = packed struct {
+ fill_pre: u8 = 0x55,
+ data: [0:0]u8 = undefined,
+ fill_post: u8 = 0xAA,
+ };
+ var x = T{};
+ var as_slice = mem.asBytes(&x);
+ try expectEqual(@as(usize, 3), as_slice.len);
+ try expectEqual(@as(u8, 0x55), as_slice[0]);
+ try expectEqual(@as(u8, 0xAA), as_slice[2]);
+ }
+ };
+
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "zero-sized array with recursive type definition" {
+ const U = struct {
+ fn foo(comptime T: type, comptime n: usize) type {
+ return struct {
+ s: [n]T,
+ x: usize = n,
+ };
+ }
+ };
+
+ const S = struct {
+ list: U.foo(@This(), 0),
+ };
+
+ var t: S = .{ .list = .{ .s = undefined } };
+ try expectEqual(@as(usize, 0), t.list.x);
+}
+
+test "type coercion of anon struct literal to array" {
+ const S = struct {
+ const U = union {
+ a: u32,
+ b: bool,
+ c: []const u8,
+ };
+
+ fn doTheTest() !void {
+ var x1: u8 = 42;
+ const t1 = .{ x1, 56, 54 };
+ var arr1: [3]u8 = t1;
+ try expect(arr1[0] == 42);
+ try expect(arr1[1] == 56);
+ try expect(arr1[2] == 54);
+
+ var x2: U = .{ .a = 42 };
+ const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
+ var arr2: [3]U = t2;
+ try expect(arr2[0].a == 42);
+ try expect(arr2[1].b == true);
+ try expect(mem.eql(u8, arr2[2].c, "hello"));
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
+test "type coercion of pointer to anon struct literal to pointer to array" {
+ const S = struct {
+ const U = union {
+ a: u32,
+ b: bool,
+ c: []const u8,
+ };
+
+ fn doTheTest() !void {
+ var x1: u8 = 42;
+ const t1 = &.{ x1, 56, 54 };
+ var arr1: *const [3]u8 = t1;
+ try expect(arr1[0] == 42);
+ try expect(arr1[1] == 56);
+ try expect(arr1[2] == 54);
+
+ var x2: U = .{ .a = 42 };
+ const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
+ var arr2: *const [3]U = t2;
+ try expect(arr2[0].a == 42);
+ try expect(arr2[1].b == true);
+ try expect(mem.eql(u8, arr2[2].c, "hello"));
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig
index dbda9f3238..fd526e1bef 100644
--- a/test/behavior/enum.zig
+++ b/test/behavior/enum.zig
@@ -203,7 +203,7 @@ test "int to enum" {
try testIntToEnumEval(3);
}
fn testIntToEnumEval(x: i32) !void {
- try expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
+ try expect(@intToEnum(IntToEnumNumber, x) == IntToEnumNumber.Three);
}
const IntToEnumNumber = enum {
Zero,
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index b1ef55af9e..74bf105799 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -412,19 +412,19 @@ test "function pointer with return type that is error union with payload which i
test "return result loc as peer result loc in inferred error set function" {
const S = struct {
fn doTheTest() !void {
- if (foo(2)) |x| {
+ if (quux(2)) |x| {
try expect(x.Two);
} else |e| switch (e) {
error.Whatever => @panic("fail"),
}
- try expectError(error.Whatever, foo(99));
+ try expectError(error.Whatever, quux(99));
}
const FormValue = union(enum) {
One: void,
Two: bool,
};
- fn foo(id: u64) !FormValue {
+ fn quux(id: u64) !FormValue {
return switch (id) {
2 => FormValue{ .Two = true },
1 => FormValue{ .One = {} },
@@ -452,11 +452,11 @@ test "error payload type is correctly resolved" {
test "error union comptime caching" {
const S = struct {
- fn foo(comptime arg: anytype) void {
+ fn quux(comptime arg: anytype) void {
arg catch {};
}
};
- S.foo(@as(anyerror!void, {}));
- S.foo(@as(anyerror!void, {}));
+ S.quux(@as(anyerror!void, {}));
+ S.quux(@as(anyerror!void, {}));
}
diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig
index a97aab7bb3..1b6540cd32 100644
--- a/test/behavior/eval.zig
+++ b/test/behavior/eval.zig
@@ -130,3 +130,34 @@ test "no undeclared identifier error in unanalyzed branches" {
lol_this_doesnt_exist = nonsense;
}
}
+
+test "a type constructed in a global expression" {
+ var l: List = undefined;
+ l.array[0] = 10;
+ l.array[1] = 11;
+ l.array[2] = 12;
+ const ptr = @ptrCast([*]u8, &l.array);
+ try expect(ptr[0] == 10);
+ try expect(ptr[1] == 11);
+ try expect(ptr[2] == 12);
+}
+
+const List = blk: {
+ const T = [10]u8;
+ break :blk struct {
+ array: T,
+ };
+};
+
+test "comptime function with the same args is memoized" {
+ comptime {
+ try expect(MakeType(i32) == MakeType(i32));
+ try expect(MakeType(i32) != MakeType(f64));
+ }
+}
+
+fn MakeType(comptime T: type) type {
+ return struct {
+ field: T,
+ };
+}
diff --git a/test/behavior/eval_stage1.zig b/test/behavior/eval_stage1.zig
index 3599d5a477..644de50fd0 100644
--- a/test/behavior/eval_stage1.zig
+++ b/test/behavior/eval_stage1.zig
@@ -356,19 +356,6 @@ test "binary math operator in partially inlined function" {
try expect(s[3] == 0xd0e0f10);
}
-test "comptime function with the same args is memoized" {
- comptime {
- try expect(MakeType(i32) == MakeType(i32));
- try expect(MakeType(i32) != MakeType(f64));
- }
-}
-
-fn MakeType(comptime T: type) type {
- return struct {
- field: T,
- };
-}
-
test "comptime function with mutable pointer is not memoized" {
comptime {
var x: i32 = 1;
diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig
index 67fb1def8b..ef772deb4e 100644
--- a/test/behavior/generics.zig
+++ b/test/behavior/generics.zig
@@ -78,3 +78,42 @@ fn max_i32(a: i32, b: i32) i32 {
fn max_f64(a: f64, b: f64) f64 {
return max_anytype(a, b);
}
+
+test "type constructed by comptime function call" {
+ var l: SimpleList(10) = undefined;
+ l.array[0] = 10;
+ l.array[1] = 11;
+ l.array[2] = 12;
+ const ptr = @ptrCast([*]u8, &l.array);
+ try expect(ptr[0] == 10);
+ try expect(ptr[1] == 11);
+ try expect(ptr[2] == 12);
+}
+
+fn SimpleList(comptime L: usize) type {
+ var T = u8;
+ return struct {
+ array: [L]T,
+ };
+}
+
+test "function with return type type" {
+ var list: List(i32) = undefined;
+ var list2: List(i32) = undefined;
+ list.length = 10;
+ list2.length = 10;
+ try expect(list.prealloc_items.len == 8);
+ try expect(list2.prealloc_items.len == 8);
+}
+
+pub fn List(comptime T: type) type {
+ return SmallList(T, 8);
+}
+
+pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
+ return struct {
+ items: []T,
+ length: usize,
+ prealloc_items: [STATIC_SIZE]T,
+ };
+}
diff --git a/test/behavior/generics_stage1.zig b/test/behavior/generics_stage1.zig
index 4b768a5b4f..4fa52f5377 100644
--- a/test/behavior/generics_stage1.zig
+++ b/test/behavior/generics_stage1.zig
@@ -3,27 +3,6 @@ const testing = std.testing;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
-pub fn List(comptime T: type) type {
- return SmallList(T, 8);
-}
-
-pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
- return struct {
- items: []T,
- length: usize,
- prealloc_items: [STATIC_SIZE]T,
- };
-}
-
-test "function with return type type" {
- var list: List(i32) = undefined;
- var list2: List(i32) = undefined;
- list.length = 10;
- list2.length = 10;
- try expect(list.prealloc_items.len == 8);
- try expect(list2.prealloc_items.len == 8);
-}
-
test "generic struct" {
var a1 = GenNode(i32){
.value = 13,
diff --git a/test/behavior/misc.zig b/test/behavior/misc.zig
index 466be00bd3..8e63ad81dd 100644
--- a/test/behavior/misc.zig
+++ b/test/behavior/misc.zig
@@ -505,3 +505,36 @@ test "lazy typeInfo value as generic parameter" {
};
S.foo(@typeInfo(@TypeOf(.{})));
}
+
+fn A() type {
+ return struct {
+ b: B(),
+
+ const Self = @This();
+
+ fn B() type {
+ return struct {
+ const Self = @This();
+ };
+ }
+ };
+}
+test "non-ambiguous reference of shadowed decls" {
+ try expect(A().B().Self != A().Self);
+}
+
+test "use of declaration with same name as primitive" {
+ const S = struct {
+ const @"u8" = u16;
+ const alias = @"u8";
+ };
+ const a: S.u8 = 300;
+ try expect(a == 300);
+
+ const b: S.alias = 300;
+ try expect(b == 300);
+
+ const @"u8" = u16;
+ const c: @"u8" = 300;
+ try expect(c == 300);
+}
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index 4f7e0c2d71..d9e1c02aa1 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -162,14 +162,14 @@ const MemberFnRand = struct {
};
test "return struct byval from function" {
- const bar = makeBar(1234, 5678);
+ const bar = makeBar2(1234, 5678);
try expect(bar.y == 5678);
}
const Bar = struct {
x: i32,
y: i32,
};
-fn makeBar(x: i32, y: i32) Bar {
+fn makeBar2(x: i32, y: i32) Bar {
return Bar{
.x = x,
.y = y,
diff --git a/test/cases.zig b/test/cases.zig
index e8479b792e..4dc4499e60 100644
--- a/test/cases.zig
+++ b/test/cases.zig
@@ -26,7 +26,7 @@ pub fn addCases(ctx: *TestContext) !void {
var case = ctx.exe("hello world with updates", linux_x64);
case.addError("", &[_][]const u8{
- ":95:9: error: struct 'tmp.tmp' has no member named 'main'",
+ ":90:9: error: struct 'tmp.tmp' has no member named 'main'",
});
// Incorrect return type
diff --git a/test/compare_output.zig b/test/compare_output.zig
index 742e43e6c7..c3da3cc4a5 100644
--- a/test/compare_output.zig
+++ b/test/compare_output.zig
@@ -585,16 +585,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ comptime format: []const u8,
\\ args: anytype,
\\) void {
- \\ const level_txt = switch (level) {
- \\ .emerg => "emergency",
- \\ .alert => "alert",
- \\ .crit => "critical",
- \\ .err => "error",
- \\ .warn => "warning",
- \\ .notice => "notice",
- \\ .info => "info",
- \\ .debug => "debug",
- \\ };
+ \\ const level_txt = comptime level.asText();
\\ const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
\\ const stdout = std.io.getStdOut().writer();
\\ nosuspend stdout.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
@@ -638,16 +629,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ comptime format: []const u8,
\\ args: anytype,
\\) void {
- \\ const level_txt = switch (level) {
- \\ .emerg => "emergency",
- \\ .alert => "alert",
- \\ .crit => "critical",
- \\ .err => "error",
- \\ .warn => "warning",
- \\ .notice => "notice",
- \\ .info => "info",
- \\ .debug => "debug",
- \\ };
+ \\ const level_txt = comptime level.asText();
\\ const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
\\ const stdout = std.io.getStdOut().writer();
\\ nosuspend stdout.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 6075eee33a..6e910b1b3e 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -6969,29 +6969,24 @@ pub fn addCases(ctx: *TestContext) !void {
"tmp.zig:2:30: error: cannot set section of local variable 'foo'",
});
- ctx.objErrStage1("inner struct member shadowing outer struct member",
- \\fn A() type {
- \\ return struct {
- \\ b: B(),
- \\
- \\ const Self = @This();
- \\
- \\ fn B() type {
- \\ return struct {
- \\ const Self = @This();
- \\ };
+ ctx.objErrStage1("ambiguous decl reference",
+ \\fn foo() void {}
+ \\fn bar() void {
+ \\ const S = struct {
+ \\ fn baz() void {
+ \\ foo();
\\ }
+ \\ fn foo() void {}
\\ };
+ \\ S.baz();
\\}
- \\comptime {
- \\ assert(A().B().Self != A().Self);
- \\}
- \\fn assert(ok: bool) void {
- \\ if (!ok) unreachable;
+ \\export fn entry() void {
+ \\ bar();
\\}
, &[_][]const u8{
- "tmp.zig:9:17: error: redefinition of 'Self'",
- "tmp.zig:5:9: note: previous definition here",
+ "tmp.zig:5:13: error: ambiguous reference",
+ "tmp.zig:7:9: note: declared here",
+ "tmp.zig:1:1: note: also declared here",
});
ctx.objErrStage1("while expected bool, got optional",
@@ -7263,14 +7258,36 @@ pub fn addCases(ctx: *TestContext) !void {
"tmp.zig:2:17: error: expected type 'u3', found 'u8'",
});
- ctx.objErrStage1("globally shadowing a primitive type",
- \\const u16 = u8;
- \\export fn entry() void {
- \\ const a: u16 = 300;
+ ctx.objErrStage1("locally shadowing a primitive type",
+ \\export fn foo() void {
+ \\ const u8 = u16;
+ \\ const a: u8 = 300;
\\ _ = a;
\\}
, &[_][]const u8{
- "tmp.zig:1:1: error: declaration shadows primitive type 'u16'",
+ "tmp.zig:2:11: error: name shadows primitive 'u8'",
+ "tmp.zig:2:11: note: consider using @\"u8\" to disambiguate",
+ });
+
+ ctx.objErrStage1("primitives take precedence over declarations",
+ \\const @"u8" = u16;
+ \\export fn entry() void {
+ \\ const a: u8 = 300;
+ \\ _ = a;
+ \\}
+ , &[_][]const u8{
+ "tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'",
+ });
+
+ ctx.objErrStage1("declaration with same name as primitive must use special syntax",
+ \\const u8 = u16;
+ \\export fn entry() void {
+ \\ const a: u8 = 300;
+ \\ _ = a;
+ \\}
+ , &[_][]const u8{
+ "tmp.zig:1:7: error: name shadows primitive 'u8'",
+ "tmp.zig:1:7: note: consider using @\"u8\" to disambiguate",
});
ctx.objErrStage1("implicitly increasing pointer alignment",
@@ -7691,12 +7708,12 @@ pub fn addCases(ctx: *TestContext) !void {
\\};
\\
\\export fn entry() void {
- \\ var y = @as(u3, 3);
+ \\ var y = @as(f32, 3);
\\ var x = @intToEnum(Small, y);
\\ _ = x;
\\}
, &[_][]const u8{
- "tmp.zig:10:31: error: expected type 'u2', found 'u3'",
+ "tmp.zig:10:31: error: expected integer type, found 'f32'",
});
ctx.objErrStage1("union fields with value assignments",
diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig
index 2e579b06c7..28ba7aa704 100644
--- a/test/run_translated_c.zig
+++ b/test/run_translated_c.zig
@@ -1749,4 +1749,22 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
+
+ cases.add("Allow non-const char* string literals. Issue #9126",
+ \\#include
+ \\int func(char *x) { return x[0]; }
+ \\struct S { char *member; };
+ \\struct S global_struct = { .member = "global" };
+ \\char *g = "global";
+ \\int main(void) {
+ \\ if (g[0] != 'g') abort();
+ \\ if (global_struct.member[0] != 'g') abort();
+ \\ char *string = "hello";
+ \\ if (string[0] != 'h') abort();
+ \\ struct S s = {.member = "hello"};
+ \\ if (s.member[0] != 'h') abort();
+ \\ if (func("foo") != 'f') abort();
+ \\ return 0;
+ \\}
+ , "");
}
diff --git a/test/stage2/arm.zig b/test/stage2/arm.zig
index 103b058a54..912e77ebae 100644
--- a/test/stage2/arm.zig
+++ b/test/stage2/arm.zig
@@ -204,6 +204,48 @@ pub fn addCases(ctx: *TestContext) !void {
,
"123456",
);
+
+ // Bit Shift Left
+ case.addCompareOutput(
+ \\pub fn main() void {
+ \\ var x: u32 = 1;
+ \\ assert(x << 1 == 2);
+ \\
+ \\ x <<= 1;
+ \\ assert(x << 2 == 8);
+ \\ assert(x << 3 == 16);
+ \\}
+ \\
+ \\pub fn assert(ok: bool) void {
+ \\ if (!ok) unreachable; // assertion failure
+ \\}
+ ,
+ "",
+ );
+
+ // Bit Shift Right
+ case.addCompareOutput(
+ \\pub fn main() void {
+ \\ var a: u32 = 1024;
+ \\ assert(a >> 1 == 512);
+ \\
+ \\ a >>= 1;
+ \\ assert(a >> 2 == 128);
+ \\ assert(a >> 3 == 64);
+ \\ assert(a >> 4 == 32);
+ \\ assert(a >> 5 == 16);
+ \\ assert(a >> 6 == 8);
+ \\ assert(a >> 7 == 4);
+ \\ assert(a >> 8 == 2);
+ \\ assert(a >> 9 == 1);
+ \\}
+ \\
+ \\pub fn assert(ok: bool) void {
+ \\ if (!ok) unreachable; // assertion failure
+ \\}
+ ,
+ "",
+ );
}
{
@@ -319,6 +361,22 @@ pub fn addCases(ctx: *TestContext) !void {
,
"",
);
+
+ case.addCompareOutput(
+ \\const Number = enum { one, two, three };
+ \\
+ \\pub fn main() void {
+ \\ var x: Number = .one;
+ \\ var y = Number.two;
+ \\ assert(@enumToInt(x) < @enumToInt(y));
+ \\}
+ \\
+ \\fn assert(ok: bool) void {
+ \\ if (!ok) unreachable; // assertion failure
+ \\}
+ ,
+ "",
+ );
}
{
@@ -429,4 +487,48 @@ pub fn addCases(ctx: *TestContext) !void {
"",
);
}
+
+ {
+ var case = ctx.exe("print u32s", linux_arm);
+ case.addCompareOutput(
+ \\pub fn main() void {
+ \\ printNumberHex(0x00000000);
+ \\ printNumberHex(0xaaaaaaaa);
+ \\ printNumberHex(0xdeadbeef);
+ \\ printNumberHex(0x31415926);
+ \\}
+ \\
+ \\fn printNumberHex(x: u32) void {
+ \\ var i: u5 = 28;
+ \\ while (true) : (i -= 4) {
+ \\ const digit = (x >> i) & 0xf;
+ \\ asm volatile ("svc #0"
+ \\ :
+ \\ : [number] "{r7}" (4),
+ \\ [arg1] "{r0}" (1),
+ \\ [arg2] "{r1}" (@ptrToInt("0123456789abcdef") + digit),
+ \\ [arg3] "{r2}" (1)
+ \\ : "memory"
+ \\ );
+ \\
+ \\ if (i == 0) break;
+ \\ }
+ \\ asm volatile ("svc #0"
+ \\ :
+ \\ : [number] "{r7}" (4),
+ \\ [arg1] "{r0}" (1),
+ \\ [arg2] "{r1}" (@ptrToInt("\n")),
+ \\ [arg3] "{r2}" (1)
+ \\ : "memory"
+ \\ );
+ \\}
+ ,
+ \\00000000
+ \\aaaaaaaa
+ \\deadbeef
+ \\31415926
+ \\
+ ,
+ );
+ }
}
diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig
index aa1022257b..21270f130b 100644
--- a/test/stage2/cbe.zig
+++ b/test/stage2/cbe.zig
@@ -555,6 +555,19 @@ pub fn addCases(ctx: *TestContext) !void {
\\ return p.y - p.x - p.x;
\\}
, "");
+ case.addCompareOutput(
+ \\const Point = struct { x: i32, y: i32, z: i32, a: i32, b: i32 };
+ \\pub export fn main() c_int {
+ \\ var p: Point = .{
+ \\ .x = 18,
+ \\ .y = 24,
+ \\ .z = 1,
+ \\ .a = 2,
+ \\ .b = 3,
+ \\ };
+ \\ return p.y - p.x - p.z - p.a - p.b;
+ \\}
+ , "");
}
{
@@ -808,6 +821,31 @@ pub fn addCases(ctx: *TestContext) !void {
});
}
+ {
+ var case = ctx.exeFromCompiledC("shift right + left", .{});
+ case.addCompareOutput(
+ \\pub export fn main() c_int {
+ \\ var i: u32 = 16;
+ \\ assert(i >> 1, 8);
+ \\ return 0;
+ \\}
+ \\fn assert(a: u32, b: u32) void {
+ \\ if (a != b) unreachable;
+ \\}
+ , "");
+
+ case.addCompareOutput(
+ \\pub export fn main() c_int {
+ \\ var i: u32 = 16;
+ \\ assert(i << 1, 32);
+ \\ return 0;
+ \\}
+ \\fn assert(a: u32, b: u32) void {
+ \\ if (a != b) unreachable;
+ \\}
+ , "");
+ }
+
{
var case = ctx.exeFromCompiledC("inferred error sets", .{});
diff --git a/test/stage2/darwin.zig b/test/stage2/darwin.zig
index 3f05d6c198..87b04d1dff 100644
--- a/test/stage2/darwin.zig
+++ b/test/stage2/darwin.zig
@@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {
{
var case = ctx.exe("hello world with updates", target);
case.addError("", &[_][]const u8{
- ":95:9: error: struct 'tmp.tmp' has no member named 'main'",
+ ":90:9: error: struct 'tmp.tmp' has no member named 'main'",
});
// Incorrect return type
diff --git a/test/stage2/llvm.zig b/test/stage2/llvm.zig
index 0e8e0036e3..09649f518c 100644
--- a/test/stage2/llvm.zig
+++ b/test/stage2/llvm.zig
@@ -28,6 +28,31 @@ pub fn addCases(ctx: *TestContext) !void {
, "");
}
+ {
+ var case = ctx.exeUsingLlvmBackend("shift right + left", linux_x64);
+
+ case.addCompareOutput(
+ \\pub export fn main() c_int {
+ \\ var i: u32 = 16;
+ \\ assert(i >> 1, 8);
+ \\ return 0;
+ \\}
+ \\fn assert(a: u32, b: u32) void {
+ \\ if (a != b) unreachable;
+ \\}
+ , "");
+ case.addCompareOutput(
+ \\pub export fn main() c_int {
+ \\ var i: u32 = 16;
+ \\ assert(i << 1, 32);
+ \\ return 0;
+ \\}
+ \\fn assert(a: u32, b: u32) void {
+ \\ if (a != b) unreachable;
+ \\}
+ , "");
+ }
+
{
var case = ctx.exeUsingLlvmBackend("llvm hello world", linux_x64);
diff --git a/tools/update-license-headers.zig b/tools/update-license-headers.zig
new file mode 100644
index 0000000000..4cc60ca4ea
--- /dev/null
+++ b/tools/update-license-headers.zig
@@ -0,0 +1,47 @@
+const std = @import("std");
+
+/// This script replaces a matching license header from .zig source files in a directory tree
+/// with the `new_header` below.
+const new_header = "";
+
+pub fn main() !void {
+ var progress = std.Progress{};
+ const root_node = try progress.start("", 0);
+ defer root_node.end();
+
+ var arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator);
+ const arena = &arena_allocator.allocator;
+
+ const args = try std.process.argsAlloc(arena);
+ const path_to_walk = args[1];
+ const dir = try std.fs.cwd().openDir(path_to_walk, .{ .iterate = true });
+
+ var walker = try dir.walk(arena);
+ defer walker.deinit();
+
+ var buffer: [500]u8 = undefined;
+ const expected_header = buffer[0..try std.io.getStdIn().readAll(&buffer)];
+
+ while (try walker.next()) |entry| {
+ if (!std.mem.endsWith(u8, entry.basename, ".zig"))
+ continue;
+
+ var node = root_node.start(entry.basename, 0);
+ node.activate();
+ defer node.end();
+
+ const source = try dir.readFileAlloc(arena, entry.path, 20 * 1024 * 1024);
+ if (!std.mem.startsWith(u8, source, expected_header)) {
+ std.debug.print("no match: {s}\n", .{entry.path});
+ continue;
+ }
+
+ const truncated_source = source[expected_header.len..];
+
+ const new_source = try arena.alloc(u8, truncated_source.len + new_header.len);
+ std.mem.copy(u8, new_source, new_header);
+ std.mem.copy(u8, new_source[new_header.len..], truncated_source);
+
+ try dir.writeFile(entry.path, new_source);
+ }
+}