From 642f5df0abbcfda47df94ba657b24a913d6903d4 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Thu, 24 Jun 2021 04:11:28 -0600 Subject: [PATCH 01/54] Expose default std.log implementation This allows root.log implementations to capture log messages, process them, and forward them to the default implementation if desired. --- lib/std/log.zig | 51 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/lib/std/log.zig b/lib/std/log.zig index a20648626e7ff5fe65e07f2aee1cb34701c9f35a..5cff132e440d693a43b921940ee7baea218ca5c3 100644 --- a/lib/std/log.zig +++ b/lib/std/log.zig @@ -145,30 +145,43 @@ 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 = 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; +} + /// Returns a scoped logging namespace that logs all messages using the scope /// provided here. pub fn scoped(comptime scope: @Type(.EnumLiteral)) type { -- 2.54.0 From cadf32d74545a31daaddcfccbf0f8e68efea66a7 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Thu, 24 Jun 2021 04:30:05 -0600 Subject: [PATCH 02/54] Expose mechanism to convert log level to text --- lib/std/log.zig | 28 ++++++++++++++++++---------- test/compare_output.zig | 22 ++-------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/lib/std/log.zig b/lib/std/log.zig index 5cff132e440d693a43b921940ee7baea218ca5c3..1b3095e0ee1621113082cb88696c2a45b1bb54ed 100644 --- a/lib/std/log.zig +++ b/lib/std/log.zig @@ -100,6 +100,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. @@ -165,16 +182,7 @@ pub fn defaultLog( return; } - const level_txt = switch (message_level) { - .emerg => "emergency", - .alert => "alert", - .crit => "critical", - .err => "error", - .warn => "warning", - .notice => "notice", - .info => "info", - .debug => "debug", - }; + 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(); diff --git a/test/compare_output.zig b/test/compare_output.zig index 742e43e6c7fca67ff92cd5417dcbb64a1707cdb4..c3da3cc4a5c0721f09ca28629f1c64c984a1fda6 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; -- 2.54.0 From 2e6ce11eb29434231102c00fddd0a1b3e0ba5608 Mon Sep 17 00:00:00 2001 From: Jacob G-W Date: Wed, 18 Aug 2021 22:22:12 -0400 Subject: [PATCH 03/54] stage2: implement shr and boilerplate for shl This implements it in the llvm and c backends. x86_64 will have to be a little more work. --- src/Air.zig | 8 +++++++ src/Liveness.zig | 2 ++ src/Sema.zig | 45 +++++++++++++++++++++++++++++++---- src/codegen.zig | 20 ++++++++++++++++ src/codegen/c.zig | 3 +++ src/codegen/llvm.zig | 32 +++++++++++++++++++++++++ src/codegen/llvm/bindings.zig | 17 +++++++++++++ src/print_air.zig | 2 ++ test/stage2/cbe.zig | 14 +++++++++++ test/stage2/llvm.zig | 14 +++++++++++ 10 files changed, 153 insertions(+), 4 deletions(-) diff --git a/src/Air.zig b/src/Air.zig index 391683afd5c0c8f99c4b3d03abbc91f67e07d8ff..2c5235e4a1c8b71a4454eee03fbe36b5011509b4 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, @@ -445,6 +451,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, diff --git a/src/Liveness.zig b/src/Liveness.zig index 48603fc7c9174f8cbef4ca5e826a3cc3b2437a39..240c82bea5cc04cd5456bd54fc8a213ea2f6c448 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 }); diff --git a/src/Sema.zig b/src/Sema.zig index 8b6f6d4a9fa1d858292547c608f761313ee6aa4e..d2b2a665e65592888a3d5968b7d8f8a3cb5f8e51 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5303,8 +5303,25 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A 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| { + if (lhs_val.isUndef() or rhs_val.isUndef()) { + return sema.addConstUndef(sema.typeOf(lhs)); + } + return sema.mod.fail(&block.base, src, "TODO implement comptime shr", .{}); + } + } + + try sema.requireRuntimeBlock(block, src); + return block.addBinOp(.shr, lhs, rhs); } fn zirBitwise( @@ -6001,13 +6018,33 @@ 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 { + if (operand.zigTypeTag() != .Int) return sema.mod.fail( + &block.base, + src, + "bit shifting operation expected integer type, found '{}'", + .{operand}, + ); + + 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); } fn zirTypeofPeer( diff --git a/src/codegen.zig b/src/codegen.zig index d5b106dbe308b3b15387d6159a708b26944bc2db..584b2bf8f4d63214251dcbf4936308c0c8d221d8 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), @@ -1270,6 +1272,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) { diff --git a/src/codegen/c.zig b/src/codegen/c.zig index a67e2438c24f1b2acb33e28e52d8625a036b23f0..d3417d1567e3e5f19cf91de069e2db696f4389ef 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -871,6 +871,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), diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 4f9a24f80c973bdef6f8d8b79d579e874d34ac82..4b5ac9efe9511c5130f5edf37d6d5b7990a7caa4 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -993,6 +993,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), @@ -1736,6 +1739,35 @@ 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); + return self.builder.buildShl(lhs, 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 da02e56ac8f94bb7e381df198617d1098121c9aa..d33ca29d4f751f4af81e6d242d021015ba150c23 100644 --- a/src/codegen/llvm/bindings.zig +++ b/src/codegen/llvm/bindings.zig @@ -290,6 +290,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, @@ -381,6 +389,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/print_air.zig b/src/print_air.zig index 66490b6512a8fd654295744e1be98a3c97aad2b0..738453464b02fae25c6aa1c50929db1ad61a56a9 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, diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index aa1022257b208e0d469b5defe12cf2643532dbb2..5025d2ad9fdf40ef12435fe5f7be7d04646ec2ec 100644 --- a/test/stage2/cbe.zig +++ b/test/stage2/cbe.zig @@ -808,6 +808,20 @@ pub fn addCases(ctx: *TestContext) !void { }); } + { + var case = ctx.exeUsingLlvmBackend("shift right", linux_x64); + + case.addCompareOutput( + \\pub export fn main() void { + \\ var i: u32 = 16; + \\ assert(i >> 1, 8); + \\} + \\fn assert(a: u32, b: u32) void { + \\ if (a != b) unreachable; + \\} + , ""); + } + { var case = ctx.exeFromCompiledC("inferred error sets", .{}); diff --git a/test/stage2/llvm.zig b/test/stage2/llvm.zig index 0e8e0036e391945234e2ba1e730bf6a7f99b79e1..e49641b99767200ede8fae2c18fe319751633f03 100644 --- a/test/stage2/llvm.zig +++ b/test/stage2/llvm.zig @@ -28,6 +28,20 @@ pub fn addCases(ctx: *TestContext) !void { , ""); } + { + var case = ctx.exeUsingLlvmBackend("shift right", linux_x64); + + case.addCompareOutput( + \\pub export fn main() void { + \\ var i: u32 = 16; + \\ assert(i >> 1, 8); + \\} + \\fn assert(a: u32, b: u32) void { + \\ if (a != b) unreachable; + \\} + , ""); + } + { var case = ctx.exeUsingLlvmBackend("llvm hello world", linux_x64); -- 2.54.0 From 2e22f7e5a5ff51aa4a1672e011cdc07b08a9a661 Mon Sep 17 00:00:00 2001 From: Jacob G-W Date: Thu, 19 Aug 2021 13:04:52 -0400 Subject: [PATCH 04/54] stage2: implement shl This is implemented in the llvm and cbe backends. x86_64 will take a bit more time. --- src/Sema.zig | 22 +++++++++++++++++++--- src/codegen/llvm.zig | 8 +++++++- test/stage2/cbe.zig | 17 ++++++++++++++--- test/stage2/llvm.zig | 11 ++++++++++- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index d2b2a665e65592888a3d5968b7d8f8a3cb5f8e51..360d936b61d0667d45a175391f56a4b8f1f33e36 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5294,9 +5294,25 @@ 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 { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 4b5ac9efe9511c5130f5edf37d6d5b7990a7caa4..632b275704924c7a7e20aad982959a2b62133a04 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1745,7 +1745,13 @@ pub const FuncGen = struct { 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); - return self.builder.buildShl(lhs, 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 { diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index 5025d2ad9fdf40ef12435fe5f7be7d04646ec2ec..c2c82c20e63235ce29127fd52f4a33b2cc3f8aa9 100644 --- a/test/stage2/cbe.zig +++ b/test/stage2/cbe.zig @@ -809,12 +809,23 @@ pub fn addCases(ctx: *TestContext) !void { } { - var case = ctx.exeUsingLlvmBackend("shift right", linux_x64); - + var case = ctx.exeFromCompiledC("shift right + left", .{}); case.addCompareOutput( - \\pub export fn main() void { + \\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; diff --git a/test/stage2/llvm.zig b/test/stage2/llvm.zig index e49641b99767200ede8fae2c18fe319751633f03..9e6e938a8cd1040e455aa6c7c846ca57b33d1430 100644 --- a/test/stage2/llvm.zig +++ b/test/stage2/llvm.zig @@ -29,7 +29,7 @@ pub fn addCases(ctx: *TestContext) !void { } { - var case = ctx.exeUsingLlvmBackend("shift right", linux_x64); + var case = ctx.exeUsingLlvmBackend("shift right + left", linux_x64); case.addCompareOutput( \\pub export fn main() void { @@ -40,6 +40,15 @@ pub fn addCases(ctx: *TestContext) !void { \\ if (a != b) unreachable; \\} , ""); + case.addCompareOutput( + \\pub export fn main() void { + \\ var i: u32 = 16; + \\ assert(i << 1, 32); + \\} + \\fn assert(a: u32, b: u32) void { + \\ if (a != b) unreachable; + \\} + , ""); } { -- 2.54.0 From 2f6dbaa0ea7307dd6806082b07266a43db5da950 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Fri, 13 Aug 2021 17:03:27 -0700 Subject: [PATCH 05/54] fs.Dir.walk: Do not close the initial dir during/after walking it Closing the initial directory was unexpected to me, and does not mesh very well with how the rest of the Dir API works. Fixes #9556 --- lib/std/build.zig | 3 ++- lib/std/fs.zig | 13 +++++++++++-- lib/std/fs/test.zig | 11 ++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/std/build.zig b/lib/std/build.zig index efb305d4a3e804a33f5e2b2989d3af71899a0161..b06ef55db49c09bf161445f1e7fcf01143d13ec3 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -3026,7 +3026,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| { diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 0d5db65011599315e7d4c57225e327caa441ed14..494d871974d373ee2c371af01aef2c20dc10ceb9 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -795,22 +795,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(); diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 7cc43bbb362d5ba5fea03dabd60862c745d0d086..26abbe5158f1a3c29432d012bc15f85a52ae4998 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -909,11 +909,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 +938,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; -- 2.54.0 From 8c39ab2659a2bdc741c0ce51014977fb9bebe2ab Mon Sep 17 00:00:00 2001 From: Isaac Yonemoto Date: Tue, 15 Jun 2021 07:57:48 -0500 Subject: [PATCH 06/54] enables user-custom code to work with LI and SI --- lib/std/debug.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index c3ef9dec4c8ef3fce400853e8c7024b9a5b009f3..aa7a979f8ff851996f2760e42e3248401c527bb1 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -36,7 +36,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 +47,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(); } -- 2.54.0 From e94f3c4e25de123f5d19efdf2e068f7fd222f07e Mon Sep 17 00:00:00 2001 From: Samadi van Koten Date: Mon, 7 Jun 2021 22:09:53 +0100 Subject: [PATCH 07/54] Add std.io.Reader.readUntilDelimiter() --- lib/std/io/reader.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/std/io/reader.zig b/lib/std/io/reader.zig index 920b82e420e4101b4175e604beaeb1a0e495f6b6..0846b14650bd01431f65c580be95ec1ddfa5ac87 100644 --- a/lib/std/io/reader.zig +++ b/lib/std/io/reader.zig @@ -143,6 +143,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 -- 2.54.0 From ddaca728647c85d77706aead2f7e5d83714cb7fc Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 20 Aug 2021 17:02:14 +0700 Subject: [PATCH 08/54] Make clearer inline code blocks in language reference paragraphs (#9317) * Make clearer inline code blocks in language reference paragraphs This commit makes the inline code blocks within paragraphs standout against the descriptive text. The code blocks within tables are left un-styled. The line-height of the paragraphs has been set to 1.7 based on recommendations from MDN Web Docs and W3C. The value is unitless based on the recommendation. Closes #9316, #6313 * Make clearer inline code blocks in language reference paragraphs Goal: To improve legibility of inline code blocks in the language reference. This commit alters the styles of code HTML elements in paragraphs, unordered lists, ordered lists, tables, and preformatted text elements. Most of the changes here are taken from suggestions from @dbandstra on GitHub in response to a code review. * p, ul, ol, but not #toc are set to the same line-height * p, ul, ol, and table have the same inline code styles * The inline code background color set to match the preformatted code blocks in the light theme and dark theme. The border colors are adjusted as well. * The preformatted code block font size is set to default. The 12pt setting was removed. The line-height of paragraphs is set to 1.5. This value is chosen based on recommendations from W3C [1] via MDN Web Docs [2] and the contents of the language reference. The MDN Web Docs offers two recommendations: 1. Use a unitless number for line-height. 2. Use a minimum value of 1.5 for main paragraph content. [1] https://www.w3.org/TR/WCAG21/#visual-presentation [2] https://developer.mozilla.org/en-US/docs/Web/CSS/line-height Closes #6313, #9316 * Set language reference line-height and pre code border color This commit is an update to a group of commits with the goal of improving the legibility of the language reference. In this commit, the line-height is now set in the `#contents` ID and reset to normal for preformatted code blocks. This change better separates lines of all main content text for legibility. Closes: #9316, #6313 * Style the language reference code elements This commit sets the style of the HTML code element. Since preformatted code blocks have an overriding style, this is safe to set for all inline code elements. --- doc/langref.html.in | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 386fe9f41a9cadb64029b8c08e5f15fa818500a4..8626a566d2c8c23f3a0703076db4020d262d4903 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; -- 2.54.0 From 0cecdca6a24d5009d543962f62c907aa45ec82ff Mon Sep 17 00:00:00 2001 From: Tom Maenan Read Cutting Date: Mon, 28 Jun 2021 21:48:59 +0100 Subject: [PATCH 09/54] Resolve order-of-call dependencies in build.zig --- lib/std/build.zig | 56 ++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/std/build.zig b/lib/std/build.zig index b06ef55db49c09bf161445f1e7fcf01143d13ec3..0a59c1da6ddad801a7e4cb2c210e0c3d75700b6e 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1735,7 +1735,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; } @@ -2247,28 +2246,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 +2299,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)), @@ -2719,6 +2721,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| { -- 2.54.0 From cfb2827b0a9efaf3937db27dbe3352cbb612466b Mon Sep 17 00:00:00 2001 From: bnprks Date: Wed, 9 Jun 2021 00:37:07 -0700 Subject: [PATCH 10/54] Clarify async/await language documentation. The async/await documentation was somewhat hard for me to follow when first learning. Two particular sticking points were 1. The alphabet example constructing the string "abcdefghi" breaks the stated rule that every async has a matching await. 2. It was somewhat unclear to me what the rules for control flow were around async/await constructs. I've tried to improve this documentation with some minimal explanatory edits, which are correct to the best of my beginner's understanding & experimentation. --- doc/langref.html.in | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 8626a566d2c8c23f3a0703076db4020d262d4903..3691cbba2848846948e3ad435386ec8070a45e68 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -6645,14 +6645,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. @@ -6755,7 +6762,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"); @@ -6790,7 +6804,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. -- 2.54.0 From b2e970d157343919ea2be44b3ebe4c519324bd4e Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Fri, 20 Aug 2021 17:52:48 +0600 Subject: [PATCH 11/54] std.json: Add support for recursive objects to std.json.parse (#9307) * Add support for recursive objects to std.json.parse * Remove previously defined error set * Try with function which returns an error set * Don't analyze already inferred types * Add comptime to inferred_type parameter * Make ParseInternalError to accept only a single argument * Add public `ParseError` for `parse` function * Use error.Foo syntax for errors instead of a named error set * Better formatting * Update to latest code changes --- lib/std/fmt.zig | 1 + lib/std/fmt/parse_float.zig | 4 +- lib/std/json.zig | 132 ++++++++++++++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 5 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 5cbdc57832f6746727da6505ca2f1446ffb050db..a9895e270aabd71dbb024695daa71b7c98ca4399 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -1757,6 +1757,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/parse_float.zig b/lib/std/fmt/parse_float.zig index 6178398b1789711f3a86cdc1f80b129e2a196fb9..ed6224b4b91cdf54463af0ead693d12c5f4ba90e 100644 --- a/lib/std/fmt/parse_float.zig +++ b/lib/std/fmt/parse_float.zig @@ -349,7 +349,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/json.zig b/lib/std/json.zig index 7aac61681dc41464dfd5f83162a5e906845f7497..656c91c08021952edd4474f835b06f6db62d90fa 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1468,7 +1468,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 +1532,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 +1873,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 +2264,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 +2540,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; -- 2.54.0 From 7aecf90d2eeead6796569713635f523cbe17295e Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Thu, 19 Aug 2021 22:43:25 +0200 Subject: [PATCH 12/54] stage2 ARM: add lsl, lsr, asr, ror psuedo-instructions --- src/codegen/arm.zig | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/codegen/arm.zig b/src/codegen/arm.zig index 891a9e100bb58a531711bf2b1cd3fbf75405fa31..d30479e1f1a55544499de4802d91ae2c875043bc 100644 --- a/src/codegen/arm.zig +++ b/src/codegen/arm.zig @@ -1142,6 +1142,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" { @@ -1262,6 +1335,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| { -- 2.54.0 From 2f1abd919a8465e515875cd08816778df795aabe Mon Sep 17 00:00:00 2001 From: rgreenblatt Date: Sat, 26 Jun 2021 10:35:39 -0500 Subject: [PATCH 13/54] Fix issue where root.os.panic could return --- lib/std/builtin.zig | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 6643e07837e5e759d595deae2992a95d2e410542..91b0adf0e45e06e86d107cc8fb6724f8a3071b5b 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -671,7 +671,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 +689,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) { -- 2.54.0 From f9e50a5830ab9a9ce0cb3e7eeb5e8da845926867 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Fri, 20 Aug 2021 23:17:46 +0200 Subject: [PATCH 14/54] stage2 ARM: implement bitshifting for 32-bit integers --- src/codegen.zig | 70 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/src/codegen.zig b/src/codegen.zig index f4306c5f2ba21cf5cca46dcef20a596786bc24cb..39fff7fab66dd63bf53b660e0a254876f9631670 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -1592,15 +1592,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; @@ -1617,7 +1655,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}) }; @@ -1656,7 +1694,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}) }; @@ -1683,6 +1721,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { rhs_mcv, swap_lhs_and_rhs, op, + signedness, ); return dst_mcv; } @@ -1694,6 +1733,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); @@ -1739,6 +1779,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 } } @@ -2989,7 +3050,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 }, -- 2.54.0 From 224fe49be23c44095d39297a4986782bd19ce8b2 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Fri, 20 Aug 2021 23:37:41 +0200 Subject: [PATCH 15/54] stage2 ARM: add test cases for bit shifts --- test/stage2/arm.zig | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/stage2/arm.zig b/test/stage2/arm.zig index 103b058a547c119f7472b955827c6e0ebd31ffa8..48c86f1590dac004450f4b905de0db587f79869b 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 + \\} + , + "", + ); } { @@ -429,4 +471,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 + \\ + , + ); + } } -- 2.54.0 From 0cd361219c107bce48f2d7b44c6f3dd05ea6ccf4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 20 Aug 2021 15:23:55 -0700 Subject: [PATCH 16/54] stage2: field type expressions support referencing locals The big change in this commit is making `semaDecl` resolve the fields if the Decl ends up being a struct or union. It needs to do this while the `Sema` is still in scope, because it will have the resolved AIR instructions that the field type expressions possibly reference. We do this after the decl is populated and set to `complete` so that a `Decl` may reference itself. Everything else is fixes and improvements to make the test suite pass again after making this change. * New AIR instruction: `ptr_elem_ptr` - Implemented for LLVM backend * New Type tag: `type_info` which represents `std.builtin.TypeInfo`. It is used by AstGen for the operand type of `@Type`. * ZIR instruction `set_float_mode` uses `coerced_ty` to avoid superfluous `as` instruction on operand. * ZIR instruction `Type` uses `coerced_ty` to properly handle result location type of operand. * Fix two instances of `enum_nonexhaustive` Value Tag not handled properly - it should generally be handled the same as `enum_full`. * Fix struct and union field resolution not copying Type and Value objects into its Decl arena. * Fix enum tag value resolution discarding the ZIR=>AIR instruction map for the child Sema, when they still needed to be accessed. * Fix `zirResolveInferredAlloc` use-after-free in the AIR instructions data array. * Fix `elemPtrArray` not respecting const/mutable attribute of pointer in the result type. * Fix LLVM backend crashing when `updateDeclExports` is called before `updateDecl`/`updateFunc` (which is, according to the API, perfectly legal for the frontend to do). * Fix LLVM backend handling element pointer of pointer-to-array. It needed another index in the GEP otherwise LLVM saw the wrong type. * Fix LLVM test cases not returning 0 from main, causing test failures. Fixes a regression introduced in 6a5094872f10acc629543cc7f10533b438d0283a. * Implement comptime shift-right. * Implement `@Type` for integers and `@TypeInfo` for integers. * Implement union initialization syntax. * Implement `zirFieldType` for unions. * Implement `elemPtrArray` for a runtime-known operand. * Make `zirLog2IntType` support RHS of shift being `comptime_int`. In this case it returns `comptime_int`. The motivating test case for this commit was originally: ```zig test "example" { var l: List(10) = undefined; l.array[1] = 1; } fn List(comptime L: usize) type { var T = u8; return struct { array: [L]T, }; } ``` However I changed it to: ```zig test "example" { var l: List = undefined; l.array[1] = 1; } const List = blk: { const T = [10]u8; break :blk struct { array: T, }; }; ``` Which ended up being a similar, smaller problem. The former test case will require a similar solution in the implementation of comptime function calls - checking if the result of the function call is a struct or union, and using the child `Sema` before it is destroyed to resolve the fields. --- lib/std/builtin.zig | 2 +- src/Air.zig | 14 +- src/AstGen.zig | 64 +-- src/Liveness.zig | 4 + src/Module.zig | 320 +-------------- src/Sema.zig | 727 ++++++++++++++++++++++++++------- src/Zir.zig | 13 +- src/codegen.zig | 10 + src/codegen/c.zig | 8 + src/codegen/llvm.zig | 35 +- src/print_air.zig | 16 +- src/type.zig | 39 ++ src/value.zig | 30 ++ test/behavior.zig | 3 +- test/behavior/array.zig | 484 ---------------------- test/behavior/array_stage1.zig | 489 ++++++++++++++++++++++ test/behavior/eval.zig | 18 + test/stage2/llvm.zig | 6 +- 18 files changed, 1295 insertions(+), 987 deletions(-) create mode 100644 test/behavior/array_stage1.zig diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 91b0adf0e45e06e86d107cc8fb6724f8a3071b5b..0d92157d31a4e2a856f9a3d2fa3dae4c7f3cad01 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -237,7 +237,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 diff --git a/src/Air.zig b/src/Air.zig index 2c5235e4a1c8b71a4454eee03fbe36b5011509b4..81d220ba597d7e84571b479b672f960701e697ec 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -286,6 +286,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. @@ -410,6 +414,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 @@ -482,6 +491,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, @@ -527,8 +537,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 e3f33ec332ad743c1c82049dea6da5184e8db232..2b2bbd4f2275d18453dbb5967d653e1ff05b9958 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -7102,38 +7102,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), diff --git a/src/Liveness.zig b/src/Liveness.zig index 240c82bea5cc04cd5456bd54fc8a213ea2f6c448..f6d51e58b4fe4e6fcc3812bdcd3eeefd9152891d 100644 --- a/src/Liveness.zig +++ b/src/Liveness.zig @@ -330,6 +330,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 319363e9b867f849663a8e90dd5fc959e8683b55..d55931bec8b9678b676367acfee94ee54ad573d2 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -554,8 +554,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 +660,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`. @@ -3091,6 +3092,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 +3197,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) { @@ -4450,309 +4463,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 360d936b61d0667d45a175391f56a4b8f1f33e36..78f09486233f75a819bedb3e8e7a9acdb1513196 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1032,25 +1032,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 +1061,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; @@ -1466,8 +1465,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 +1479,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, .{ @@ -5329,10 +5328,16 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A 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(sema.typeOf(lhs)); + return sema.addConstUndef(lhs_ty); } - return sema.mod.fail(&block.base, src, "TODO implement comptime shr", .{}); + // 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); } } @@ -6008,6 +6013,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), }), @@ -6047,20 +6074,24 @@ fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil } fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref { - if (operand.zigTypeTag() != .Int) return sema.mod.fail( - &block.base, - src, - "bit shifting operation expected integer type, found '{}'", - .{operand}, - ); - - var count: u16 = 0; - var s = operand.bitSize(sema.mod.getTarget()) - 1; - while (s != 0) : (s >>= 1) { - count += 1; + 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}, + ), } - const res = try Module.makeIntType(sema.arena, .unsigned, count); - return sema.addType(res); } fn zirTypeofPeer( @@ -6517,99 +6548,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); - } - found_fields[field_index] = item.data.field_type; - field_inits[field_index] = sema.resolveInst(item.data.init); - } - - var root_msg: ?*Module.ErrorMsg = null; + const field_index = union_obj.fields.getIndex(field_name) orelse + return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); - 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 (is_ref) { + return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true union", .{}); } - } - 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; + 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, + }), + ); } - } 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 union values", .{}); } - - 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 { @@ -6647,17 +6713,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( @@ -6732,7 +6806,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 { @@ -8152,24 +8273,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( @@ -9177,22 +9309,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 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.mod.analyzeStructFields(struct_obj); + try sema.analyzeStructFields(block, struct_obj); struct_obj.status = .have_field_types; - return ty; }, + .@"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, + } + }, + .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"), @@ -9205,18 +9377,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, } @@ -9232,6 +9398,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, @@ -9344,6 +9769,7 @@ fn typeHasOnePossibleValue( .call_options, .export_options, .extern_options, + .type_info, .@"anyframe", .anyframe_T, .many_const_pointer, @@ -9528,6 +9954,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/Zir.zig b/src/Zir.zig index 1aed609de9d5484f7154e3730eb40dcfed32fd25..2110122580365be8a2bba7f596e8de1681cae5b0 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -687,14 +687,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 +1703,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 +1974,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 f4306c5f2ba21cf5cca46dcef20a596786bc24cb..b2f0e453eab8b7627b4a099f71a5ddfa6a203b75 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -862,6 +862,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 @@ -1419,6 +1420,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; diff --git a/src/codegen/c.zig b/src/codegen/c.zig index d3417d1567e3e5f19cf91de069e2db696f4389ef..e7994ffd06d4675b3d3adc895f217affb9585a77 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -913,6 +913,7 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM .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]["), @@ -960,6 +961,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)) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 632b275704924c7a7e20aad982959a2b62133a04..745fb036db03428f1f7449aead429fc242ed0ace 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -432,6 +432,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( @@ -440,7 +442,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); @@ -1041,6 +1045,7 @@ pub const FuncGen = struct { .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), @@ -1296,11 +1301,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)) diff --git a/src/print_air.zig b/src/print_air.zig index 738453464b02fae25c6aa1c50929db1ad61a56a9..20badcdc31c551c9057b86a5446a1b9260c09c5d 100644 --- a/src/print_air.zig +++ b/src/print_air.zig @@ -175,6 +175,7 @@ const Writer = struct { .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), @@ -239,10 +240,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/type.zig b/src/type.zig index 41f392c04ad91b2a8fc67f415e489fcd63afc7bf..467e9c931b2cc228d1974ed40a874e8de7151962 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 562d7171e816c61734825f700ca8b5aefd78b225..7b3056bfcf8c3c9defbfebab442b1c95f97e74e2 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, @@ -221,6 +222,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"), @@ -402,6 +404,7 @@ pub const Value = extern union { .call_options_type, .export_options_type, .extern_options_type, + .type_info_type, .generic_poison, => unreachable, @@ -585,6 +588,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 {}{}"), @@ -743,6 +747,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; @@ -1514,6 +1519,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 bb55ec83f13be2b4bd1d6d9b3fefacfadf09b750..7836380c1370a0f122c9db3c3b23caee9877a38a 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 84a2cdb36c63d6be5cf8ccce52a6e370671ca51e..232ba87f55f361decd1cce08790098edcac20864 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 0000000000000000000000000000000000000000..84a2cdb36c63d6be5cf8ccce52a6e370671ca51e --- /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/eval.zig b/test/behavior/eval.zig index a97aab7bb3ddc41b806bbbbba3741830e13f2b3f..67103e01ff4dd5a2790e4a7fc9ef4d5ad711f7b5 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -130,3 +130,21 @@ 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, + }; +}; diff --git a/test/stage2/llvm.zig b/test/stage2/llvm.zig index 9e6e938a8cd1040e455aa6c7c846ca57b33d1430..09649f518c5ae757c206f3b3c03b5ebd432d2973 100644 --- a/test/stage2/llvm.zig +++ b/test/stage2/llvm.zig @@ -32,18 +32,20 @@ pub fn addCases(ctx: *TestContext) !void { var case = ctx.exeUsingLlvmBackend("shift right + left", linux_x64); case.addCompareOutput( - \\pub export fn main() void { + \\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() void { + \\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; -- 2.54.0 From e48d7bbb99a81d9e6058aa764266dcc3dbe71644 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Wed, 18 Aug 2021 15:09:21 +0200 Subject: [PATCH 17/54] stage2 ARM: Implement loading from memory --- src/codegen.zig | 50 ++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/codegen.zig b/src/codegen.zig index bc815c1f8d6b6de0fa4d61d52233a9a32024ceb8..dd7f1d55b725b02ede960754c72cb5838382aed7 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -1469,7 +1469,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, @@ -1486,11 +1486,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", .{}); @@ -3884,15 +3898,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 }); }, @@ -4060,15 +4069,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 }); }, -- 2.54.0 From 5806c386eb640247f6aa8983132c6b193195ea4a Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Tue, 17 Aug 2021 11:06:55 +0200 Subject: [PATCH 18/54] stage2 codegen: re-allocate result register in finishAir 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. --- src/codegen.zig | 14 ++++++++++++++ test/stage2/arm.zig | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/codegen.zig b/src/codegen.zig index dd7f1d55b725b02ede960754c72cb5838382aed7..ca7a04a4a0e5bc93dd9a3a60f271bcefce9b8124 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -973,6 +973,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(); } diff --git a/test/stage2/arm.zig b/test/stage2/arm.zig index 48c86f1590dac004450f4b905de0db587f79869b..912e77ebae0474b4a133313d4842f57be3d1c83f 100644 --- a/test/stage2/arm.zig +++ b/test/stage2/arm.zig @@ -361,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 + \\} + , + "", + ); } { -- 2.54.0 From 6c55d854cffbe7a518e8ec62f746585ddc68ebbf Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Fri, 20 Aug 2021 09:11:04 -0600 Subject: [PATCH 19/54] Add compstui.def The compstui library contains 4 Windows functions which were recently added to the win32metadta project. I copied this def file from the mingw-w64 project. --- lib/libc/mingw/lib-common/compstui.def | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/libc/mingw/lib-common/compstui.def diff --git a/lib/libc/mingw/lib-common/compstui.def b/lib/libc/mingw/lib-common/compstui.def new file mode 100644 index 0000000000000000000000000000000000000000..240a6ccc9a490f0fe8d685034cd63027dfaa1b49 --- /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 -- 2.54.0 From f0176eec4a744c17fc49cbd63c67179887005935 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 20 Aug 2021 17:44:03 -0700 Subject: [PATCH 20/54] stage2: support comptime fn call returning type ...when the field type expressions reference locals as well as comptime function parameters. --- src/Sema.zig | 13 ++++++++++++- test/behavior/generics.zig | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Sema.zig b/src/Sema.zig index 78f09486233f75a819bedb3e8e7a9acdb1513196..8ffc828fba118c3159bd599e4802a292f19fe538 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2623,7 +2623,18 @@ fn analyzeCall( 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); + const result = try sema.analyzeBlockBody(block, call_src, &child_block, merges); + + // 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 :res result; } 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; diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index 67fb1def8bfdd9c24704a8598d763303975a20cc..2d487a6f1608bab48e40270b0918379144053c87 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -78,3 +78,21 @@ 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: List(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 List(comptime L: usize) type { + var T = u8; + return struct { + array: [L]T, + }; +} -- 2.54.0 From bbb96e112cc555fd63fe305398c5b89b778e9c81 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sat, 21 Aug 2021 10:17:22 +0900 Subject: [PATCH 21/54] build: allow specifying -mexec-model flag. Signed-off-by: Takeshi Yoneda --- lib/std/build.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/std/build.zig b/lib/std/build.zig index 0a59c1da6ddad801a7e4cb2c210e0c3d75700b6e..013770bbece61ffb7ed699c8e3eb142d3ecb6d26 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1432,6 +1432,7 @@ 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, @@ -2549,6 +2550,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"); -- 2.54.0 From 4c18da1ef3ef21033394041be21774bf13882b54 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Sat, 14 Aug 2021 13:58:46 +0200 Subject: [PATCH 22/54] Fix args when calling clang::ASTUnit::LoadFromCommandLine. clang::ASTUnit::LoadFromCommandLine interprets the first argument as the name of program (like the main function). This change shifts the arguments passing "" for the first argument. --- src/Compilation.zig | 1 + src/main.zig | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Compilation.zig b/src/Compilation.zig index 7987ed95df8ab80dacf530099d97f5017a0a7eb7..7dc726aeb2691c49c1d53b2c3513acc23667a609 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/main.zig b/src/main.zig index 285b6d23161c6b3a71aaa67a6a095d874c5ac396..44b3a0515c7dd0ebfc9ed8425095f59ebc968a10 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(); -- 2.54.0 From d57c0cc3bfeff9af297279759ec2b631e6d95140 Mon Sep 17 00:00:00 2001 From: Michael Dusan Date: Mon, 19 Jul 2021 13:28:03 -0400 Subject: [PATCH 23/54] dragonfly: port libc++ Used https://github.com/DragonFlyBSD/DPorts/tree/master/devel/libc++/files for hints as to which patches were needed. --- lib/libcxx/include/__config | 13 +++++++------ lib/libcxx/include/__locale | 6 +++--- lib/libcxx/include/locale | 2 +- lib/libcxx/src/locale.cpp | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/libcxx/include/__config b/lib/libcxx/include/__config index a3838c89e8e168c605708f7866b198fcc42eb457..fbcd483ace8d32e1d3cdade817cae153c3614487 100644 --- a/lib/libcxx/include/__config +++ b/lib/libcxx/include/__config @@ -122,7 +122,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 @@ -366,7 +366,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 @@ -914,7 +914,7 @@ 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 @@ -925,7 +925,7 @@ typedef unsigned int char32_t; # endif #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__) #define _DECLARE_C99_LDBL_MATH 1 #endif @@ -954,11 +954,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 @@ -1125,6 +1125,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 77e5faab2676ddf2b75f56a9a0f88fa14af23b53..bb285a9d6219653da116037abcea1e8a3539179b 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 9a705c77cfab821df299b021cc2a5f57f4ecba93..2ffcf18848171cfaba88567bbfa1343f20238396 100644 --- a/lib/libcxx/include/locale +++ b/lib/libcxx/include/locale @@ -223,7 +223,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 a0209d0ce8cf4d320974e58d9fb809c8003fe1fb..989e522980fedfee2563137f89c373da34b2e531 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; -- 2.54.0 From 3b2520583390c7ebbb1e1ea458c9ced04180d9c4 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Sun, 1 Aug 2021 17:14:57 -0700 Subject: [PATCH 24/54] translate-c: allow string literals to be used as `char *` In C the type of string literals is `char *`, so when using them in a non-const context we have to cast the const away. Fixes #9126 --- src/translate_c.zig | 93 ++++++++++++++++++++++++++++++++++++--- src/translate_c/ast.zig | 15 ++++--- test/run_translated_c.zig | 18 ++++++++ 3 files changed, 115 insertions(+), 11 deletions(-) diff --git a/src/translate_c.zig b/src/translate_c.zig index e11fc5b736c6f4b4c0ff715300e9da6a489ad23a..4437913efe9d8aff7c9f10be6a9c22b65b610924 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -719,6 +719,44 @@ 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: @TypeOf(S.*) = S.*; +/// }).static; +fn stringLiteralToCharStar(c: *Context, str: Node) Error!Node { + const var_name = Scope.Block.StaticInnerName; + + const derefed = try Tag.deref.create(c.arena, str); + const var_type = try Tag.typeof.create(c.arena, derefed); + + const variables = try c.arena.alloc(Node, 1); + variables[0] = try Tag.var_decl.create(c.arena, .{ + .is_pub = false, + .is_const = false, + .is_extern = false, + .is_export = false, + .is_threadlocal = false, + .linksection_string = null, + .alignment = null, + .name = var_name, + .type = var_type, + .init = derefed, + }); + + 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 +817,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 +1141,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 +1846,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 +2566,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 +3513,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 +3893,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 +3918,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 +4278,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 fa6b749589f682d3694db6456859fd6b6598bade..f7d5022a2f5f35d619f5043db09baa63aa8b783f 100644 --- a/src/translate_c/ast.zig +++ b/src/translate_c/ast.zig @@ -558,9 +558,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 { @@ -1952,9 +1953,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 +1964,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 +2008,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, "}"); diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig index 2e579b06c7509cbc15cd720db65c6468dce2d2de..28ba7aa704ce552108f8a9036cc28292a76b6e95 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; + \\} + , ""); } -- 2.54.0 From 724995e892acd9d2981b55847f2ccb85af923d6b Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 20 Aug 2021 15:33:56 +0300 Subject: [PATCH 25/54] translate-c: avoid repeating string in type when making it mutable --- src/translate_c.zig | 18 ++---------------- src/translate_c/ast.zig | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/translate_c.zig b/src/translate_c.zig index 4437913efe9d8aff7c9f10be6a9c22b65b610924..0cc40cdfd4d94e8bbb4b019bbd310c94e71e916d 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -721,27 +721,13 @@ fn transQualTypeMaybeInitialized(c: *Context, scope: *Scope, qt: clang.QualType, /// This is used in global scope to convert a string literal `S` to [*c]u8: /// &(struct { -/// var static: @TypeOf(S.*) = S.*; +/// var static = S.*; /// }).static; fn stringLiteralToCharStar(c: *Context, str: Node) Error!Node { const var_name = Scope.Block.StaticInnerName; - const derefed = try Tag.deref.create(c.arena, str); - const var_type = try Tag.typeof.create(c.arena, derefed); - const variables = try c.arena.alloc(Node, 1); - variables[0] = try Tag.var_decl.create(c.arena, .{ - .is_pub = false, - .is_const = false, - .is_extern = false, - .is_export = false, - .is_threadlocal = false, - .linksection_string = null, - .alignment = null, - .name = var_name, - .type = var_type, - .init = derefed, - }); + 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, diff --git a/src/translate_c/ast.zig b/src/translate_c/ast.zig index f7d5022a2f5f35d619f5043db09baa63aa8b783f..e1da1c7d05127a33b63111aa1e328b2d4d77ea52 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, @@ -1230,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, @@ -1240,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; @@ -2145,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); @@ -2240,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); -- 2.54.0 From e3e6df17ed93db3ca53983d6149249746594e11c Mon Sep 17 00:00:00 2001 From: Aydin Mercan Date: Sat, 21 Aug 2021 18:35:07 +0300 Subject: [PATCH 26/54] linux: Add recent clone/clone3 and missing signalfd flags. The following flags have been introduced: - CLONE_PIDFD (>=5.2) - CLONE_INTO_CGROUP (>=5.7) - SFD_CLOEXEC and SFD_NONBLOCK (>=2.6.27) --- lib/std/os/bits/linux.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index fdf240e954454fec2c414a33f5fa2d0904379a5b..ffe74b74e9a0c7ca3cc7d19a58a076c27b1e3106 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -887,6 +887,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 +912,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 +1134,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, -- 2.54.0 From 27e321628587fd82b431dbbed1e6ba99e6df24a6 Mon Sep 17 00:00:00 2001 From: Martin Wickham Date: Thu, 3 Jun 2021 12:06:22 -0500 Subject: [PATCH 27/54] Add a flag to build a single-threaded compiler, for debugging --- build.zig | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index 449c6a7f1a794d3c976bf4bc9bc470081326488a..d727e1cac2c8278f73e1b8c9baa75815266268f5 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,6 +107,7 @@ 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; exe.addBuildOption(u32, "mem_leak_frames", mem_leak_frames); exe.addBuildOption(bool, "skip_non_native", skip_non_native); @@ -131,6 +135,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); @@ -296,7 +301,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 +318,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 +335,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, -- 2.54.0 From f28868e8fd4028cad29bd2de8c0aa1c1713c69dd Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Fri, 13 Aug 2021 12:52:36 -0600 Subject: [PATCH 28/54] mingw.zig: fix logic to add crt sources The current version of code uses isARM to check if we are compiling to any arm target then checks the target bit width to either add the 32-bit sources or 64-bit source. However, isARM only returns true for 32-bit targets, and isAARCH64 is for the 64-bit targets. I also replaced the unreachable with a @panic when we receive an unsupported arch because this code is reachable and should turn into an error. --- src/mingw.zig | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/mingw.zig b/src/mingw.zig index 42d1ac47dbafe3d3dafcf869857e7c7c8e618859..529025c51735fa66aaa7af3afabe0925d39f41e8 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); }, -- 2.54.0 From 2b40815a220bbbd657bfa441e304090f11f1eb4c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 21 Aug 2021 15:00:40 -0700 Subject: [PATCH 29/54] stage2: fix wrong value for Decl owns_tv In the case of a comptime function call of a function that returns a type, resulting in a compiler crash on deinit(). --- src/Module.zig | 1 - src/Sema.zig | 4 ++++ test/behavior/generics.zig | 25 +++++++++++++++++++++++-- test/behavior/generics_stage1.zig | 21 --------------------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index d55931bec8b9678b676367acfee94ee54ad573d2..29c091abd350715c33599e00e7fed0ccb419afa2 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4037,7 +4037,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; diff --git a/src/Sema.zig b/src/Sema.zig index 8ffc828fba118c3159bd599e4802a292f19fe538..36ac4d224dca9e9710a79985badeb13f2d323a1e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -866,6 +866,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 +987,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.* = .{ @@ -1152,6 +1154,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, @@ -1223,6 +1226,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| { diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index 2d487a6f1608bab48e40270b0918379144053c87..ef772deb4e9a93c09679c20e65d1f7cc92724382 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -80,7 +80,7 @@ fn max_f64(a: f64, b: f64) f64 { } test "type constructed by comptime function call" { - var l: List(10) = undefined; + var l: SimpleList(10) = undefined; l.array[0] = 10; l.array[1] = 11; l.array[2] = 12; @@ -90,9 +90,30 @@ test "type constructed by comptime function call" { try expect(ptr[2] == 12); } -fn List(comptime L: usize) type { +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 4b768a5b4ff1a4bd3b6bc50affc1a782acfc38e9..4fa52f5377a4589dd1076f954276ef342faf95e8 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, -- 2.54.0 From f378b0adce80aa6f85d9bf6bf97172426de2c719 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 21 Aug 2021 20:42:45 -0700 Subject: [PATCH 30/54] stage2: comptime function with the same args is memoized * Introduce `memoized_calls` to `Module` which stores all the comptime function calls that are cached. It is keyed on the `*Fn` and the comptime arguments, but it does not yet properly detect comptime function pointers and avoid memoizing in this case. So it will have false positives for when a comptime function call mutates data through a pointer parameter. * Sema: Add a new helper function: `resolveConstMaybeUndefVal` * Value: add `enumToInt` method and use it in `zirEnumToInt`. It is also used by the hashing function. * Value: fix representation of optionals to match error unions. Previously it would not handle nested optionals correctly. Now it matches the memory layout of error unions and supports nested optionals properly. This required changes in all the backends for generating optional constants. * TypedValue gains `eql` and `hash` methods. * Value: Implement hashing for floats, optionals, and enums. Additionally, the zig type tag is added to the hash, where it was not previously, so that values of differing types will get different hashes. --- src/Module.zig | 77 +++++++++++++++- src/Sema.zig | 159 +++++++++++++++++++++++++--------- src/TypedValue.zig | 15 +++- src/codegen/c.zig | 16 ++-- src/codegen/llvm.zig | 33 +++---- src/codegen/wasm.zig | 25 +++--- src/value.zig | 111 +++++++++++++++++++++--- test/behavior/eval.zig | 13 +++ test/behavior/eval_stage1.zig | 13 --- 9 files changed, 351 insertions(+), 111 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index 29c091abd350715c33599e00e7fed0ccb419afa2..4ed39c99546c1d6dcaf3fe7c90ba1ad44d32e051 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. @@ -2255,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 { diff --git a/src/Sema.zig b/src/Sema.zig index 36ac4d224dca9e9710a79985badeb13f2d323a1e..d543b59ac01ba6df2ac9c8283af6ef640418975e 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( @@ -2565,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 @@ -2589,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; }, @@ -2626,19 +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); - const result = try sema.analyzeBlockBody(block, call_src, &child_block, merges); - - // 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 :res result; + // 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; @@ -3305,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); @@ -3414,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), + ); } } @@ -3451,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); @@ -9095,7 +9170,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); diff --git a/src/TypedValue.zig b/src/TypedValue.zig index 48b2c04970d15593a420f73d40967f003cbec9d9..83242b5329427eb52025ca0b8c241ba9dc1c0f4e 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/codegen/c.zig b/src/codegen/c.zig index e7994ffd06d4675b3d3adc895f217affb9585a77..bc3e357827c1817b15118b109d72f24f61c93757 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 => { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 745fb036db03428f1f7449aead429fc242ed0ace..b80dcf0febafdafb65eb210abfad3629ff1bf40f 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -810,27 +810,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()) { diff --git a/src/codegen/wasm.zig b/src/codegen/wasm.zig index 4814ba0b55c51e5e8e0594666ee433a0a3dbf150..422afef9c40ce1d2e0049b4a77c4a7aa19a8fb3d 100644 --- a/src/codegen/wasm.zig +++ b/src/codegen/wasm.zig @@ -1198,20 +1198,21 @@ pub const Context = struct { // When constant has value 'null', set is_null local to '1' // and payload to '0' - if (val.tag() == .null_value) { - try writer.writeByte(wasm.opcode(.i32_const)); - try leb.writeILEB128(writer, @as(i32, 1)); - - const opcode: wasm.Opcode = buildOpcode(.{ - .op = .@"const", - .valtype1 = try self.typeToValtype(payload_type), - }); - try writer.writeByte(wasm.opcode(opcode)); - try leb.writeULEB128(writer, @as(u32, 0)); - } else { + 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(val, payload_type); + try self.emitConstant(payload_val, payload_type); + } else { + try writer.writeByte(wasm.opcode(.i32_const)); + try leb.writeILEB128(writer, @as(i32, 1)); + + const opcode: wasm.Opcode = buildOpcode(.{ + .op = .@"const", + .valtype1 = try self.typeToValtype(payload_type), + }); + try writer.writeByte(wasm.opcode(opcode)); + try leb.writeULEB128(writer, @as(u32, 0)); } }, else => |zig_type| return self.fail("Wasm TODO: emitConstant for zigTypeTag {s}", .{zig_type}), diff --git a/src/value.zig b/src/value.zig index 7b3056bfcf8c3c9defbfebab442b1c95f97e74e2..5ac9f142c46c64fa01128474d1e20f2392bc7122 100644 --- a/src/value.zig +++ b/src/value.zig @@ -133,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. @@ -238,6 +247,8 @@ pub const Value = extern union { .repeated, .eu_payload, .eu_payload_ptr, + .opt_payload, + .opt_payload_ptr, => Payload.SubValue, .bytes, @@ -459,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.* = .{ @@ -656,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; + }, }; } @@ -776,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()) { @@ -1132,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, @@ -1157,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"); @@ -1169,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"); @@ -1178,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"); @@ -1257,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, @@ -1354,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()) { - .undef => unreachable, - .unreachable_value => unreachable, - .inferred_alloc => unreachable, - .inferred_alloc_comptime => unreachable, .null_value => true, + .opt_payload => false, - else => false, + .undef => unreachable, + .unreachable_value => unreachable, + .inferred_alloc => unreachable, + .inferred_alloc_comptime => unreachable, + else => unreachable, }; } @@ -1390,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, }; } diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 67103e01ff4dd5a2790e4a7fc9ef4d5ad711f7b5..1b6540cd32a8b181752b755a57418bf9d3a18de6 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -148,3 +148,16 @@ const List = blk: { 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 3599d5a477a870aa74bbe7ede6d92e4fb1525740..644de50fd07558efd96f3ead11c57f3475a585fc 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; -- 2.54.0 From 4ac37eb484737e98269e198b31b81ee8e929b4f1 Mon Sep 17 00:00:00 2001 From: Jacob G-W Date: Mon, 16 Aug 2021 23:11:55 -0400 Subject: [PATCH 31/54] stage2 Air: add struct_field_ptr_index_{0..3} Since these are very common, it will save memory. --- src/Air.zig | 11 +++++++++++ src/Liveness.zig | 4 ++++ src/Sema.zig | 27 +++++++++++++++++++++------ src/codegen.zig | 19 ++++++++++++++++++- src/codegen/c.zig | 28 +++++++++++++++++++++++++--- src/codegen/llvm.zig | 14 ++++++++++++++ src/codegen/wasm.zig | 15 +++++++++++++-- src/print_air.zig | 4 ++++ test/stage2/cbe.zig | 13 +++++++++++++ 9 files changed, 123 insertions(+), 12 deletions(-) diff --git a/src/Air.zig b/src/Air.zig index 81d220ba597d7e84571b479b672f960701e697ec..6e4125be444586676a0f2730199aedc8e71b20c0 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -264,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, @@ -510,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, diff --git a/src/Liveness.zig b/src/Liveness.zig index f6d51e58b4fe4e6fcc3812bdcd3eeefd9152891d..6a47bfe59732961cb86f1a44136db2ea55dc8da1 100644 --- a/src/Liveness.zig +++ b/src/Liveness.zig @@ -282,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 }); diff --git a/src/Sema.zig b/src/Sema.zig index d543b59ac01ba6df2ac9c8283af6ef640418975e..a11bdec66dfc9cc1bfec7dedce44110fd752ba8c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -8119,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, } }, }); } diff --git a/src/codegen.zig b/src/codegen.zig index ca7a04a4a0e5bc93dd9a3a60f271bcefce9b8124..9103c7ad173fa993c82a87e14fa332b58edce711 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -855,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), @@ -1592,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 }); } diff --git a/src/codegen/c.zig b/src/codegen/c.zig index bc3e357827c1817b15118b109d72f24f61c93757..2084b1e1ce7a272a9f0b0353ed25522899c555ef 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -909,6 +909,12 @@ 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"), @@ -1651,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 b80dcf0febafdafb65eb210abfad3629ff1bf40f..d7aa2d45b338828e4bf770bc152af5f787156bd6 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1037,6 +1037,11 @@ 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), @@ -1350,6 +1355,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; diff --git a/src/codegen/wasm.zig b/src/codegen/wasm.zig index 422afef9c40ce1d2e0049b4a77c4a7aa19a8fb3d..bb0556723698ed75cd83dd671a9646a232299f01 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), @@ -1441,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/print_air.zig b/src/print_air.zig index 20badcdc31c551c9057b86a5446a1b9260c09c5d..276158f720cae212e53e881957af5a303b64dee1 100644 --- a/src/print_air.zig +++ b/src/print_air.zig @@ -169,6 +169,10 @@ 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, diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index c2c82c20e63235ce29127fd52f4a33b2cc3f8aa9..21270f130b94db95669506c87eab33d68a30b559 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; + \\} + , ""); } { -- 2.54.0 From 62e3d67605075f27134736917495e7a7a17869f6 Mon Sep 17 00:00:00 2001 From: Richard Eklycke Date: Sun, 22 Aug 2021 12:29:49 +0200 Subject: [PATCH 32/54] Fix typo introduced in 50a29f7 Now the last argument will be checked as well --- src/stage1/astgen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp index 44dc1080c2995dabb2615af30648c5ac95121639..e7c4eacb3f707efab96aaa49a70d72a4abd8cb57 100644 --- a/src/stage1/astgen.cpp +++ b/src/stage1/astgen.cpp @@ -4653,17 +4653,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, -- 2.54.0 From 72c4b80d31c3ccecbd8cf96e5afdf756e055dc6a Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 23 Aug 2021 05:22:53 +1000 Subject: [PATCH 33/54] std.os: (p)writev should perform partial writes if iov.len > IOV_MAX Co-authored-by: Veikka Tuominen --- lib/std/os.zig | 8 ++++---- lib/std/os/bits/darwin.zig | 1 + lib/std/os/bits/dragonfly.zig | 1 + lib/std/os/bits/freebsd.zig | 2 ++ lib/std/os/bits/netbsd.zig | 2 ++ lib/std/os/bits/wasi.zig | 2 ++ lib/std/os/test.zig | 14 ++++++++++++++ 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 5735539366e84f3856fd86758ae3de3ae83fdc1f..e85a6fe42fd1a35dbe955591024a9831733c91e6 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -787,7 +787,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 @@ -816,7 +816,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { } } - 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)) { @@ -954,7 +954,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, @@ -997,7 +997,7 @@ 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); diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index 91705c0d2e44561d81e9049b1639ec41ca4def7f..f39b5948d7d3d76b27ecee2eebd1d16717744c03 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -235,6 +235,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; diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index 573721749cd5f167ca81efe612b207afad704366..dfa54972f37cc3676572ed6b043de0e771ffded6 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -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 1805941993943c6dbef53fe710ede0f55dcdf472..b08c31c8e3b12f7bed1bd0af9a88b6f806a23d74 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -238,8 +238,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; diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index f3ece9349334ea529a953b9785e41c66e01151ab..af04d0536bf16665ded4d0bb75950e063e2de390 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -405,8 +405,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; diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig index 5102d9b439a5b67be9670a97f7f3685f7b3d797c..ece97eacce60576ce379dd4cd3f4fe5b3ad1f3f7 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -76,6 +76,8 @@ pub const kernel_stat = struct { } }; +pub const IOV_MAX = 1024; + pub const AT_REMOVEDIR: u32 = 0x4; pub const AT_FDCWD: fd_t = -2; diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 6184c9770699d6ad2fbeec833486716ce65601f6..fb23f4459aeec22c99324be225792e7a4352d10c 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -786,3 +786,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); +} -- 2.54.0 From c465b34d32725f1f0bd019f6ecb77ece6b667320 Mon Sep 17 00:00:00 2001 From: William Stein Date: Sun, 22 Aug 2021 23:31:21 -0700 Subject: [PATCH 34/54] Trivial typo "for for" --> "for" (also a few nearby run-on sentence). (#9610) --- lib/std/math.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/math.zig b/lib/std/math.zig index 9f92e2e82b221a43a7d56c53c7884bc1c124d019..55ef506366c88e2556edd6204c356601a0c503bd 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -111,11 +111,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 +138,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. /// -- 2.54.0 From d5ef5da5947d24792933847454c84daf1282b29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Mon, 23 Aug 2021 21:22:27 +0700 Subject: [PATCH 35/54] Update comment: s/var/anytype/ (#9611) --- lib/std/builtin.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 0d92157d31a4e2a856f9a3d2fa3dae4c7f3cad01..caf32890b6219f53f01219e1c9b8ad8e78698ec2 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -259,7 +259,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, }; -- 2.54.0 From bb38931c7146678548f63ae9ef71e534c7598fe3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 23 Aug 2021 15:30:57 -0700 Subject: [PATCH 36/54] stage1: `@intToEnum` implicitly does an `@intCast` This is a backwards-compatible language change. Previously, `@intToEnum` coerced its integer operand to the integer tag type of the destination enum type, often requiring the callsite to additionally wrap the operand in an `@intCast`. Now, the `@intCast` is implicit, and any integer operand can be passed to `@intToEnum`. The same as before, it is illegal behavior to pass any integer which does not have a corresponding enum tag. --- doc/langref.html.in | 6 ++++-- src/stage1/ir.cpp | 39 +++++++++++++++++++++++++-------------- test/behavior/enum.zig | 2 +- test/compile_errors.zig | 4 ++-- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 3691cbba2848846948e3ad435386ec8070a45e68..336db082f160de8669b52754be31368dfc267cf8 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3163,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 @@ -7972,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.

diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index b1583cc6b48b9e2d9f873f7bb3af6ee34086b291..830ce76708ca7f415654e2e92c4b474d6c9a9e58 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/test/behavior/enum.zig b/test/behavior/enum.zig index dbda9f3238122af416dced4e284aea36935dd189..fd526e1befca9cdef88cd473ba34de24f5bd8165 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/compile_errors.zig b/test/compile_errors.zig index 6075eee33ab3ecb90aae75b642c7934458064cf3..14d2a98e02880246dd076463f2bcb67dabf6cf67 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -7691,12 +7691,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", -- 2.54.0 From 9e3ec98937de07d0e06f483ba8f7e6592b4dd152 Mon Sep 17 00:00:00 2001 From: Frank Denis <124872+jedisct1@users.noreply.github.com> Date: Tue, 24 Aug 2021 02:06:02 +0200 Subject: [PATCH 37/54] Don't define valgrind_support on macOS (#9612) Unfortunately, Valgrind for macOS has been broken for years, and the Homebrew formula is only for Linux. --- src/stage1/target.cpp | 2 +- src/target.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stage1/target.cpp b/src/stage1/target.cpp index 6594eb57d5ef07f7aac5ba82b14963fde082deed..8415b1934e437f71de4b90346b645e4d2f3ced3c 100644 --- a/src/stage1/target.cpp +++ b/src/stage1/target.cpp @@ -919,7 +919,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 06483d68ffccbbd7529c2d7aecccb28f82334b0d..25a133f03b9dae13c9c142e82bf1601bf3ded474 100644 --- a/src/target.zig +++ b/src/target.zig @@ -163,7 +163,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, -- 2.54.0 From a98fa56ae9ad437d3e4241bc2c231e0745766ba9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 23 Aug 2021 17:06:56 -0700 Subject: [PATCH 38/54] std: [breaking] move errno to become an nonexhaustive enum The primary purpose of this change is to eliminate one usage of `usingnamespace` in the standard library - specifically the usage for errno values in `std.os.linux`. This is accomplished by truncating the `E` prefix from error values, and making errno a proper enum. A similar strategy can be used to eliminate some other `usingnamespace` sites in the std lib. --- CMakeLists.txt | 2 +- lib/std/Thread.zig | 166 +- lib/std/Thread/Condition.zig | 16 +- lib/std/Thread/Futex.zig | 78 +- lib/std/Thread/Mutex.zig | 32 +- lib/std/Thread/ResetEvent.zig | 24 +- lib/std/Thread/RwLock.zig | 24 +- lib/std/Thread/StaticResetEvent.zig | 10 +- lib/std/c.zig | 56 +- lib/std/c/darwin.zig | 4 +- lib/std/c/linux.zig | 4 +- lib/std/c/netbsd.zig | 4 +- lib/std/fs.zig | 56 +- lib/std/fs/wasi.zig | 8 +- lib/std/io/c_writer.zig | 26 +- lib/std/os.zig | 2594 +++++++++++------------ lib/std/os/bits/darwin.zig | 453 ++-- lib/std/os/bits/dragonfly.zig | 199 +- lib/std/os/bits/freebsd.zig | 221 +- lib/std/os/bits/haiku.zig | 215 +- lib/std/os/bits/linux.zig | 15 +- lib/std/os/bits/linux/errno-generic.zig | 462 ---- lib/std/os/bits/linux/errno-mips.zig | 143 -- lib/std/os/bits/linux/errno-sparc.zig | 145 -- lib/std/os/bits/linux/errno/generic.zig | 466 ++++ lib/std/os/bits/linux/errno/mips.zig | 147 ++ lib/std/os/bits/linux/errno/sparc.zig | 150 ++ lib/std/os/bits/netbsd.zig | 272 +-- lib/std/os/bits/openbsd.zig | 217 +- lib/std/os/bits/wasi.zig | 163 +- lib/std/os/bits/windows.zig | 174 +- lib/std/os/linux.zig | 15 +- lib/std/os/linux/bpf.zig | 62 +- lib/std/os/linux/io_uring.zig | 88 +- lib/std/os/linux/test.zig | 30 +- lib/std/os/wasi.zig | 2 +- lib/std/process.zig | 8 +- lib/std/special/compiler_rt/emutls.zig | 6 +- lib/std/time.zig | 2 +- lib/std/x/os/socket_posix.zig | 98 +- 40 files changed, 3459 insertions(+), 3398 deletions(-) delete mode 100644 lib/std/os/bits/linux/errno-generic.zig delete mode 100644 lib/std/os/bits/linux/errno-mips.zig delete mode 100644 lib/std/os/bits/linux/errno-sparc.zig create mode 100644 lib/std/os/bits/linux/errno/generic.zig create mode 100644 lib/std/os/bits/linux/errno/mips.zig create mode 100644 lib/std/os/bits/linux/errno/sparc.zig diff --git a/CMakeLists.txt b/CMakeLists.txt index 20d19fa167ac777082f91bdbfad6b868a3c45001..0e4d5cfb43139ef5f07bb23d3c327fc681f155fb 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/lib/std/Thread.zig b/lib/std/Thread.zig index cd742cc955cf6fcf0f26ad6675d64a6dcb7b8bcb..9d3b0cb1fc7d629341753d5f321046be7928a4ce 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -9,9 +9,10 @@ //! 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 +25,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 +40,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 +66,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 +90,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 +113,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 +155,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 +183,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 +202,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 +292,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 +615,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 +630,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 +644,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, } } @@ -937,13 +941,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 +986,9 @@ const LinuxThreadImpl = struct { tid, null, ))) { - 0 => continue, - os.EINTR => continue, - os.EAGAIN => continue, + .SUCCESS => continue, + .INTR => continue, + .AGAIN => continue, else => unreachable, } } @@ -1011,7 +1015,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 +1033,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 +1058,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 +1067,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 +1100,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 +1114,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/Condition.zig b/lib/std/Thread/Condition.zig index 8485f84aa4ce75a8b622ce0f31e5ed301f0bdafd..9513e794edaf7ce54ae76f32903827ae99b44546 100644 --- a/lib/std/Thread/Condition.zig +++ b/lib/std/Thread/Condition.zig @@ -81,17 +81,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 +115,9 @@ pub const AtomicCondition = struct { 0, null, ))) { - 0 => {}, - std.os.EINTR => {}, - std.os.EAGAIN => {}, + .SUCCESS => {}, + .INTR => {}, + .AGAIN => {}, else => unreachable, } }, @@ -136,8 +136,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 81dba07996639cc88b6d04c89e93294359bfeb5e..a896942d6ea7bccd046adec857a8588e0cf7d880 100644 --- a/lib/std/Thread/Futex.zig +++ b/lib/std/Thread/Futex.zig @@ -152,12 +152,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 +168,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 +215,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 +237,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 +255,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 +272,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 +297,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 +340,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 +375,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 35095b2a3cacabbee8f963ea7f9b9bc5d58d8e99..522d1fe4183d82ecb6b87e96c3259056e8c71a80 100644 --- a/lib/std/Thread/Mutex.zig +++ b/lib/std/Thread/Mutex.zig @@ -143,9 +143,9 @@ pub const AtomicMutex = struct { @enumToInt(new_state), null, ))) { - 0 => {}, - std.os.EINTR => {}, - std.os.EAGAIN => {}, + .SUCCESS => {}, + .INTR => {}, + .AGAIN => {}, else => unreachable, } }, @@ -164,8 +164,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 +182,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 +195,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 +206,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 356b8eb78df23d1fc9188319c4f05b2f041fd5c7..bbf9e7263a0cd429377607e38c1d7c67cbd66e59 100644 --- a/lib/std/Thread/ResetEvent.zig +++ b/lib/std/Thread/ResetEvent.zig @@ -130,7 +130,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 +147,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 +165,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 +177,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 1d606a9cf1ede77cb672da0e3d8e04bcc02b1ebc..0721aad3f7cc82987e6b0af2cd56ea27b2d90345 100644 --- a/lib/std/Thread/RwLock.zig +++ b/lib/std/Thread/RwLock.zig @@ -13,7 +13,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 +165,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/StaticResetEvent.zig b/lib/std/Thread/StaticResetEvent.zig index 40974938d04808daa988906a9dbe70b4cecef733..e15a6a0a5435e261a73e68505b104265eeb136c2 100644 --- a/lib/std/Thread/StaticResetEvent.zig +++ b/lib/std/Thread/StaticResetEvent.zig @@ -201,7 +201,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 +221,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/c.zig b/lib/std/c.zig index c8b3020dc79524224c1bb21f825c3e71884e8b22..700a1dc25090ed050cd39269b9a1179799aae52f 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -35,11 +35,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 +270,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 +339,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 22473a3899c603a4b6e74838791ee7433cbe0139..117172fc7b4e247edc77652c9d92b305327c05ba 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -193,8 +193,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/linux.zig b/lib/std/c/linux.zig index 694af28904b736d5c3a4beb8c06674b9de4e8b6d..2ce98e2246c57b14c9ff1fe77d292abb100e45a0 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -186,8 +186,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/netbsd.zig b/lib/std/c/netbsd.zig index 32b7cc69e382a99fea705501651c3be936f9ea93..07af1dc689855a05b95494ac44994f096065d3f7 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -95,5 +95,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/fs.zig b/lib/std/fs.zig index 494d871974d373ee2c371af01aef2c20dc10ceb9..cb33464dd2190f8d7aa1cf4caf8bbf5fe53a06e2 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -339,10 +339,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 +385,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 +457,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 +522,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 +655,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; @@ -2557,12 +2557,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/wasi.zig b/lib/std/fs/wasi.zig index 378e4a7bac31bfa14e76eeaf3a257c5c15ff0398..2bfc384773ce1ebff1b933dc8cc769118b509330 100644 --- a/lib/std/fs/wasi.zig +++ b/lib/std/fs/wasi.zig @@ -121,13 +121,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 +137,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/io/c_writer.zig b/lib/std/io/c_writer.zig index 9f551b08fcda8b081e027c61fd3680eead70c615..bbb7f1daf301a312ba2bc6de1cb427328c767d3d 100644 --- a/lib/std/io/c_writer.zig +++ b/lib/std/io/c_writer.zig @@ -17,19 +17,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/os.zig b/lib/std/os.zig index e85a6fe42fd1a35dbe955591024a9831733c91e6..7781233a490f3a7043ae59c98c25d00e10d6fd96 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -116,13 +116,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 +159,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 +175,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 +238,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 +255,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 +267,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 +342,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 +370,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 +407,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 +426,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 +469,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 +505,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 +558,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 +579,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 +620,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 +649,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 +723,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 +751,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), } } @@ -798,20 +798,20 @@ 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), } } @@ -820,20 +820,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { 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 +875,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 +913,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), } } @@ -971,23 +971,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), } } @@ -1002,22 +1002,22 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz 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 +1098,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 +1193,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 +1239,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 +1286,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 +1296,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 +1331,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 +1543,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 +1602,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 +1645,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 +1672,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 +1708,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 +1744,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 +1823,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 +1876,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 +1906,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 +1983,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 +2037,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 +2075,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 +2173,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 +2199,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 +2275,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 +2347,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 +2414,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 +2444,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 +2502,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 +2538,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 +2568,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 +2591,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 +2681,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 +2779,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 +2842,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 +2926,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 +2995,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 +3101,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 +3146,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 +3185,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 +3207,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 +3226,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 +3267,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 +3296,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 +3386,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 +3456,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 +3486,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 +3506,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 +3538,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 +3562,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 +3588,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 +3629,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 +3653,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 +3683,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 +3700,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 +3725,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 +3738,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 +3784,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 +3813,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 +3857,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 +3908,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 +3975,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 +3988,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 +4011,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 +4024,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 +4058,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 +4084,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 +4114,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 +4129,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 +4147,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 +4162,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 +4177,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 +4194,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 +4209,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 +4224,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 +4241,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 +4256,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 +4271,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 +4288,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 +4309,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 +4384,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 +4459,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 +4532,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 +4566,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 +4672,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 +4702,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 +4713,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 +4736,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 +4772,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 +4790,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 +4802,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 +4841,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 +4869,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 +4889,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 +5049,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 +5149,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 +5312,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 +5325,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 +5340,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 +5392,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 +5408,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 +5419,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 +5428,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 +5471,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 +5491,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 +5595,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 +5652,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 +5681,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 +5750,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 +5830,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 +5874,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 +5909,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 +5940,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 +5953,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 +5967,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 +5986,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 +6003,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 +6030,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 +6054,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 +6073,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 +6111,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 +6134,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 +6150,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 +6194,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/darwin.zig b/lib/std/os/bits/darwin.zig index f39b5948d7d3d76b27ecee2eebd1d16717744c03..35d507541e52ec0b0202e21cb51327fe5c9835f8 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -866,337 +866,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 dfa54972f37cc3676572ed6b043de0e771ffded6..cf647a8438283c75501868ba0ad25bf1ccca6621 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -25,103 +25,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; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index b08c31c8e3b12f7bed1bd0af9a88b6f806a23d74..b60676e266d7e5cf7c1ec68413c7ad9b15348966 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -887,127 +887,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 b3ea4aa0e2236e101e2eab99522edae9e6449342..8421c80a52b5c2c27683f6a297e4b44d4274793a 100644 --- a/lib/std/os/bits/haiku.zig +++ b/lib/std/os/bits/haiku.zig @@ -734,125 +734,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 ffe74b74e9a0c7ca3cc7d19a58a076c27b1e3106..1dbc552b3c589d032ddb3189f8eb407a9fa17998 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -8,10 +8,10 @@ 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) { @@ -1665,6 +1665,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/errno-generic.zig b/lib/std/os/bits/linux/errno-generic.zig deleted file mode 100644 index f55aa3698ef4f1b7fca6422384b6459b18e81de5..0000000000000000000000000000000000000000 --- 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 2c222902889b0203d3e1235f726e636722246680..0000000000000000000000000000000000000000 --- 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 94b696fc35027f3d4f1e354974a4528304281071..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..49b35f650117c7fb0165f5312d29874c0d890d1b --- /dev/null +++ b/lib/std/os/bits/linux/errno/generic.zig @@ -0,0 +1,466 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.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 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 0000000000000000000000000000000000000000..4f14db65ee40d7dcba80c19ff3bdd863e569dd60 --- /dev/null +++ b/lib/std/os/bits/linux/errno/mips.zig @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.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 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 0000000000000000000000000000000000000000..cc43ce1a94c941008d3b64566bd4ea8bd82ea5cf --- /dev/null +++ b/lib/std/os/bits/linux/errno/sparc.zig @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.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 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/netbsd.zig b/lib/std/os/bits/netbsd.zig index af04d0536bf16665ded4d0bb75950e063e2de390..f1bfe1b958a87695c104f9c940bed1edd90c746f 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -933,140 +933,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 - -// math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 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 - -// 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 -- 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 - -pub const ELOOP = 62; // Too many levels of symbolic links -pub const ENAMETOOLONG = 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 - -// quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 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 - -pub const ENOLCK = 77; // No locks available -pub const ENOSYS = 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 - -// 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 - -// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 -pub const EILSEQ = 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 - -// Realtime option errors -pub const ECANCELED = 87; // Operation canceled - -// Realtime, XSI STREAMS option errors -pub const EBADMSG = 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 - -// File system extended attribute errors -pub const ENOATTR = 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 - -pub const ELAST = 96; // Must equal largest errno +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 + DOM = 33, // Numerical argument out of domain + RANGE = 34, // Result too large or too small + + // 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 + 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 + 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 + + LOOP = 62, // Too many levels of symbolic links + NAMETOOLONG = 63, // File name too long + + // should be rearranged + HOSTDOWN = 64, // Host is down + HOSTUNREACH = 65, // No route to host + NOTEMPTY = 66, // Directory not empty + + // quotas & mush + PROCLIM = 67, // Too many processes + USERS = 68, // Too many users + DQUOT = 69, // Disc quota exceeded + + // 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 + + NOLCK = 77, // No locks available + NOSYS = 78, // Function not implemented + + FTYPE = 79, // Inappropriate file type or format + AUTH = 80, // Authentication error + NEEDAUTH = 81, // Need authenticator + + // 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 + ILSEQ = 85, // Illegal byte sequence + + // From IEEE Std 1003.1-2001 + // Base, Realtime, Threads or Thread Priority Scheduling option errors + NOTSUP = 86, // Not supported + + // Realtime option errors + CANCELED = 87, // Operation canceled + + // Realtime, XSI STREAMS option errors + BADMSG = 88, // Bad or Corrupt message + + // 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 + NOATTR = 93, // Attribute not found + + // Realtime, XSI STREAMS option errors + MULTIHOP = 94, // Multihop attempted + NOLINK = 95, // Link has been severed + PROTO = 96, // Protocol error + + _, +}; 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 233ebcbd684b78f7cb9f359753217b56f85d2ae5..5ad1f8980bf8922dd49e93bd0eca8093afe40dc9 100644 --- a/lib/std/os/bits/openbsd.zig +++ b/lib/std/os/bits/openbsd.zig @@ -295,6 +295,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 +825,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/wasi.zig b/lib/std/os/bits/wasi.zig index ece97eacce60576ce379dd4cd3f4fe5b3ad1f3f7..eb68946f05d8dcaff124c5a2bb35c0a9e110b3ef 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -111,86 +111,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 05c50ffe475de3a455b9b98d108c1bdf09e154be..3943d1fd3d35de82a24f16892421958da7667985 100644 --- a/lib/std/os/bits/windows.zig +++ b/lib/std/os/bits/windows.zig @@ -87,94 +87,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/linux.zig b/lib/std/os/linux.zig index ca8f0907e13c5d18ff4469a0d7bd0ae63b94e896..841f77467c748d75760a0e7aaf1158306723a950 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -91,9 +91,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 +282,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 +747,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 +765,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 +962,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 +1203,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/bpf.zig b/lib/std/os/linux/bpf.zig index 86993083e32ffe2d150267cca55457de9ba4bfd6..8afd85162941ef0c7358d57986333647a7344bbd 100644 --- a/lib/std/os/linux/bpf.zig +++ b/lib/std/os/linux/bpf.zig @@ -1508,13 +1508,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 +1533,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 +1555,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 +1576,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 +1639,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/io_uring.zig b/lib/std/os/linux/io_uring.zig index b6bde34b7d221b4cc1528f55c46dd4c651488aa5..1db4c30d2a51caf412213a3478df8e4952f87c27 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -54,19 +54,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 +180,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 +681,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 +706,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 +1272,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 +1322,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 +1357,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 +1397,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 +1425,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 +1433,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 +1466,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 +1535,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 +1578,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/test.zig b/lib/std/os/linux/test.zig index 2e98fe359d7b69023cbe260cf095a68eb3b3ffc0..8efa6c754f1bcbd7248cc584a0e36ea97f8b773a 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -22,9 +22,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 +37,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 +53,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 +81,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/wasi.zig b/lib/std/os/wasi.zig index 3965ae77a0959dc7d0d9782e67d66d1c7dae941d..e99d2b820b2cab912b2054a8ad21dd1a444c3fb8 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -83,6 +83,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/process.zig b/lib/std/process.zig index 47e800c124bb1083554932f200e508a3509c25c5..db9f442e565ce1e2c03b78da4e1af5224e4f4b48 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -93,7 +93,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 +103,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 +255,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 +265,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/special/compiler_rt/emutls.zig b/lib/std/special/compiler_rt/emutls.zig index 46d0dd98e896817e484608b2445680299a70870d..d51550c0d5f77d1afaf3659e9ddb35844338b8ea 100644 --- a/lib/std/special/compiler_rt/emutls.zig +++ b/lib/std/special/compiler_rt/emutls.zig @@ -201,7 +201,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 +248,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/time.zig b/lib/std/time.zig index 99304af46ae0de0a0f564f300a56e5000eaa964d..a0430049cfae48854f2b4d3c8319c87dc6142bcc 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -92,7 +92,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/x/os/socket_posix.zig b/lib/std/x/os/socket_posix.zig index 5deff2231720d8cfa0b8b3146f9f4746a56bb32c..59e4b177f71817406ef851a293b3e4d83df17542 100644 --- a/lib/std/x/os/socket_posix.zig +++ b/lib/std/x/os/socket_posix.zig @@ -82,32 +82,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 +120,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 +164,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 +181,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), }; } -- 2.54.0 From 8c41a8e761cb609d927b0f2c3c3c094970d2eb58 Mon Sep 17 00:00:00 2001 From: lucky <53379023+x13a@users.noreply.github.com> Date: Tue, 24 Aug 2021 14:58:09 +0300 Subject: [PATCH 39/54] add scrypt kdf (#9577) add phc encoding parser add password hash functions to benchmark change bcrypt to be consistent with scrypt Co-authored-by: lucky <> --- lib/std/crypto.zig | 9 + lib/std/crypto/bcrypt.zig | 403 ++++++++++++++----- lib/std/crypto/benchmark.zig | 44 +++ lib/std/crypto/phc_encoding.zig | 377 ++++++++++++++++++ lib/std/crypto/scrypt.zig | 663 ++++++++++++++++++++++++++++++++ 5 files changed, 1392 insertions(+), 104 deletions(-) create mode 100644 lib/std/crypto/phc_encoding.zig create mode 100644 lib/std/crypto/scrypt.zig diff --git a/lib/std/crypto.zig b/lib/std/crypto.zig index 42ded1f2ea59319a8fcee6f3c66dd752cbb7be59..84b291d57ef03c9b4e16a0d95994c1dc547d34ff 100644 --- a/lib/std/crypto.zig +++ b/lib/std/crypto.zig @@ -110,7 +110,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/bcrypt.zig b/lib/std/crypto/bcrypt.zig index 07c2142a97f0033bab3c11b7a96719d5137ec281..7d56350664b54073a48e3f67c680038e57df26f8 100644 --- a/lib/std/crypto/bcrypt.zig +++ b/lib/std/crypto/bcrypt.zig @@ -6,21 +6,28 @@ 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 +146,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 +163,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 +181,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 +387,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 +420,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 e8e50b95ea8ffb1032baf1b1865ac98ce1f790c3..efaca227c13c2aa0b043bf1770f2cb677513625f 100644 --- a/lib/std/crypto/benchmark.zig +++ b/lib/std/crypto/benchmark.zig @@ -300,6 +300,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 +455,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/phc_encoding.zig b/lib/std/crypto/phc_encoding.zig new file mode 100644 index 0000000000000000000000000000000000000000..812c1d54ff019ece70661f47c50316c60078bbf2 --- /dev/null +++ b/lib/std/crypto/phc_encoding.zig @@ -0,0 +1,377 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +// 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/scrypt.zig b/lib/std/crypto/scrypt.zig new file mode 100644 index 0000000000000000000000000000000000000000..8d8e227408c7917a06759dd2721a232eb37691d8 --- /dev/null +++ b/lib/std/crypto/scrypt.zig @@ -0,0 +1,663 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +// 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); +} -- 2.54.0 From 8a37fe21764659c5f742454a4eb9950b5c747a42 Mon Sep 17 00:00:00 2001 From: Frank Denis <124872+jedisct1@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:59:28 +0200 Subject: [PATCH 40/54] BoundedArray: a simple way to represent small data whose max size is known (#9134) This is a simple structure containing an array and a length, that can be viewed as a slice. It is useful to pass-by-copy small data whose exact size is known at runtime, but whose maximum size is known at comptime. This greatly simplifies code that otherwise would require an allocator, or reimplementing what this type does. --- lib/std/bounded_array.zig | 321 ++++++++++++++++++++++++++++++++++++++ lib/std/std.zig | 1 + 2 files changed, 322 insertions(+) create mode 100644 lib/std/bounded_array.zig diff --git a/lib/std/bounded_array.zig b/lib/std/bounded_array.zig new file mode 100644 index 0000000000000000000000000000000000000000..33216969bf03cb78461f7c59e02a36864e554e56 --- /dev/null +++ b/lib/std/bounded_array.zig @@ -0,0 +1,321 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), 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; +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/std.zig b/lib/std/std.zig index 940d1ab42eaabd94dbb1ecb84192d7bd8725166a..d4545717742f2cb68881fe4fbbcbb29651401f23 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -13,6 +13,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; -- 2.54.0 From 5c79370e9c3edee271d4f0e65e718d12b8db8a1e Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 24 Aug 2021 21:03:50 +0900 Subject: [PATCH 41/54] wasm: pass --export-dynamic to wasm-ld for WASI reactors. (#9605) Signed-off-by: Takeshi Yoneda --- src/link/Wasm.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 3c3cd4eef362f747e1364ad82bcaa656bcd2244e..fc559948c45b3aca1ea6e7f27279358f6fde3905 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. -- 2.54.0 From e3840817d7a8a3e9e69a7b0e6f3c7f2ce8c8d029 Mon Sep 17 00:00:00 2001 From: Koakuma Date: Tue, 3 Aug 2021 20:14:40 +0700 Subject: [PATCH 42/54] Linux/SPARCv9: account for branch delay in freeAndExit() --- lib/std/Thread.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 9d3b0cb1fc7d629341753d5f321046be7928a4ce..b4232d695532233e006123425129c22ecf1be628 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -810,8 +810,10 @@ const LinuxThreadImpl = struct { \\ 1: \\ cmp %%sp, 0 \\ beq 2f + \\ nop \\ restore \\ ba 1f + \\ nop \\ 2: \\ mov 73, %%g1 \\ mov %[ptr], %%o0 -- 2.54.0 From dd75302563f5cc0c67907b5c8a724e69379893f0 Mon Sep 17 00:00:00 2001 From: Koakuma Date: Tue, 3 Aug 2021 22:24:11 +0700 Subject: [PATCH 43/54] Linux/SPARCv9: use C calling convention for restore_rt This is needed to prevent infinite loop when calling rt_sigreturn. --- lib/std/os/linux/sparc64.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index f347a0e88e71b4146037d351ca9dd480dd6c62e8..1c08d39c05478b20451caca5dbbbdf44aae213fa 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)) -- 2.54.0 From d29871977f97b50fe5e3f16cd9c68ebeba02a562 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 24 Aug 2021 12:25:09 -0700 Subject: [PATCH 44/54] remove redundant license headers from zig standard library We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file. --- lib/std/Progress.zig | 6 --- lib/std/SemanticVersion.zig | 6 --- lib/std/Thread.zig | 6 --- lib/std/Thread/AutoResetEvent.zig | 6 --- lib/std/Thread/Condition.zig | 6 --- lib/std/Thread/Futex.zig | 6 --- lib/std/Thread/Mutex.zig | 6 --- lib/std/Thread/ResetEvent.zig | 6 --- lib/std/Thread/RwLock.zig | 6 --- lib/std/Thread/Semaphore.zig | 6 --- lib/std/Thread/StaticResetEvent.zig | 6 --- lib/std/array_hash_map.zig | 5 -- lib/std/array_list.zig | 5 -- lib/std/ascii.zig | 5 -- lib/std/atomic.zig | 6 --- lib/std/atomic/Atomic.zig | 6 --- lib/std/atomic/queue.zig | 5 -- lib/std/atomic/stack.zig | 5 -- lib/std/base64.zig | 5 -- lib/std/bit_set.zig | 6 --- lib/std/bounded_array.zig | 6 --- lib/std/buf_map.zig | 5 -- lib/std/buf_set.zig | 5 -- lib/std/build.zig | 5 -- lib/std/build/CheckFileStep.zig | 5 -- lib/std/build/FmtStep.zig | 5 -- lib/std/build/InstallRawStep.zig | 5 -- lib/std/build/RunStep.zig | 5 -- lib/std/build/TranslateCStep.zig | 5 -- lib/std/build/WriteFileStep.zig | 5 -- lib/std/builtin.zig | 5 -- lib/std/c.zig | 5 -- lib/std/c/darwin.zig | 5 -- lib/std/c/dragonfly.zig | 5 -- lib/std/c/emscripten.zig | 5 -- lib/std/c/freebsd.zig | 5 -- lib/std/c/fuchsia.zig | 5 -- lib/std/c/haiku.zig | 6 --- lib/std/c/hermit.zig | 5 -- lib/std/c/linux.zig | 5 -- lib/std/c/minix.zig | 5 -- lib/std/c/netbsd.zig | 5 -- lib/std/c/openbsd.zig | 5 -- lib/std/c/solaris.zig | 5 -- lib/std/c/tokenizer.zig | 5 -- lib/std/c/wasi.zig | 5 -- lib/std/c/windows.zig | 5 -- lib/std/child_process.zig | 5 -- lib/std/coff.zig | 5 -- lib/std/compress.zig | 5 -- lib/std/compress/deflate.zig | 5 -- lib/std/compress/gzip.zig | 5 -- lib/std/compress/zlib.zig | 5 -- lib/std/comptime_string_map.zig | 5 -- lib/std/crypto.zig | 6 --- lib/std/crypto/25519/curve25519.zig | 5 -- lib/std/crypto/25519/ed25519.zig | 5 -- lib/std/crypto/25519/edwards25519.zig | 5 -- lib/std/crypto/25519/field.zig | 5 -- lib/std/crypto/25519/ristretto255.zig | 5 -- lib/std/crypto/25519/scalar.zig | 5 -- lib/std/crypto/25519/x25519.zig | 5 -- lib/std/crypto/aegis.zig | 6 --- lib/std/crypto/aes.zig | 6 --- lib/std/crypto/aes/aesni.zig | 6 --- lib/std/crypto/aes/armcrypto.zig | 6 --- lib/std/crypto/aes/soft.zig | 5 -- lib/std/crypto/aes_gcm.zig | 6 --- lib/std/crypto/aes_ocb.zig | 6 --- lib/std/crypto/bcrypt.zig | 6 --- lib/std/crypto/benchmark.zig | 5 -- lib/std/crypto/blake2.zig | 5 -- lib/std/crypto/blake3.zig | 5 -- lib/std/crypto/chacha20.zig | 5 -- lib/std/crypto/ghash.zig | 5 -- lib/std/crypto/gimli.zig | 5 -- lib/std/crypto/hkdf.zig | 6 --- lib/std/crypto/hmac.zig | 5 -- lib/std/crypto/md5.zig | 5 -- lib/std/crypto/modes.zig | 5 -- lib/std/crypto/pbkdf2.zig | 6 --- lib/std/crypto/pcurves/p256.zig | 6 --- lib/std/crypto/pcurves/p256/field.zig | 6 --- lib/std/crypto/pcurves/p256/scalar.zig | 6 --- lib/std/crypto/pcurves/tests.zig | 6 --- lib/std/crypto/phc_encoding.zig | 6 --- lib/std/crypto/poly1305.zig | 5 -- lib/std/crypto/salsa20.zig | 6 --- lib/std/crypto/scrypt.zig | 6 --- lib/std/crypto/sha1.zig | 5 -- lib/std/crypto/sha2.zig | 5 -- lib/std/crypto/sha3.zig | 5 -- lib/std/crypto/siphash.zig | 5 -- lib/std/crypto/test.zig | 5 -- lib/std/crypto/tlcsprng.zig | 6 --- lib/std/cstr.zig | 5 -- lib/std/debug.zig | 5 -- lib/std/dwarf.zig | 5 -- lib/std/dwarf_bits.zig | 5 -- lib/std/dynamic_library.zig | 5 -- lib/std/elf.zig | 5 -- lib/std/enums.zig | 6 --- lib/std/event.zig | 5 -- lib/std/event/batch.zig | 5 -- lib/std/event/channel.zig | 5 -- lib/std/event/future.zig | 5 -- lib/std/event/group.zig | 5 -- lib/std/event/lock.zig | 5 -- lib/std/event/locked.zig | 5 -- lib/std/event/loop.zig | 5 -- lib/std/event/rwlock.zig | 5 -- lib/std/event/rwlocked.zig | 5 -- lib/std/event/wait_group.zig | 5 -- lib/std/fifo.zig | 5 -- lib/std/fmt.zig | 5 -- lib/std/fmt/errol.zig | 5 -- lib/std/fmt/errol/enum3.zig | 5 -- lib/std/fmt/errol/lookup.zig | 5 -- lib/std/fmt/parse_float.zig | 5 -- lib/std/fmt/parse_hex_float.zig | 6 --- lib/std/fs.zig | 5 -- lib/std/fs/file.zig | 5 -- lib/std/fs/get_app_data_dir.zig | 5 -- lib/std/fs/path.zig | 5 -- lib/std/fs/test.zig | 5 -- lib/std/fs/wasi.zig | 5 -- lib/std/fs/watch.zig | 5 -- lib/std/hash.zig | 5 -- lib/std/hash/adler.zig | 5 -- lib/std/hash/auto_hash.zig | 5 -- lib/std/hash/benchmark.zig | 5 -- lib/std/hash/cityhash.zig | 5 -- lib/std/hash/crc.zig | 5 -- lib/std/hash/fnv.zig | 5 -- lib/std/hash/murmur.zig | 5 -- lib/std/hash/wyhash.zig | 5 -- lib/std/hash_map.zig | 5 -- lib/std/heap.zig | 5 -- lib/std/heap/arena_allocator.zig | 5 -- lib/std/heap/general_purpose_allocator.zig | 5 -- lib/std/heap/log_to_writer_allocator.zig | 5 -- lib/std/heap/logging_allocator.zig | 5 -- lib/std/io.zig | 5 -- lib/std/io/bit_reader.zig | 5 -- lib/std/io/bit_writer.zig | 5 -- lib/std/io/buffered_atomic_file.zig | 5 -- lib/std/io/buffered_reader.zig | 5 -- lib/std/io/buffered_writer.zig | 5 -- lib/std/io/c_writer.zig | 5 -- lib/std/io/change_detection_stream.zig | 6 --- lib/std/io/counting_reader.zig | 5 -- lib/std/io/counting_writer.zig | 5 -- lib/std/io/find_byte_writer.zig | 6 --- lib/std/io/fixed_buffer_stream.zig | 5 -- lib/std/io/limited_reader.zig | 5 -- lib/std/io/multi_writer.zig | 5 -- lib/std/io/peek_stream.zig | 5 -- lib/std/io/reader.zig | 5 -- lib/std/io/seekable_stream.zig | 5 -- lib/std/io/stream_source.zig | 5 -- lib/std/io/test.zig | 5 -- lib/std/io/writer.zig | 5 -- lib/std/json.zig | 5 -- lib/std/json/test.zig | 5 -- lib/std/json/write_stream.zig | 5 -- lib/std/leb128.zig | 5 -- lib/std/linked_list.zig | 5 -- lib/std/log.zig | 6 --- lib/std/macho.zig | 5 -- lib/std/math.zig | 5 -- lib/std/math/acos.zig | 5 -- lib/std/math/acosh.zig | 5 -- lib/std/math/asin.zig | 5 -- lib/std/math/asinh.zig | 5 -- lib/std/math/atan.zig | 5 -- lib/std/math/atan2.zig | 5 -- lib/std/math/atanh.zig | 5 -- lib/std/math/big.zig | 5 -- lib/std/math/big/int.zig | 5 -- lib/std/math/big/int_test.zig | 5 -- lib/std/math/big/rational.zig | 5 -- lib/std/math/cbrt.zig | 5 -- lib/std/math/ceil.zig | 5 -- lib/std/math/complex.zig | 5 -- lib/std/math/complex/abs.zig | 5 -- lib/std/math/complex/acos.zig | 5 -- lib/std/math/complex/acosh.zig | 5 -- lib/std/math/complex/arg.zig | 5 -- lib/std/math/complex/asin.zig | 5 -- lib/std/math/complex/asinh.zig | 5 -- lib/std/math/complex/atan.zig | 5 -- lib/std/math/complex/atanh.zig | 5 -- lib/std/math/complex/conj.zig | 5 -- lib/std/math/complex/cos.zig | 5 -- lib/std/math/complex/cosh.zig | 5 -- lib/std/math/complex/exp.zig | 5 -- lib/std/math/complex/ldexp.zig | 5 -- lib/std/math/complex/log.zig | 5 -- lib/std/math/complex/pow.zig | 5 -- lib/std/math/complex/proj.zig | 5 -- lib/std/math/complex/sin.zig | 5 -- lib/std/math/complex/sinh.zig | 5 -- lib/std/math/complex/sqrt.zig | 5 -- lib/std/math/complex/tan.zig | 5 -- lib/std/math/complex/tanh.zig | 5 -- lib/std/math/copysign.zig | 5 -- lib/std/math/cos.zig | 5 -- lib/std/math/cosh.zig | 5 -- lib/std/math/epsilon.zig | 5 -- lib/std/math/exp.zig | 5 -- lib/std/math/exp2.zig | 5 -- lib/std/math/expm1.zig | 5 -- lib/std/math/expo2.zig | 5 -- lib/std/math/fabs.zig | 5 -- lib/std/math/floor.zig | 5 -- lib/std/math/fma.zig | 5 -- lib/std/math/frexp.zig | 5 -- lib/std/math/hypot.zig | 5 -- lib/std/math/ilogb.zig | 5 -- lib/std/math/inf.zig | 5 -- lib/std/math/isfinite.zig | 5 -- lib/std/math/isinf.zig | 5 -- lib/std/math/isnan.zig | 5 -- lib/std/math/isnormal.zig | 5 -- lib/std/math/ln.zig | 5 -- lib/std/math/log.zig | 5 -- lib/std/math/log10.zig | 5 -- lib/std/math/log1p.zig | 5 -- lib/std/math/log2.zig | 5 -- lib/std/math/modf.zig | 5 -- lib/std/math/nan.zig | 5 -- lib/std/math/pow.zig | 5 -- lib/std/math/powi.zig | 5 -- lib/std/math/round.zig | 5 -- lib/std/math/scalbn.zig | 5 -- lib/std/math/signbit.zig | 5 -- lib/std/math/sin.zig | 5 -- lib/std/math/sinh.zig | 5 -- lib/std/math/sqrt.zig | 5 -- lib/std/math/tan.zig | 5 -- lib/std/math/tanh.zig | 5 -- lib/std/math/trunc.zig | 5 -- lib/std/mem.zig | 5 -- lib/std/mem/Allocator.zig | 5 -- lib/std/meta.zig | 5 -- lib/std/meta/trailer_flags.zig | 5 -- lib/std/meta/trait.zig | 5 -- lib/std/multi_array_list.zig | 5 -- lib/std/net.zig | 5 -- lib/std/net/test.zig | 5 -- lib/std/once.zig | 5 -- lib/std/os.zig | 5 -- lib/std/os/bits.zig | 5 -- lib/std/os/bits/darwin.zig | 5 -- lib/std/os/bits/dragonfly.zig | 5 -- lib/std/os/bits/freebsd.zig | 5 -- lib/std/os/bits/haiku.zig | 5 -- lib/std/os/bits/linux.zig | 5 -- lib/std/os/bits/linux/arm-eabi.zig | 5 -- lib/std/os/bits/linux/arm64.zig | 5 -- lib/std/os/bits/linux/errno/generic.zig | 6 --- lib/std/os/bits/linux/errno/mips.zig | 6 --- lib/std/os/bits/linux/errno/sparc.zig | 6 --- lib/std/os/bits/linux/i386.zig | 5 -- lib/std/os/bits/linux/mips.zig | 5 -- lib/std/os/bits/linux/netlink.zig | 5 -- lib/std/os/bits/linux/powerpc.zig | 6 --- lib/std/os/bits/linux/powerpc64.zig | 6 --- lib/std/os/bits/linux/prctl.zig | 6 --- lib/std/os/bits/linux/riscv64.zig | 5 -- lib/std/os/bits/linux/securebits.zig | 6 --- lib/std/os/bits/linux/x86_64.zig | 5 -- lib/std/os/bits/linux/xdp.zig | 5 -- lib/std/os/bits/netbsd.zig | 5 -- lib/std/os/bits/openbsd.zig | 5 -- lib/std/os/bits/posix.zig | 6 --- lib/std/os/bits/wasi.zig | 5 -- lib/std/os/bits/windows.zig | 5 -- lib/std/os/darwin.zig | 5 -- lib/std/os/dragonfly.zig | 5 -- lib/std/os/freebsd.zig | 5 -- lib/std/os/haiku.zig | 5 -- lib/std/os/linux.zig | 5 -- lib/std/os/linux/arm-eabi.zig | 5 -- lib/std/os/linux/arm64.zig | 5 -- lib/std/os/linux/bpf.zig | 5 -- lib/std/os/linux/bpf/btf.zig | 5 -- lib/std/os/linux/bpf/btf_ext.zig | 5 -- lib/std/os/linux/bpf/helpers.zig | 5 -- lib/std/os/linux/bpf/kern.zig | 5 -- lib/std/os/linux/i386.zig | 5 -- lib/std/os/linux/io_uring.zig | 5 -- lib/std/os/linux/mips.zig | 5 -- lib/std/os/linux/powerpc.zig | 6 --- lib/std/os/linux/powerpc64.zig | 6 --- lib/std/os/linux/riscv64.zig | 5 -- lib/std/os/linux/test.zig | 5 -- lib/std/os/linux/thumb.zig | 5 -- lib/std/os/linux/tls.zig | 5 -- lib/std/os/linux/vdso.zig | 5 -- lib/std/os/linux/x86_64.zig | 5 -- lib/std/os/netbsd.zig | 5 -- lib/std/os/openbsd.zig | 5 -- lib/std/os/test.zig | 5 -- lib/std/os/uefi.zig | 5 -- lib/std/os/uefi/protocols.zig | 5 -- .../protocols/absolute_pointer_protocol.zig | 5 -- .../uefi/protocols/device_path_protocol.zig | 5 -- .../uefi/protocols/edid_active_protocol.zig | 5 -- .../protocols/edid_discovered_protocol.zig | 5 -- .../uefi/protocols/edid_override_protocol.zig | 5 -- lib/std/os/uefi/protocols/file_protocol.zig | 5 -- .../protocols/graphics_output_protocol.zig | 5 -- lib/std/os/uefi/protocols/hii.zig | 5 -- .../uefi/protocols/hii_database_protocol.zig | 5 -- .../os/uefi/protocols/hii_popup_protocol.zig | 5 -- .../os/uefi/protocols/ip6_config_protocol.zig | 5 -- lib/std/os/uefi/protocols/ip6_protocol.zig | 5 -- .../ip6_service_binding_protocol.zig | 5 -- .../uefi/protocols/loaded_image_protocol.zig | 5 -- .../protocols/managed_network_protocol.zig | 5 -- ...naged_network_service_binding_protocol.zig | 5 -- lib/std/os/uefi/protocols/rng_protocol.zig | 5 -- .../protocols/shell_parameters_protocol.zig | 5 -- .../protocols/simple_file_system_protocol.zig | 5 -- .../protocols/simple_network_protocol.zig | 5 -- .../protocols/simple_pointer_protocol.zig | 5 -- .../simple_text_input_ex_protocol.zig | 5 -- .../protocols/simple_text_input_protocol.zig | 5 -- .../protocols/simple_text_output_protocol.zig | 5 -- lib/std/os/uefi/protocols/udp6_protocol.zig | 5 -- .../udp6_service_binding_protocol.zig | 5 -- lib/std/os/uefi/status.zig | 5 -- lib/std/os/uefi/tables.zig | 5 -- lib/std/os/uefi/tables/boot_services.zig | 5 -- .../os/uefi/tables/configuration_table.zig | 5 -- lib/std/os/uefi/tables/runtime_services.zig | 5 -- lib/std/os/uefi/tables/system_table.zig | 5 -- lib/std/os/uefi/tables/table_header.zig | 5 -- lib/std/os/wasi.zig | 5 -- lib/std/os/windows.zig | 5 -- lib/std/os/windows/advapi32.zig | 5 -- lib/std/os/windows/bits.zig | 5 -- lib/std/os/windows/gdi32.zig | 5 -- lib/std/os/windows/kernel32.zig | 5 -- lib/std/os/windows/lang.zig | 5 -- lib/std/os/windows/ntdll.zig | 5 -- lib/std/os/windows/ntstatus.zig | 6 --- lib/std/os/windows/ole32.zig | 5 -- lib/std/os/windows/psapi.zig | 5 -- lib/std/os/windows/shell32.zig | 5 -- lib/std/os/windows/sublang.zig | 5 -- lib/std/os/windows/test.zig | 5 -- lib/std/os/windows/user32.zig | 5 -- lib/std/os/windows/win32error.zig | 5 -- lib/std/os/windows/winmm.zig | 5 -- lib/std/os/windows/ws2_32.zig | 5 -- lib/std/packed_int_array.zig | 5 -- lib/std/pdb.zig | 5 -- lib/std/priority_dequeue.zig | 5 -- lib/std/priority_queue.zig | 5 -- lib/std/process.zig | 5 -- lib/std/rand.zig | 6 --- lib/std/rand/Gimli.zig | 6 --- lib/std/rand/Isaac64.zig | 6 --- lib/std/rand/Pcg.zig | 6 --- lib/std/rand/Sfc64.zig | 6 --- lib/std/rand/Xoroshiro128.zig | 6 --- lib/std/rand/Xoshiro256.zig | 6 --- lib/std/rand/ziggurat.zig | 5 -- lib/std/sort.zig | 5 -- lib/std/special/build_runner.zig | 5 -- lib/std/special/c.zig | 5 -- lib/std/special/compiler_rt.zig | 5 -- lib/std/special/compiler_rt/addXf3.zig | 5 -- lib/std/special/compiler_rt/addXf3_test.zig | 5 -- lib/std/special/compiler_rt/arm.zig | 5 -- lib/std/special/compiler_rt/ashldi3_test.zig | 5 -- lib/std/special/compiler_rt/ashlti3_test.zig | 5 -- lib/std/special/compiler_rt/ashrdi3_test.zig | 5 -- lib/std/special/compiler_rt/ashrti3_test.zig | 5 -- lib/std/special/compiler_rt/atomics.zig | 5 -- lib/std/special/compiler_rt/aulldiv.zig | 5 -- lib/std/special/compiler_rt/aullrem.zig | 5 -- lib/std/special/compiler_rt/clear_cache.zig | 5 -- lib/std/special/compiler_rt/clzsi2.zig | 5 -- lib/std/special/compiler_rt/clzsi2_test.zig | 5 -- lib/std/special/compiler_rt/compareXf2.zig | 5 -- .../special/compiler_rt/comparedf2_test.zig | 5 -- .../special/compiler_rt/comparesf2_test.zig | 5 -- lib/std/special/compiler_rt/divdf3.zig | 5 -- lib/std/special/compiler_rt/divdf3_test.zig | 5 -- lib/std/special/compiler_rt/divsf3.zig | 5 -- lib/std/special/compiler_rt/divsf3_test.zig | 5 -- lib/std/special/compiler_rt/divtf3.zig | 5 -- lib/std/special/compiler_rt/divtf3_test.zig | 5 -- lib/std/special/compiler_rt/divti3.zig | 5 -- lib/std/special/compiler_rt/divti3_test.zig | 5 -- lib/std/special/compiler_rt/emutls.zig | 6 --- lib/std/special/compiler_rt/extendXfYf2.zig | 5 -- .../special/compiler_rt/extendXfYf2_test.zig | 5 -- lib/std/special/compiler_rt/fixdfdi.zig | 5 -- lib/std/special/compiler_rt/fixdfdi_test.zig | 5 -- lib/std/special/compiler_rt/fixdfsi.zig | 5 -- lib/std/special/compiler_rt/fixdfsi_test.zig | 5 -- lib/std/special/compiler_rt/fixdfti.zig | 5 -- lib/std/special/compiler_rt/fixdfti_test.zig | 5 -- lib/std/special/compiler_rt/fixint.zig | 5 -- lib/std/special/compiler_rt/fixint_test.zig | 5 -- lib/std/special/compiler_rt/fixsfdi.zig | 5 -- lib/std/special/compiler_rt/fixsfdi_test.zig | 5 -- lib/std/special/compiler_rt/fixsfsi.zig | 5 -- lib/std/special/compiler_rt/fixsfsi_test.zig | 5 -- lib/std/special/compiler_rt/fixsfti.zig | 5 -- lib/std/special/compiler_rt/fixsfti_test.zig | 5 -- lib/std/special/compiler_rt/fixtfdi.zig | 5 -- lib/std/special/compiler_rt/fixtfdi_test.zig | 5 -- lib/std/special/compiler_rt/fixtfsi.zig | 5 -- lib/std/special/compiler_rt/fixtfsi_test.zig | 5 -- lib/std/special/compiler_rt/fixtfti.zig | 5 -- lib/std/special/compiler_rt/fixtfti_test.zig | 5 -- lib/std/special/compiler_rt/fixuint.zig | 5 -- lib/std/special/compiler_rt/fixunsdfdi.zig | 5 -- .../special/compiler_rt/fixunsdfdi_test.zig | 5 -- lib/std/special/compiler_rt/fixunsdfsi.zig | 5 -- .../special/compiler_rt/fixunsdfsi_test.zig | 5 -- lib/std/special/compiler_rt/fixunsdfti.zig | 5 -- .../special/compiler_rt/fixunsdfti_test.zig | 5 -- lib/std/special/compiler_rt/fixunssfdi.zig | 5 -- .../special/compiler_rt/fixunssfdi_test.zig | 5 -- lib/std/special/compiler_rt/fixunssfsi.zig | 5 -- .../special/compiler_rt/fixunssfsi_test.zig | 5 -- lib/std/special/compiler_rt/fixunssfti.zig | 5 -- .../special/compiler_rt/fixunssfti_test.zig | 5 -- lib/std/special/compiler_rt/fixunstfdi.zig | 5 -- .../special/compiler_rt/fixunstfdi_test.zig | 5 -- lib/std/special/compiler_rt/fixunstfsi.zig | 5 -- .../special/compiler_rt/fixunstfsi_test.zig | 5 -- lib/std/special/compiler_rt/fixunstfti.zig | 5 -- .../special/compiler_rt/fixunstfti_test.zig | 5 -- lib/std/special/compiler_rt/floatXisf.zig | 5 -- lib/std/special/compiler_rt/floatdidf.zig | 5 -- .../special/compiler_rt/floatdidf_test.zig | 5 -- .../special/compiler_rt/floatdisf_test.zig | 5 -- lib/std/special/compiler_rt/floatditf.zig | 5 -- .../special/compiler_rt/floatditf_test.zig | 5 -- lib/std/special/compiler_rt/floatsiXf.zig | 5 -- lib/std/special/compiler_rt/floattidf.zig | 5 -- .../special/compiler_rt/floattidf_test.zig | 5 -- .../special/compiler_rt/floattisf_test.zig | 5 -- lib/std/special/compiler_rt/floattitf.zig | 5 -- .../special/compiler_rt/floattitf_test.zig | 5 -- lib/std/special/compiler_rt/floatundidf.zig | 5 -- .../special/compiler_rt/floatundidf_test.zig | 5 -- lib/std/special/compiler_rt/floatundisf.zig | 5 -- lib/std/special/compiler_rt/floatunditf.zig | 5 -- .../special/compiler_rt/floatunditf_test.zig | 5 -- lib/std/special/compiler_rt/floatunsidf.zig | 5 -- lib/std/special/compiler_rt/floatunsisf.zig | 5 -- lib/std/special/compiler_rt/floatunsitf.zig | 5 -- .../special/compiler_rt/floatunsitf_test.zig | 5 -- lib/std/special/compiler_rt/floatuntidf.zig | 5 -- .../special/compiler_rt/floatuntidf_test.zig | 5 -- lib/std/special/compiler_rt/floatuntisf.zig | 5 -- .../special/compiler_rt/floatuntisf_test.zig | 5 -- lib/std/special/compiler_rt/floatuntitf.zig | 5 -- .../special/compiler_rt/floatuntitf_test.zig | 5 -- lib/std/special/compiler_rt/int.zig | 5 -- lib/std/special/compiler_rt/lshrdi3_test.zig | 5 -- lib/std/special/compiler_rt/lshrti3_test.zig | 5 -- lib/std/special/compiler_rt/modti3.zig | 5 -- lib/std/special/compiler_rt/modti3_test.zig | 5 -- lib/std/special/compiler_rt/mulXf3.zig | 5 -- lib/std/special/compiler_rt/mulXf3_test.zig | 5 -- lib/std/special/compiler_rt/muldi3.zig | 5 -- lib/std/special/compiler_rt/muldi3_test.zig | 5 -- lib/std/special/compiler_rt/mulodi4.zig | 5 -- lib/std/special/compiler_rt/mulodi4_test.zig | 5 -- lib/std/special/compiler_rt/muloti4.zig | 5 -- lib/std/special/compiler_rt/muloti4_test.zig | 5 -- lib/std/special/compiler_rt/multi3.zig | 5 -- lib/std/special/compiler_rt/multi3_test.zig | 5 -- lib/std/special/compiler_rt/negXf2.zig | 5 -- lib/std/special/compiler_rt/popcountdi2.zig | 5 -- .../special/compiler_rt/popcountdi2_test.zig | 5 -- lib/std/special/compiler_rt/shift.zig | 5 -- lib/std/special/compiler_rt/sparc.zig | 5 -- lib/std/special/compiler_rt/stack_probe.zig | 5 -- lib/std/special/compiler_rt/truncXfYf2.zig | 5 -- .../special/compiler_rt/truncXfYf2_test.zig | 5 -- lib/std/special/compiler_rt/udivmod.zig | 5 -- .../special/compiler_rt/udivmoddi4_test.zig | 5 -- lib/std/special/compiler_rt/udivmodti4.zig | 5 -- .../special/compiler_rt/udivmodti4_test.zig | 5 -- lib/std/special/compiler_rt/udivti3.zig | 5 -- lib/std/special/compiler_rt/umodti3.zig | 5 -- lib/std/special/ssp.zig | 5 -- lib/std/special/test_runner.zig | 5 -- lib/std/start.zig | 5 -- lib/std/start_windows_tls.zig | 5 -- lib/std/std.zig | 5 -- lib/std/target.zig | 5 -- lib/std/testing.zig | 5 -- lib/std/testing/failing_allocator.zig | 5 -- lib/std/time.zig | 5 -- lib/std/time/epoch.zig | 5 -- lib/std/unicode.zig | 5 -- lib/std/unicode/throughput_test.zig | 5 -- lib/std/valgrind.zig | 5 -- lib/std/valgrind/callgrind.zig | 5 -- lib/std/valgrind/memcheck.zig | 5 -- lib/std/wasm.zig | 5 -- lib/std/x.zig | 6 --- lib/std/x/net/ip.zig | 6 --- lib/std/x/net/tcp.zig | 6 --- lib/std/x/os/net.zig | 6 --- lib/std/x/os/socket.zig | 6 --- lib/std/x/os/socket_posix.zig | 6 --- lib/std/x/os/socket_windows.zig | 6 --- lib/std/zig.zig | 5 -- lib/std/zig/ast.zig | 5 -- lib/std/zig/c_builtins.zig | 6 --- lib/std/zig/c_translation.zig | 6 --- lib/std/zig/cross_target.zig | 5 -- lib/std/zig/parse.zig | 5 -- lib/std/zig/parser_test.zig | 6 --- lib/std/zig/perf_test.zig | 5 -- lib/std/zig/render.zig | 5 -- lib/std/zig/string_literal.zig | 5 -- lib/std/zig/system.zig | 5 -- lib/std/zig/system/darwin.zig | 5 -- lib/std/zig/system/darwin/macos.zig | 5 -- lib/std/zig/system/windows.zig | 5 -- lib/std/zig/system/x86.zig | 5 -- lib/std/zig/tokenizer.zig | 5 -- tools/update-license-headers.zig | 47 +++++++++++++++++++ 536 files changed, 47 insertions(+), 2743 deletions(-) create mode 100644 tools/update-license-headers.zig diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index ba60f91233651a3874af442b3d109069b1586648..e99b298c1ed5e04a3c6d4a5dee2de5ed8adb541f 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 17d5b6557160eae7a0ec0e974941bb0b07c44c30..fb09f85ff2539e49bd04a9f439a409d22dc1b2eb 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 b4232d695532233e006123425129c22ecf1be628..3c0a53612c49376629371c353b50a724f1d8b942 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.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 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. diff --git a/lib/std/Thread/AutoResetEvent.zig b/lib/std/Thread/AutoResetEvent.zig index 13e404d60277905e433f557075b8bfc625334b62..49639d60e9d39ffc71cf6d2ecd1ff85f7db258ee 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 9513e794edaf7ce54ae76f32903827ae99b44546..647a50b9136c4ec4c2c8411a718cfbdf1e6bb4e2 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. diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig index a896942d6ea7bccd046adec857a8588e0cf7d880..5a3da5cd9489fbbfc1d061e4e0f448b456fd9700 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()`. diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig index 522d1fe4183d82ecb6b87e96c3259056e8c71a80..ee54a1582bbf1ac3844fe3f2e74fa4639fa2a549 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 diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig index bbf9e7263a0cd429377607e38c1d7c67cbd66e59..d9304dd70b768d1c1d5f3643a2784f33ef028084 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 diff --git a/lib/std/Thread/RwLock.zig b/lib/std/Thread/RwLock.zig index 0721aad3f7cc82987e6b0af2cd56ea27b2d90345..cfe06c76e8021b285cb13d91d53217472aee84d5 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 diff --git a/lib/std/Thread/Semaphore.zig b/lib/std/Thread/Semaphore.zig index 169975b3626e50e780e68c12361423ca0d8894f5..b5bde88d736a907267af9ee7921561109fba711d 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 e15a6a0a5435e261a73e68505b104265eeb136c2..d779a4de9e2c7d232ef89a4b905dc19e851f9eb4 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 diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index 4ca603d2e889bba5034c09d79ffc22e65c38b90e..37612a1266b5d446c0c1ea98062e369259461ba3 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 1e74d34922a8c8610cbb69969f1cefdda6da0c69..f6ee5cdad26c19b730b933542c5047e2f0ce246f 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 afaf9f8ca473fe94359e517043d7c5d9aeef655b..c999162b3643378c068e5d3a259d67479a7b53ce 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 42d57eb8fa105b97af96ad87020a376a688f95f6..95d218736a8270c93a6ea75a59483734ac4df67e 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 f4e3ebda9dfcdea36338e2efe8d2dee3062430e1..deb364b7d3d7390bcce0593e20fc14ca1159139b 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 cee431951c1b593555dcca7815c4e0a6c78ce160..f3781b4ce79268e7310ec6332b8f90c285242d13 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 cfdf40fa60c21f1a3df1b80158870fee579e4ef0..a1747db0f5722485906da7564b335254de833b1b 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 4b01455112dac67dff6a51b65173cf02282c859d..7e593900e6ce40ab11e93766e41bd374b926dc9c 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 261c6af2dfa340b5d10bebf81b4ce330696c3412..dd8afb4168ea141435a10f5f63c89be4971fa293 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 index 33216969bf03cb78461f7c59e02a36864e554e56..587251458eacec25c8f76cefbaff8cf154ce93db 100644 --- a/lib/std/bounded_array.zig +++ b/lib/std/bounded_array.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 mem = std.mem; diff --git a/lib/std/buf_map.zig b/lib/std/buf_map.zig index 3494fce0323f670c38754e4b872e1633dc3b0c18..1e4462e6aee425b874af819967b7402043b73c56 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 c2a1f9bcb97ddf1681cfb9c0e493c621e11d54f1..ce2d51b0569c76c39aa6997759c196ac1c02300a 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 013770bbece61ffb7ed699c8e3eb142d3ecb6d26..1533f93085965a3cc472cd7afd5bd53f51469d77 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; diff --git a/lib/std/build/CheckFileStep.zig b/lib/std/build/CheckFileStep.zig index 1f1ed0884ea2a1b33f7aaec466c6fb60dc09a541..2b433b5448cc9bdbc690a1592079d9ea9f59f792 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 82faf32be903ce5322f15e24a6f1eba6413c1dca..62923623f2aaea208be692355b6f7a651beddd99 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 743b25f3cdeace469db52011c279f4c5235aa46c..39a2d29845542ce60d27c0848d9303caecb252ed 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/RunStep.zig b/lib/std/build/RunStep.zig index 89d9cd911cb25f84cc9d0b3ccd18f9479ae0a014..67929b6f5d6b0f62c397d97987cacbf057af50a2 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 2f209b80b423699009cd86261def3eb50224c010..0d44ebd80a887fdca58b2bc27551e1228ffc3b8b 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 12879421103a1a6ae04d31d2d9765a3b2b5e0439..5a8d806049eb7bf5b63b8e50a530a229d43234ee 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 caf32890b6219f53f01219e1c9b8ad8e78698ec2..bb35d61375189e1b6e1f05d7bd5720c268300b18 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. diff --git a/lib/std/c.zig b/lib/std/c.zig index 700a1dc25090ed050cd39269b9a1179799aae52f..0ad69f873fdec96595e725522f5cf6ecc1826646 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; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 117172fc7b4e247edc77652c9d92b305327c05ba..7fa07719a8865849e547471fa3400c97a9c7b944 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"); diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 7d722dad443737504bb3269aff8270e122cdaad2..e5786d2bd400e99fbfda93a0bf572a8fdffa25a7 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 526eb9e99c1af0663af6e0b2f86f6c61117ad506..0d78d4d73f2756d2ea6213bd488becb2233fe8ef 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 eb449165d34a296d1a0a3003025e5f3572312c1e..f7d1e07608dbc14bd002134403c7ad17aaa8c2a0 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 fc34f49d2249ccb20080fd1ba226c464cb97d32a..af6c4756b9eec3c35e750f70a8626e4788f9c6ce 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 fcf99db57158126b13da0b84d90d59456431e452..be6c180bed059c854d234c28a78bcbafa141ec48 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 a159395ab367b2393e3b5d08a7e02ddcff576669..ae13840e16568392d3e4cf513f4a267071592298 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 2ce98e2246c57b14c9ff1fe77d292abb100e45a0..808b05bd6db79352b0dd5dde6a41ba12eafef056 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; diff --git a/lib/std/c/minix.zig b/lib/std/c/minix.zig index 3f03d31ed5473d7f7abf16258a1ac10c99d7c726..9c644a79867c892e05f67335872813d41c6e347d 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 07af1dc689855a05b95494ac44994f096065d3f7..e45dc85d34eb842ec31ef23384389a5043787a79 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; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 15820fb0a935d8a482659c4078b61198215cfb1f..e5ded7f3fb837dedc1edccce56def2bfce25c21c 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 ed043018d0fd98b1e6e4d6bb2e9defb7e0b6a6cc..7c70a01fc4ac1c9281c6ad6476c61d959ddb2889 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 f8709e12bea54e074e0f6a43f80fdfc08f64ef80..9ad5ab0179e972951442377dfd39b8f8b6829abe 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 0edc77de3780e66bc72f6e6acbda7e40efffe735..339bdcd127f5b1a069a6ee372927e0dbe1d395f0 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 bed2e421ff03093f6872a2b18cf0f2710b0dbbb7..a10715f0830e8e5e00e7603c90727cabe07cf09a 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 3f3fa9c754d0133bc75c96ab6c8d160f6e18eb1d..7d8881a67995b25a12f9271c09ae186d374dc182 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 8b00a2429702e62540536a412c55ca7cfe9d3959..6caf214728f51ebf37d5a1efe014d70852b9b045 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 972031c182c871afa1e8d1037e3f611459122678..f4db3fecd5a6ec2b0f79e6b0ab45f59aa8e8871a 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 d7209981ce0ae6be0e62d2c56737bd2476abf90b..b443c2971f3ea56421f296d798fa91adfd91b76a 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 6f17601949325701ffbfcc425a0e9e021bc23a1e..497b07d905e27c56e3a01ec4f8dbc47084419b46 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 909bae4090586296bd8bc6d4e61813a2244202a7..f0f4ca2ff4d91efe3f1743bb8531e3d49baa5423 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 6e8f190bc48b1d05dff6fa80885720f027cb645c..09ba4e5a3caf571db2ea36062c842b5b61ff7b9f 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 84b291d57ef03c9b4e16a0d95994c1dc547d34ff..e00e331b460721f56f4f6d8e62b4b8a1108e09d5 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 { diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig index 9b8cecb917626740c180e2a5f1674c5cc914fa54..44a19362e4e3ebdab4f1f81e298aa63f68c0e1cd 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 4940f0dee6cb83fc891dcf7cbb1afe4199a72fe6..a6ac956183af1180321591a574228f62da8a8362 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 15af616d602e79db9cabe9dc7bd99c9777c5708a..7e58692e63a5dad62e41cc3e17a0071ac8dfe303 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 1d67f0a902395db03eccc1a5a127bb43be8c2c83..277fb98d5cea11ae3175dee48e2f325b225c92fd 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 dea6193fca2e0e59f7dcc370ca0462546592bf23..e33bdb496d075844b57d726bc30553314e419ca3 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 bea054234efd95af644669a7fa1a0cd36c66d616..9582a888f0f91b2b0faf2c2f55babfab54065029 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 5109fd7c2a95cffa4f8c8bc78f58142b8d81799f..d935513ab6ab8c97943a085bb7324f064ce2dcf2 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 194b6de8f5ceaf3456cc1699a242280c202dc53f..68062c537e2a1b9fe98e54938bba5dbd51ac7bdb 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 7d6e0d1e84bf0e39b4c91fd27158b0f7a495157d..18bae3978ef770436c31da82135e79dd6b0d0411 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 7fbbaac7e8818657b7487fd68a8186425b4ab0ae..94c7f5efc6f6008dbf93ca794f9d83fbbc5083b7 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 4d16b2f680114bd0b9f6a318839640b9474191c6..cee5b9bccbf7681cabbac8722b8c6be3fc79167d 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 0d8a56679312de472eec0d979933e68dfdc89c44..bc9a994b95abd682a68bfebb2a476d0b555782ea 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 492a1a5223c1a677ea3a73829394cfb0aabf3294..2d1cefaa3130cd0f601f54e1132227cafe9e2d6d 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 6aaa7fc8cb2763cd17acf8123c9a24fc15b6cc1e..69c34afcdac1e7cfa8ed1aa276dff82eeeb2e9ac 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 7d56350664b54073a48e3f67c680038e57df26f8..d8c4d67453c7b55194a4bbb1917002df685e0056 100644 --- a/lib/std/crypto/bcrypt.zig +++ b/lib/std/crypto/bcrypt.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/benchmark.zig b/lib/std/crypto/benchmark.zig index efaca227c13c2aa0b043bf1770f2cb677513625f..7d55b95a3f3dacd24cb862d3c12fc5c9d3658bd7 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"); diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig index e0b9eff5b90b033d3cccdf29bf59aabd2d73912b..e2107dda56f667e9ecdcaf045c9f4d7bb9eb6da3 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 75aba06da0c58f2592c2f04ccc265013baccad5e..6a2950645a3b300c50a2076c92884b5b3d7fc9ac 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 592116ddd4acd62971252ad5ffbf2cca87f01b11..11496034a06f16d1374db4a3609128d668956285 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 b9a7e48adc1ed85551212a535ca967caa0ffea0e..704ed367f049ce86d0a643016375ad434cae964d 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 7aa67212e4ff479871777095192a38ac318edc6f..c2342137043d9e7a7fef7e43a2e76cc7d73de4c3 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 81c541231dd799d92e6915a6756dfdbf5e399a0d..8de3052a0b08417f4725bd98c5dbdf3f9e42c617 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 12c4a53e0f3657211651521d0ada71c4d4d033d0..5ff37f8112e95048dddfdda36f6407bf2260d054 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 ef9907d18b459cc5bde97b53db643a2bc2bd6d00..9306c222ed3dc80aa07417697bcba3574385a830 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 8848334dae7e3e0630ec6e9407a8f7041f657f98..d2df2ce15a4711278cec0952bd20158618b342db 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 b3e2a32bf3088043b96b64eb3ab1abb74cb9dc58..b8f03bceb717934042dedf2da1b67e611bdb5233 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 dcc97bcbe5edc9adaed1ffe6cd83f183df5036dd..02410a88590d26a4631be38966c1d2fb20639c28 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 15de1fe43e21ccec602804f8a3d34a8f5092201b..c36db58e87debe0d53198db6ce97eac8f6ebdf7f 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 afdc3fb50201e7b20e2ed58385f54baeb7eb7cd5..265300a7a6bb04786fa022a3be26b57d612989b6 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 6bd0ac43f2f1f336c2267b9a4c38a22fc7b0410c..0321d0574c4cdb4e290d8ed0dab86822a7c5491f 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 index 812c1d54ff019ece70661f47c50316c60078bbf2..56fa76b5c0f823c2486e3190baaa6f9c7a52f672 100644 --- a/lib/std/crypto/phc_encoding.zig +++ b/lib/std/crypto/phc_encoding.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. - // https://github.com/P-H-C/phc-string-format const std = @import("std"); diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index e93afac859a693aa52f65b691f32f1eb0b504a98..4f16f66cd039df5c4107d624578c4f505f0ef9ea 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 55e4db13f0c41ea78c55cad9abf438ff87ade82e..45dad75a8f39f45a0e623c00ac0dc8e5382a92f3 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 index 8d8e227408c7917a06759dd2721a232eb37691d8..5dcba41531d6564844d1db2989cd0cf2449eaa05 100644 --- a/lib/std/crypto/scrypt.zig +++ b/lib/std/crypto/scrypt.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. - // https://tools.ietf.org/html/rfc7914 // https://github.com/golang/crypto/blob/master/scrypt/scrypt.go diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig index e167a5071067d87ecd7c0115c2e80d7a38cbd3b0..b464fb03f52afb856a831e780315d1531605a457 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 eb0eccfa84c1d04abb59cf6a6ce9f75a0b9eb7d7..2d2a70c87f9be93519d3334086dfaab9e082fad0 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 a4637c7fd4df309f9b9953f9a213aca5b6092f3a..db8126d183d4f2f60448c179eecc245ad9f9af48 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 3bed5d1086e6a8b2ac4fb2dd414a3a3d888f25e7..c984e04490a18b487280334b1fb87ae5686509fb 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 b517fbecb16db92f1d87844737ea29d8b47d2111..656fa89cfebef84ddccc9c39955e3bacd1cfa5a0 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 15a356d3d3bf2e075941eeeac5853241fb213edb..46960cc0907a723001356dc566cc9b11abf25388 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 da7c646ddeec589d999429ad5875b13f5bcd7246..6de5672df3ba33f76d19da785821b5cd42e46ff6 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 aa7a979f8ff851996f2760e42e3248401c527bb1..13f8a4a8372834f2abc94290e740b1cc82cea08e 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; diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index eb22dba7c03833d01ab36add7f44a0dc1cea46de..3a294c2dd36268dfbc513a9d0eae0772edbc72e0 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 99e268beb7fa3f0277c3439bc308cbac14bcca80..a40fa8a2777312dd2447b2620124f0abdea1f48c 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 d1750ef761a0bb5c8a5d841e3b4a89baa2db14d5..bd07003bad8806c110f3a6deb2b5f787b9180fb6 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 6c90dff929127f53d923b2ab538c1fc4e68a54b9..69f04868e8c3d766a6cd0a63d0009289c2418bb9 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 95c6fc7ec7eaa917d50f60cfc2f7203aafb8ab2d..cfcc8e4f1d2974b5195212bc56855959e4f8de20 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 cd4af07d646df1f6bca45552312a7738e4d46140..6e608b54f04b9d56bcb3ab83912bddd3df332aa8 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 af7f293cff77270600c8ff66534ca91c485716a8..4165f88f486c354b87e128fa9aa57e7ad23bca1b 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 3880d6e286f9d119a60fe62523505848fbfd9ca8..915681d4a6d49b1d06bf11d3663314e3c1073131 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 81326f3fb6870e026895a7158a784359405ac7c3..17a7c3050b0a5160a7d9521a7d7afa797972eb9e 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 1d12689affa68f96e0293fa426b25bea213b0bf4..dc200017a4769977b84f11bfd56b7e68d8a31ac1 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 c7aeff10662ab470a56eb40b2d82707381a8c263..eea6a31455aadd1d09bd28fee1a2a9f026c19c27 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 c9303274a927bad03b9e6ed3d20d4a608b2e0304..e921803447c4740bea1a921b7950d29d00dac928 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 9c8550d459d16ef06c8c12d0bfa5549590aef26f..50fb76ec9d11bd58995a7a0d998e10498c196f1e 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 3bd0c8603564d560d84bf50161014f624490f34d..43d41b860e842fa96a27a638b38eca9575d47d2d 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 0272ca39c7fa4009cb711e2b2b14a9e8bc75265c..9a569e8f1f97b44430fa976c1ae9fd752339fddb 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 dde01c61a3cf95a371f851711c74f1b399bd5b64..2275a06d08bbd2e286ef4c381dd1de1514db92fd 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 8377fd13b5629bc638d5fdaa2ced2ecfc7dfeabd..93ef50b861a1b9677ccafec1f148f5eea72879f1 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 a9895e270aabd71dbb024695daa71b7c98ca4399..dff9e893e3d331aa3dc5f33b11d5581204425006 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; diff --git a/lib/std/fmt/errol.zig b/lib/std/fmt/errol.zig index a4f46e7f136a620e2a326b15c63827ae237bba8a..e697b7d42fa2f62bc7a3be13de6948290af6b62b 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 db671b8d254b97379598b5009bcc2f118e13928c..c27753483d168ce07c0f79b64f6e310e9d76b3fd 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 4499d3fdefc81042e46d0cd31bc3e8c1f69cd87c..2fb6b167bb49c1eccd28bd95700e2e075f4e0bae 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 ed6224b4b91cdf54463af0ead693d12c5f4ba90e..585c23ed540c2421bbae9d737bbf50791e4e3d15 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 diff --git a/lib/std/fmt/parse_hex_float.zig b/lib/std/fmt/parse_hex_float.zig index 042da605499bd2bde0b14c98cfbee145015d6135..45a289fdd25b4707159b79e6f4892bfed7e4527c 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 cb33464dd2190f8d7aa1cf4caf8bbf5fe53a06e2..1e02c0e805cd46324d9ddd5f5e840ef65960ed39 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"); diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index 147ecc7608612160024f8e4bc923adf3a56a9817..1dd5e8ba9890af583bcd4791276365f3dd138dae 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 41b8e7311d8ecb9e520b511d784fca5379d7d038..fed1c85f39858b64370c009da3562cace81bd792 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 baaadcfe59dcc0715306a8b485977a24f2e51a28..efc896e6b73efc215c183b855cc3e22df489b545 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 26abbe5158f1a3c29432d012bc15f85a52ae4998..0ce416454ba5fb56aedd1527760921a09542f5b8 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; diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig index 2bfc384773ce1ebff1b933dc8cc769118b509330..ad354e226f93e307f204f500a5cd809816d9d6dc 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; diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig index 40867bb3b570886b6a661b623e0826ee8fd08eb8..7777793b29bd0b4498cba7f01f93d44a1a16d985 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 f5b94725e2cf8319b5da6ac5e47db8f010f12b9e..f96d331d0fde18e35de4c0392ae1f798ce73d99d 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 61408e82ee76c613835aa95f776230f7e42834f7..78f52b539b2119d7681c5daf96556300e33efe91 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 3375066c12233a9d88e4fbc63276580fc5db8bf7..4f037349baaaee990daf860b525a40ceb29a91f2 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 5a86afa0569c707b1f3370b409ec13f35a6a85c7..b4952a926026ace769b405d7917ff090852a9423 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 8796eb00757dc652a79c730f4ecdeac9a06cf9ac..c6118c8cdcbcfd6db605ecd0180ee2dfee38919c 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 597a0a4c75266c0d55afd6a85ed97c19ddce309a..0b7a9a7c517caca17634144b28d974ffd462b46e 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 7dadf5488ff069f48dd33367c3ca294779cca7c9..3175f26820120328acf71dcf156b7a57276c69f8 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 2c6ec2bf1645ed29c2daa2584d712257fb1a6060..adb150446d3eaf5c8a6fb4f39978245d9956edbf 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 83cd5e097c97f56632f6bec0b572d986911ed676..05340592a972d4f1db378c9f0613023b1663b694 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 77d2df2efe6f81a0c5262969e9e6a79f35af5789..5f5321dd560c8ee1425a73781fa04e7c6e9af81a 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 088d6b39bbf772d0f79afe4ad1eba7a9068d996d..9032225b394c6c1b3ae9ad0f8843ab2eecdede6c 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 356d5c5d8155cc12f32cd3baaa843a77c3877856..d61f66ce4a50968376063678517ba2b9789f7a31 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 006a41dae83e3e32b46d160bac6892d57c479422..d51c349be22d4a96e482f10ab59f1584b10a13ec 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 c2fd687e0cc97b12369dd459a3c50bb5e4bd7e76..cf9c4162a74225935e69a62d3a9a566b8086aac2 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 7baa857f00f64235ff348d331dcfd623798ad7e6..5bd967b6965a444ecaf2978f26fb04d516d709aa 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 8bb9c4d2c09861e0dc2af10434c37d6740378ab4..4127a7b08b090b14972bd2a7d53b61676a0f26a5 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 9092c8a62d766c32e35a54454bf28fb4098e38f2..cb123bacbfc566fa449e350cb4b1fd152e93b069 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 daa0718a18c46e2e1628fb88109e304742e6b050..5236e4965a08cd1ab1234aac09d8b8122a316234 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 1aed190a47c5c931f5fb428f255a6caaf59867c8..5b27ba78f1a4a23486f33e41a8ad670c38a84d6a 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 16e6480037c0570c1d60fc77b63dd2483b069a71..b803e37602e685bfdcfc46ccb551a2bba0ee8eb4 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 056ff08987f3160018d0613c4c89998b6e3010e1..77f556f2d2f0ea0c528ffcf276348703e25664e7 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 bbb7f1daf301a312ba2bc6de1cb427328c767d3d..758df71165a28867e306c266ec41d5c9205b28eb 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; diff --git a/lib/std/io/change_detection_stream.zig b/lib/std/io/change_detection_stream.zig index 57ef8a82bd64fc3cf72227ea5f4216a238addf25..5ba2bb3c103b4b74a3719ef2671b76e3d6b620f9 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 3b06555deb98215c6366f3b0aaff1f88e1d26b4d..54e8e6f531a3a165d43917e79d07ec447564c277 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 28eddc1303b38bc3865bb6a9eebe5cccfbd49c7b..ee86c2a9b1e00f99eada4f043734267feb680efd 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 db45114d3e4eb11731c431f33e08e414bafc1610..cb7efac2d9358969cac9cbdfe2c78af565f7627b 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 8eb7c62a65f1d1fe4452a297664a16912febf84c..3623ef19896dcfb1ecee49e4b219aed02382713c 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 1647d5aac3de6fca43b136fdb93e001001b3b7d0..aa00af0d0925fa57b2447e5c9c7ae532d75b0c74 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 9676212bbd1bf5b9f923399afa3d55bf2650f88e..ae683848d0dec625e9d5010972d09bbeca132fd2 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 f3b8ba66457b80d9487fcb9de6eb9ff7954fb94b..c77052f975915849abdf9b7c00869632ab734974 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 0846b14650bd01431f65c580be95ec1ddfa5ac87..3e8eb8ec24d3c212657cec1bad79f329c15faf81 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; diff --git a/lib/std/io/seekable_stream.zig b/lib/std/io/seekable_stream.zig index 4ba39fff4281930858ce61f736c13a853c40b428..1aa653dbe52cc6297c94b0422c35c74b46515b6c 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 1496c031bca7bc65dea49f508a3bb8bcd2e88c57..06903b2977edd6429995d16b5c5ae7434a069ca7 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 c04da72230f5934dc8b223e8eb802055e104f884..f5cdbc279244fca7b6295ae106a4cecc083edb49 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 6f9386b8de137daa77a273cad7d7bf1a0ca38e47..4f809dcca593b28136cd374dcdac4eb758bf1188 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 656c91c08021952edd4474f835b06f6db62d90fa..ce9ed9af7db9e479cdecb15e505a190d86c37545 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 diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig index 027f6acacaa4b4d811cc9850da94d979564832a1..c13d6b84170687df67003dfbe1842dac6078030c 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 c9169be755e59f957e84b1ccb5f9ef9f0fae79cf..61da6ec49be09576195cca51e7a6b458c3395a35 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 6535c867f89f88b4d912331dccda141ce1fcfc12..c908b56f694bf2fa0967d1e34ea37c7a2b8e4f36 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 7bab3e21886b094db209a4a28696a8b65ac9cc95..5039e16583ca06d53955612c311fe9d4aab1737c 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 1b3095e0ee1621113082cb88696c2a45b1bb54ed..02c209c68037ffe7fc39ad7cc79d31b26b606b0e 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. diff --git a/lib/std/macho.zig b/lib/std/macho.zig index 14be755a7000ad53378d3756d580230804e7584f..3c41b65522a8f4c66650a6c4aaa1ca77a14d296d 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 55ef506366c88e2556edd6204c356601a0c503bd..01cd68e0edf73478fc7b72c45fd123d78addac5a 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; diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig index 5e3a289691f907a7aaeed6f841dbf0c1efd4b65c..b90ba9c78ee617042219dc862cf8baa4a6cffc21 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 5e596a7bb077c102cc31598cff2a55942ecb5a65..e42f4fd5d3ebb274bc463845b3e22c32bdf5796d 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 16560a12cd35f4d88296f9715bbde84a1d6de988..0849fac72e1e6fdd1a70a54cb3843750ed84ba68 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 2855a73eb8dadbd2decac0c269c12aedf2c7969f..71f7533b8924cb8065f3e657726bf4e4b64d1157 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 bbfaa22b13061c0282f596a131e5e6166ebde35e..c67e6fe8e0927f2dc274ed7fc71f7c5230c7e53e 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 21f6b95b8b9b21ead40c361b3987f0193473834d..d440d65e0458c4da69d2f7cdc3806fa964bab344 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 68824cea7a6882da7f6d4b28f8d95aeeee0356dd..2c27234cd273d837da8cacff9d8f6312c53a5a09 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 8ae214c666a6a6f6ad68e0754efa33908466554e..8c0f7f5e1ed9b436be7102c95895e796b997a4cf 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 cbae123189c116f0d9972e534da590c2be9a0e80..e289520e5790adfa0c659183a6dd5d12e461870b 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 f4b294245aa776d6cc2313aac856c94776f862c9..757f994f7e4e503bc106745ca7ecb83c9161c172 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 8b7c2d45d627bbd60397bcf7a5f24d173deaf8e6..64f444eecafec10e90f5f735cdf314d2cf99791d 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 504657894d982037249fb2c5289554bf341d805f..1ff1818e8def3da0ed039dae3c8460d4a49cc71a 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 77d3218c2409a1daaed7ebd4e453ea95cbbb6d91..fbac2561662d36299be1bcf17ebfa741670e1ec4 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 7d37fcca5ba2e03084fd4e7b0554bf34161ee87c..3ae880f7c09a817c8bb11fafd384dea33a1dad6b 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 6890d15f8ac1a55df27963c12c51e0e9bcf7850c..87163605356d13ea2ffd095861220f37148bb0aa 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 3d02ad63588bc2362e697575de865f5e493f2111..12aec799e67db8196de0a01ccca55f6353461da2 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 c239936d47f91537e13076dfe585d1f3bb5c1b9f..6f20e4dda27fb09d941d92244f283fe6d7250489 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 8a79daa0732791e6b640b1f2e5c0cf7c9885e769..b2e960ae3e3af6d7d8032e2ce13a2df97ed98fcc 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 f2c377df5686e7ee602ccf1f1228876d2274f886..e4b97c693dbe746ce50c37c2b049d66bef4e9998 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 b1083c81bf98a879b57930f30af9319fbaa53176..bd1b8ee016b3741cabf6d3d55ec9fee59bb80386 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 4550edd9655c0ebedb50b5ce2d81ef5f6f97cdbb..484b41edf5344d02a8ce0e2a1329f923ca259333 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 41232570b5ef04be86b03c26b29a6ae5ab82ba76..01ddf7a9025d571c9ff18971417c5caf7b1e4bfa 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 ea4ba7356c095e667de76efc8139308e54b91c41..7427e44caa3867eb374317b30dfb00a442385408 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 0760485bb05b3c163dcc46f1aea12fd33ca38341..1c470c44c12c9398c2db1af01cba19826afd10aa 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 2a3673d4d10c2548d810906587c21affa97079ba..46f7a714a23aa94adfe46963c3e7be45e827d939 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 80fa837ab04e763c2c698a6ec0f8e29a22e9a228..f2ae28d3fd7a950b9397af1cbf9953c1b4ddc110 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 c0a6c7a934a6ef4d119e91caf544ff8a3a05c8a7..db710a043869ee4875fc8dc38d2924a3f7c429f1 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 e59870d556bef18c391e15b97a4c099190ed4f5a..90c51058cffeb8ec14b97c609428c36bcecdf195 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 092c8c2422c3d9d5ed5e0298ba078993ec78a006..36c6796431d3f319bf23fd88bc232b2b966ba6d5 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 8527be2293fbfd34cfb8426bfc4b489dc80a6e73..1e4b13f0df8ae9cc8a0569ca2e0c064c34a25edf 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 39b5f584ac8415d69046fc150639c391904664f2..7fa3fcf923f917724900f4a41dc04f0349da7962 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 05d1d11bd2f4b3934bee371ddb1f57fd9b29ce87..ed344999ee164a5743b083b9df9f5854d4a695bf 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 07fed152fab63773e988f6818f9ff37177b850ac..4f16e631b836971922153b9b916ffce219734d88 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 0ee34dfcc22b5b6a7cb021cd203303dda32f0c4a..9e1025f74f6bb2d23adc30cb952eff593a517fa0 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 51dbc0fa90d2b7fc4fa06799ab493e3ffceea786..0960c66679a80a4e443bfead4efba8aec5dc756b 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 47065fedaddd716720f546a7ea05928c9ef3055d..72057c190dc81430b950313009c4bd23ba0a3190 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 8033b46692ba2a692b25e3a1cc077df4f9594d43..fad524fc88c47c29726864a5ea34298029791c0b 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 f252aea805d4e1f0740562a7d191c5171b85da66..c71e82ea1c710cedd52acc1c5eab0005f61e127f 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 61758f1ee035970bd31191e6feb9989a57b95cf2..de0297ee630b26f2fc9ec86f3a7328befec4adb4 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 43da387e46fd96a489416ee3d25c041598b206b6..384c4efab4bdcbf4d40c4994c565a7a93dac42c3 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 e01c997dd765f9063e7d4904934c6f293ef9ecb4..502a305854abe9391312f7b69a6a7e2f263b5d0b 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 ebc76165bac9e179d9dbf4ac92bbdef6df2b131b..5911edf36f98b4866ed845119927153b4b155b73 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 b88d4c2236a59c1a3a863fe1b6fd9bd5c817a899..f404570fb6928095d708f35804385f283c86634c 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 0b3c800b1238dbcc704b352c5f4118c2a6c74213..1221db2390328e9b21c63808ce33e205fc3c8e16 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 e4855bc0715f81efd9a8b491ce9e8123c5939835..c5ddb9e1441c09ee9f3a35cb3df57fb350d2e88d 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 0bc3271e36c3056dc5b1bb0309c27e5968baac35..ea6e15538f454406398bce48e4258b03f0b1b00a 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 4f3a03b0bc3ae7268c00de9a2aded5b080ffeb2c..f0d0c57af50ac0106d26125a1a3c3a910befcc8c 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 4c2c6f1d8a0e36140c46f0a1006e0b475de39a39..e47a1918928d758e5129ee08ed9d40c69bd83033 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 deafeda7ce899b67d0aca1656f1d53e1ed64029f..e8fc56d1f8ebde2a0deb7b88300744933a722d07 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 5011193e952770bbf5ac36feee41077ec387c23a..86ff2455332ed188f7a9f9d4fbb6e5d598afa810 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 68aec258b0d00a35c2ba1fac59fb844fe9367fc1..762fb399910ac5ade4e6fcbe11a66e7e907e9584 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 792e6b38f344d96af97d21222e7451f7d2757d6b..cadaa8d937c5fe0b3f7348a036bcb5983ec160b0 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 cf598322e5cd3d057edb99332640727dd45239db..f28eb9ce8dbee6b21cc7c53dcf4ac376aef10ba5 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 f3942d121c0ed2020ced0f92bf6d596fc437fffc..0430e1367a39602b27b9e91d037e21ae1a74ff3f 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 f85571fe34099e2ab03c90b4ba8493574fc310ec..d2a5ae807ed481b71b05ffdb726c10d053ddca58 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 bf170aa95b6912ff202e213ec5497129d658479c..cab652c62087964b03731b2200066447784f4c32 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 56e4afbab6168d6efa22fad02a7a39f023706a51..19602fb4a2563262840ca92fa5900ce8e4bc4c72 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 f844332818337e26bb9aa2764e8f9a997272984c..e186b2795a4adebef7dc2172e4a569065e3fe4c1 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 1a42404fea4424c387aae49194a12fb61c3f94d9..fca941c49a0ef600546d84fde3104cb542a4f973 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 2a8cf00bbb7c6ed81bd65dcaeba413b8bb5f5fc8..d12c49772981e7b5dedecb83dc4f442338bcba67 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 98051b155aef6610529673766490c53c4e45f257..5a01a5b3bdac95593a334f3d6cb5029ef68b2565 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 732d716dff5e16844a6ad494ca6c26c2696b95eb..040abf9a4484febd6bdd3513b4e1cd6cf861789a 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 ff7f44f4835d3a37a35f4bec9fef50960e349762..6c4b3a65f4e65288e2f5563d2ce952bd5344568f 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 863752a3f59c807a35b7ce66f173330d5e32be08..7e1ee1ebd1c39026ab4aaf5ef7e0b057a9dac135 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 bdf382a303f03069954fd461706d5dba452c340c..30494c820a7192da923f58c7236fab062ba1debf 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 a1f2f127d4647cf9e94cfe32e124a217bcd78c1a..056add5ae6d8d8eebece47a93c70f69dd6cd03d6 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 83cccfe8bffec25194b62db08c592b9ba416dcc5..4754e9502b2a140453e2ec5cc7139f89140e413f 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 5a38e83ba9609a0ff62790c8baee8cedaf52024e..5ec47fa3b587baa954c721d6fa5f77952e0705f3 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 5cd224aaaad8949d3f09f53d3f4629bdc138415a..d54063dcf62bf80fb54982bdc0fa8ef9a213cf85 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 7fedf301c4f469c14ea66a90a691ccf5bb54245e..d2c5009fb67ced76959c2f7a435bf5002a11fb36 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 8f269db021b38d84c72be0c90b58b03e46b2ce93..dcde79a925a54c139e9d27a75b55439cb9670504 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 0d83dc608d042c73db35cc70c8a3ea27d52d36f4..eab9a8b0c7cfdb757708123ecd0ec7f90115309a 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 a0e87f26a5dcfc4da781c233a5ca2ffb7418d0ef..57d5a383119b2be51a553782e1f45db4bc7c735c 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 1e13ed97b74d55472ec5c064870383782a3933cd..9ea7aeb90e2a7db5b2f5b41dd82bf7381868f61b 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 03fb4f80f145a5c6c96a9c40ecd987bcefb81c85..a1bfacf59700b3a396d93a0cef6721bc3f35d187 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 595f6917d916ebd9c65787a43a9981fb52b0af90..516a65cfac825470fe558e8708cb4c24d2e18f68 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 26330aebc476f01f20d0cf177972532475fbef16..d1590141a16f0554da2921b202a9b78e292cec94 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 9707c0634aa9847b21ab2a39e4c4bb995f01aad0..693937b399b522136cb2ae6fb72839106f03b9fe 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 fea033dc9cfc385d24c2ee0df7fe7c47e200a075..c7411d9ecc7721b054fdd7d2dec762b2547430fb 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 589efbf53e2183b3c56a7f26c447b3aae3e45b50..2e63fc9329c478bebf2bd799401754ce6e1f1dfa 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 a557f4aac9c99d3f1d9f4a53ef4e590ddec755e3..638d3b10661ec28e67b6fa0e66c3f50b9e2628a5 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 7781233a490f3a7043ae59c98c25d00e10d6fd96..294784c2bdbb4cb9885e16df15803e8096b7bfea 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. diff --git a/lib/std/os/bits.zig b/lib/std/os/bits.zig index 5c396091825f358816ad0a0c99e96dd5a94c455b..36eda7707f9634de8c3ffd990fab0f7d1fe44855 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 35d507541e52ec0b0202e21cb51327fe5c9835f8..a0f5e5a400cfbfa70c281203e91692cddf01dfcf 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; diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index cf647a8438283c75501868ba0ad25bf1ccca6621..c13a3aea910e736fa19ddb1e62f8020fbff762dd 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; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index b60676e266d7e5cf7c1ec68413c7ad9b15348966..51b7ef9f4dd3c28408c375a6683079dd3662a08d 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; diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig index 8421c80a52b5c2c27683f6a297e4b44d4274793a..620bf2341404cb3a12d9b16b4e383a96ebf0e88d 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; diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 1dbc552b3c589d032ddb3189f8eb407a9fa17998..653fb8f1e1b47e369c3dc5ca433b815d1694f9c4 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/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 arch = @import("builtin").target.cpu.arch; diff --git a/lib/std/os/bits/linux/arm-eabi.zig b/lib/std/os/bits/linux/arm-eabi.zig index 335ea074ec2ccb075c299485202a6e8048d3a1b3..91ca2b32d2b4127798f9188aba7dd1c999c24532 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 e0771e7f662e4f0619b9042958edd3035a0c044a..67c77ce186cf6b7472d406fe7b03f914f610a312 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 index 49b35f650117c7fb0165f5312d29874c0d890d1b..730c71a5a2f30b64582f444fd98a0181a9b414ae 100644 --- a/lib/std/os/bits/linux/errno/generic.zig +++ b/lib/std/os/bits/linux/errno/generic.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 E = enum(u16) { /// No error occurred. /// Same code used for `NSROK`. diff --git a/lib/std/os/bits/linux/errno/mips.zig b/lib/std/os/bits/linux/errno/mips.zig index 4f14db65ee40d7dcba80c19ff3bdd863e569dd60..39fb9f71eaecbfa01aafe54bb133138942259820 100644 --- a/lib/std/os/bits/linux/errno/mips.zig +++ b/lib/std/os/bits/linux/errno/mips.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. - //! These are MIPS ABI compatible. pub const E = enum(i32) { /// No error occurred. diff --git a/lib/std/os/bits/linux/errno/sparc.zig b/lib/std/os/bits/linux/errno/sparc.zig index cc43ce1a94c941008d3b64566bd4ea8bd82ea5cf..c4ab65f34a5aa84bf3ce2a5f225a8705770b3203 100644 --- a/lib/std/os/bits/linux/errno/sparc.zig +++ b/lib/std/os/bits/linux/errno/sparc.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. - //! These match the SunOS error numbering scheme. pub const E = enum(i32) { /// No error occurred. diff --git a/lib/std/os/bits/linux/i386.zig b/lib/std/os/bits/linux/i386.zig index f8dadb8a6026c5895041b93a5ce594dfd369b667..12c8fa4713732b2f2f868fdf63bed590b8cbf47d 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 e158755889558a4d735402859b9fb5f47ef4217d..ddf241fb4d380fe3ea3eea0143f16a629bf3b5d7 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 a840a476257a94a498b2b43da09faae18b01cfd4..9de546fb208ef8c53fe8d0d1e0d2b9408d018ced 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 96908cb7141ef4b585aa3efc8062cd79cbb8a728..06f8e326ba2d125ef449b3f90ee608d642e9d396 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 52b9109247f1ee66120018d0c68f4fa289c807bc..74c6ad11fc7a3bba448215dc600500496d356376 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 249e60eca3f46a711ed8a962231cab2c7259224e..d29b6021b606def81eee77fa0b9d142cc270d430 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 6147bca64f7b1adc983cb55351114f955bb03cf9..7a0811cc1ab048e772b9ec6d0e99850ab9952def 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 374f7c9f02dcb1e7a88dbf962229bedeab82d127..a23ced3cf2ecdde7e559d60f4306163af4d8ad32 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 30e5af384f9c6a96a353df448e5740589b59501c..69beac9d878fdcf2e6a9950948f5832f3645675b 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 be615ecf98f3220be0dca47cfd607e8d7c33867f..88fa9918a356ab94203a0d9fd8c61417756cc1fd 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 f1bfe1b958a87695c104f9c940bed1edd90c746f..be35889042c44566b823cdb710493b1631d44cc0 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; diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig index 5ad1f8980bf8922dd49e93bd0eca8093afe40dc9..c7d1c0583bc62370ebaf76b5bfa9b1fea88459de 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; diff --git a/lib/std/os/bits/posix.zig b/lib/std/os/bits/posix.zig index 0f015cd57356c62a2943fd944e631837c13c5f1d..6ffd2dcf6a061fcbe7b4ac9df4bcb743a2629dc7 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 eb68946f05d8dcaff124c5a2bb35c0a9e110b3ef..567d74961ef8f72cf6c99e5e83cf211138ffca4a 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"); diff --git a/lib/std/os/bits/windows.zig b/lib/std/os/bits/windows.zig index 3943d1fd3d35de82a24f16892421958da7667985..bb57a13ffebecfe218530e6d056fa922f1e1ddec 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"); diff --git a/lib/std/os/darwin.zig b/lib/std/os/darwin.zig index 572b470239fecf357b0bbeaca36a52950788a790..5f9684b96de967ee7422a2d96322c156ed2dbdbf 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 572b470239fecf357b0bbeaca36a52950788a790..5f9684b96de967ee7422a2d96322c156ed2dbdbf 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 572b470239fecf357b0bbeaca36a52950788a790..5f9684b96de967ee7422a2d96322c156ed2dbdbf 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 a713a009ad7efb65951a1cbb2ae7dee62274e608..5f9684b96de967ee7422a2d96322c156ed2dbdbf 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 841f77467c748d75760a0e7aaf1158306723a950..369fae8f5325a72edbf87707314e49a55ac375ba 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: diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig index 469b7299d194c3a720ce03acb5c60ca90879ba1a..ded72fd100cffc76415eecabb11c61a0b51e328d 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 4c8306c048d980dafefebc1254eb4742c7c478f3..92942a16cefebeb2c0b185e80f923fabf7bd7e7e 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 8afd85162941ef0c7358d57986333647a7344bbd..cff4acaeee6afdb023e8fd350cb935afd82b3a3e 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; diff --git a/lib/std/os/linux/bpf/btf.zig b/lib/std/os/linux/bpf/btf.zig index d8a0cb57a908045a00a58952cec527b13d45abc8..35eaf10561068221f9c3f62106f8257da8434cd0 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 ca713f1910b549ac38742077de8686f1e60d41b3..05d5d57059221e5ddee5cef3ba827d0b16dfe4a7 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 757c37949b8c0128b645550656e081c6857bb467..86c86c1ec5a6ae946ce73555787851c7580e442c 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 4d489eef5c4d4f2a133fc5c9a410bb394cb258e1..729495e91d18036abfcdc87c906bf05180ac1f8f 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 2ec34bac40f2547c481282bc774427afe3f84ac4..70178656d551da225ecc3fa6b55a76b8addd9d1b 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 1db4c30d2a51caf412213a3478df8e4952f87c27..b74a7da3dd0dce2e3c2bf3a9a3703cf71526868f 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; diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index 85157f04f865f39d14068c7c67fc6a88c80f7db7..5cff1e92657dab232b76e410e085f9e9271c309e 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 611eee1c5f0bd8257d35f0004028379a0b677a53..c48d86a155e929a113c5f9aa926bdc50e77674a6 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 611eee1c5f0bd8257d35f0004028379a0b677a53..c48d86a155e929a113c5f9aa926bdc50e77674a6 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 3e2b15b599c016cb506c94e38836830805451e14..dfc7e164e8c796aa96241bee0143211ae11bea2a 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/test.zig b/lib/std/os/linux/test.zig index 8efa6c754f1bcbd7248cc584a0e36ea97f8b773a..e45c9dbb993715b27e1e84fe4e87b088c9d73a62 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; diff --git a/lib/std/os/linux/thumb.zig b/lib/std/os/linux/thumb.zig index 85f8bfc52b41c7f3dc2c8889767fc0a5d7f106d2..d965e4430ef82722b0f3b0fdf9d5e93481635519 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 5649cadd8b99ea18216687c9b77e4826755bf0b0..47230cf7869d995ff91273d5d604f92a36f72b8f 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 f42bb064528ba5df7b898f8369b43fc3f5c6ef6d..f059ccad4ef5ec5875173251dcc12f1f4614e842 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 5aa32c56c3023da92bb55c876329ca3e237f2188..c403742d3d265d91f4bf4987a9c0b36eb1db60ac 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 572b470239fecf357b0bbeaca36a52950788a790..5f9684b96de967ee7422a2d96322c156ed2dbdbf 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 572b470239fecf357b0bbeaca36a52950788a790..5f9684b96de967ee7422a2d96322c156ed2dbdbf 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 fb23f4459aeec22c99324be225792e7a4352d10c..53a040294e9bf3d2fe8cf1effe9a2c5b87f0514b 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; diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 4bb8e375599e13087bce2eee604ccfa69e77a70f..b4582c121dc02b89566b991cf5e3db5e51a9ba36 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 68dafdcecbb0130611803f6bc17c16d002daa8ac..353c628a0582a5e1977a268c05def60ecb9a9c20 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 3dfe97233194f1639d84b743cbec71bfcb359573..ee795692338c3a6ac88e444ed0be43c137d26d6b 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 d6b239fbbb88f79d85f4d123e177dc766a9c727b..df5949882207fa25699d4e7d3d5eed1376eb4499 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 750ff2833b17fa6746aeaeb6340f8839cd273659..fcdef78d83f7090b13d1c087b66f7d1c19d2bb1c 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 fdbe59456337f17f46bb5f08730630824c560738..00b59cb6c816ad7447ec566a7cc0d9c61d6339ce 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 ad3a0939b552e7152f06ddd37c065dfaff65bc4d..8bf848c59abd7e5ec46aaf1b7166c623ba0a8160 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 a1d001065c2a4891f2a3ad76010c9478cad6c931..1f80df0af2d12cbbab304ee4e7d0bf2b149ca01b 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 4cb7744e8a2ccf6eb47b94701eace2b079100cd2..a3bb50f0d2143552ec9a01b04c8b57ed84de7211 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 9d85f293b38ef73be47f572229d426b4478a9293..5e3c23d22ab810bfa0eaedb3c2e2bf029216e762 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 33014e1cb75de388be719a00e33aebf85138c6f4..e34f72c2f3b7ebdc81bae865d8ef11d43ee8a280 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 ebbc1608b7bbeecceffaf3ecb1b57e97162d4089..cf6bdf6da539e5fdc04da13a4f10af62a0d8f586 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 d6af0e5f39c0957f21b8cc3be6fa77b37d3c415c..aa9d783fd88232306aab921b3f27abdc95a2ddd9 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 fbca959656f5c9818af2560cb8af452d885ce00e..dbe0f163968c4764b3a93c8ab39cdc70098ae595 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 69a410c01ca132271e9e3fdf72d6c056a56467ba..97ab1a431c2ee9d2cdb60d1707c19d5773c1e249 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 a5c5610f9b81c65a82b894c648b5a14a2e249ad7..b8afcb1063a159f4d69c26371c9f203039661e42 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 0da6d902f32c3656d32f9e639dab3593b06750b9..122482be236d177345629f4cce51472ab1e9ea40 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 f0b8c5fb152d0eef87f0e038eaee5921a05086d2..e9657e445640664043523f98e1fd6de1449fc7d7 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 25f7c936c317c239283d1e1ae3eccfc0bd372966..a32b202f4428757128b7cc3c63cc1a235f24e425 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 338d88fc9bf9d40b4dc7d3e95d6d6fd87b539226..afbd26e9390a17ed4de3e0c6373d3aca1c55ccd0 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 68f08ebff868bc8decf9755721c7a63a706cca59..119c1e658723dc116ed599c586aa5378c56931c8 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 1cd93bc4917840b262e4276b0ba664c9b4d89bc9..a3743ac2c193f41b97ad012a907009000c18e47c 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 b76b5bc512a922f2ee594eac73d9db4d3c0117df..d217ab593027dfebb2da4c6673779281bf9d9173 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 0cc1416641030bb9bad142b44a0c622a5cb6f507..4a2b098e61a98efa19498d0de1bac46d6791e063 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 47e632021b54e63e22240959f6d0351461ab46ef..8102ea99559de3f8293bc57d03987457f15893f9 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 6fb56724c714f6ee928bdbfcb3dc93d1900f9197..84f540cb786ac7ace519b406473ca96987bf981e 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 c2e42289987fc72fb41a02b81697aacfe1b0e286..46c76beaa60e5ba170f94bb867656b3e6354e3d9 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 620f015722b9b79ae614c588222d378252f488ad..811692adc36dbdba5c017f56734fa73d927e6231 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 48b8008b91b84d45172148b40989dfde503ee8be..09bc5030eb71e5c8ccb53802c32aaefeae6098c6 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 649fe95cd25cec49be8ec25491264d8def483d7b..0011c80a9cd20b6976c1a33a5591095cfd0bc0f0 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 8617642eaf5e166fa941a29702b584dbc98aa83e..31ac352089f8bcdafa0242e45cacbdc93a46070e 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 00c8f2f42909da9c98361fe2a54c8717392b5269..0ac3bd73c8544c1630726448f0fcfe924f0d3a19 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 2d1a1cdb82625b0667da0e45b47022bc607db443..c3c59f957fb9da6aa4aa70d4b982d823c2d42dfb 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 c5b6c5f1e9f626fe30acc23017e40d77171ec0cc..b52104f9c7d62d4ab5dd09e61b2abbf2fdbe46a4 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 8af1895cad8cd98f58b3b10767817b2a51c6936d..d5d40942327ca9f9217d6b0270ddace16f627b1d 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 e99d2b820b2cab912b2054a8ad21dd1a444c3fb8..708f445ee42b455a71e01bac0ac930bc01e2c21f 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 diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 04ce43375821a12fbaebaf1d1fcaf6031dfa7a31..6972de597c2e4234c661a8e83653bd35d9bf3510 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 6fa9ae2b45855adad31d0a83f2b5e75fa355cedd..db77c4b7e97657898de24286a2c26fb99f0e460b 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 59a2a8741567b5c72bacffccd69ae1805baeb794..7bc0e131ea1269fa926240b798fb450522485844 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 c91e1d487cab2fea506a21cdb480e27dc48ee7c8..132fd80a34a819edb3b1df04cd2de8f2474194bd 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 a04314324d844a56d91cc8f2e49edcc66f3e431a..6996ad9991ac7c6ffd389fd772a4c84008c7e96d 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 40b363cfae0bd405f58fb4cadd6187e99e85eea3..b173a62a73dc846a2e174031ed54d55da217a5bf 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 ddc08e4bb22a4af4aa44fa03ee1c30775f3c9ccd..5a0154db6f8cc57bd85adadfa6cf4d1de0a69792 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 11668a72062641e43815240b9ab2bc3628b5b8f9..41ba3ac81f2668c65d1b5b49b98c963fe4ba32a5 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 bf1eabd63e75cfd03169dba6dc424b7324dcadd6..e4e04326593336fcee8c1ed60c8c2149e3998164 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 2952df163562923cd06d1636a32679ff96e5a57f..cebe03d3aa1f0753dfd0b43c7e3f85a8221a5dd4 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 d184ba10362de9cc80733c5ab92b93f8aec7265d..8739f9301e67447d4bef5e3337e159f224d4eeda 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 ecc46dbfc4e52c32c0942015ac4101f13d5d44f0..e9929c6d79c22fdd1e1f68a041bc1a0a3b23c2e3 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 8c18d413ca03c5e8306214d752c96b4f7870db07..8e4d88615c9e6ed9a63d2919322afcda956829e9 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 d996a0f3945941ce0a9acd456552a79c0efe4067..e4511b62d3ab3643a41cb724160ded23cc23521f 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 b66d1734cbc6f594e5313b07c64eedf1b7923b88..008316ca1371247b17718e30fa1e743f385dc192 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 69e4cef605e4cf4cf009dc46661a1c56684d4dab..925905fb46a1ea14fa7726f38585860db75d256b 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 1aa6daa3e6c60c8c79dd8c70c15a9645f6f6f512..be55966917691e05fc1637d93044c506634b4087 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 571aae6e4d013afdb17f45fa293366d5dd803068..e6ae58ff186669e2ede31b481490a83856f7627f 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 30b98941b0661282dc17c07497e726501c94c57b..698407a3a8f5f3131f05e71811e6fba1bf0d999e 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 81329a0a74c9b37467830c49d94665eacd256829..d154f5df5e216c1980a9616220c584ce9bfc8663 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 de68442ea75fa83d2f76b03f3fe0860ed4802049..228c07cadbb3cf5a8bdfc4bbcc2b23e7cbcb445e 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 db9f442e565ce1e2c03b78da4e1af5224e4f4b48..f8b986d695f23c5f008a329ad83a6c4ab8702ec8 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; diff --git a/lib/std/rand.zig b/lib/std/rand.zig index 7d967d3715e5bafea167dd4f8ac8ec3c305516d1..104be7f692e492636e7634c2cbee9007c7e38c25 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 8356c7afdee10bb8f77472fe5e3010a31f268c4e..3f1488aa6243d427300bd96a2b8b4e90aa8a482e 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 ec505b0bf6d677eca8e0124c386b2b57c6e9c942..c3821d81aaec037e5d4baa6826a4a86d4caffdc2 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 8f468b5ea397430a37df0b29841a40014728b0f1..5c9789aa7bdf4117fea6c8ddaadf34d215454468 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 1966a59ceb4c4f8c401a49fcd9e96a33dd98a5ff..5808376e78f5660a0f17913361ac0716ab129b13 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 4b507cec74cd64622c6d1c7a589052c7cc97ed93..43dc95afb16ac7e288b6b7e81506201d958d7d24 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 ead27b0fd1752d5fed2d7fefee2c4bed81e1e677..c95cfc164de8a3b6e38bd6bdc53f5052c16bc60e 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 c01f7c659a25a9636c95bdb8c47d8b8fffbc2226..2b9728fa96850d6db6e6ba299840107cb2b56cee 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 67a4394b1ebba1709ef7046492f910065461d699..cbc24d9abdc48537b70a6e338e046f2923841937 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 2da273a6738dc687463068cf9fc8edac88cbfd7e..9be6ffa671f35d656cdd60e86e19a2bae32f2219 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 a6de965f9047bd2667af9218b3704d41ae9d2be5..d34e7a8a46a8b0d678e2dea1302c548c348e0b36 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 69e099ae57178440fc3ca3c96caeefe316fd513b..27a2ba7a046687f65d9c4f3a4774d2acc1bd3ad8 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 c5c739768040b97fafdfe861913d812d04b41ca2..59e9393ad6c77823090acf085e89848dc012a6b7 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 33051ed97007c24750cb9d59e7ce3b74a1f89067..70eb203ceee479f8c8fe5aecee94d1b1f7d518fd 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 f100f8293cd05df6a95b13b0074fc96200196b1e..f30d2fd6ec545cba12dfeae26e01b220fb532837 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 4b1eb1f9e4b75966f716e754d9a4d39b60e1aeb3..b69b7a16ad2793ba3145db54cfe3d1784d6bfda9 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 118712045713b9bf24b19a8b207030249b9cdbe6..5ab53c3b78c592773f173b229bcea3128d5612c3 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 423c22fc1270a3493eaa4b70160b9c8b7a740f88..c40b9bc054b405fed56112634b4253e00b3a42e6 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 e6d1d7ddbaac2e21a674db603cf666961ce3f965..d456897a27ba6534eee2870fc8a943da6ef2432d 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 1b592da0196d4ae9281e39674e302f6bd169b63b..b6d0b55e33df049758b3e9c5ce2631c6c799002e 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 196c218e24299f7312d7bf80f25856b4b472eb83..7709e17e6336c8c54695d26c7169fc0f3de603f6 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 7d0eef5921672914acf7dbc0e30e3a603918825a..dbd52cd377ae4c9f6233c27a58caefc4d55c34e9 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 568373aabe1169ea87f5bd28e1dd95f6d0930a36..033441acdbba3031cfe8c34f5d662a1196b83e75 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 d7464d5ea9973e45b4105cb4d0a34c8fcd8d2ad4..29ef4bf85e27c57391e8034eb0db5bac4bcb0f18 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 b7828cf6325601fd95ee1e9d45e5cf8a5c794fc4..c8f6519b5bc948822925dcffec0014439b76016c 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 8a9dcf94923296dc3c236a8c6c84ef4597b3e369..fa7cdfe2a2f1f14146b5be21d3d597739d43568c 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 018d95c0aed3c0512ba258fafbcb85f884cc2b18..a80297ffbfb9438e3be70d937b755a315a7813ed 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 10ffc3c063756e3ca07813600c8b96e650aa7487..8bc2c679565f625e20b26a28d3050c69d5c9f851 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 10a548090a2bfd6b6c0006f7453ad71f7975d023..b39e428d96881fcb71e38518697d9d54bf9900e7 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 a472b5ed08a2106da4881823268bccbc88ff6548..28cb0bc4dfa5cff50833885aefc392ea936e821f 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 3f89f123135f1fbf00d50b8a6b39f43c0a690153..b44f19506d356bcb0ce3d2f4bcf0e320fd940ac8 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 97f34d34a5f0ad65beaab8ae41af3fac57e5e531..0c06d4c15a4eb3d8e81ae483c63b709818404da1 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 d8ef463e490719e942de326f004cbab059a38c18..ea71c7502f91d6436892c58c201db73be8970223 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 3915177091fe140addf6f446d77800fb7cef0ebc..f426f827e8ceab480f7c214451756ac36dfa0ce1 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 03bae3f3f836498cc2c793539e89e1f13ed82bce..1fb7947e6f61b14aeac77c8bd734e6b149fb1825 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 c4f7fd01b6a52916d9bf40eb753f7b669a7c8e8c..7992e4312fac3c73928b2eab41e18fedbd8d99e4 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 d51550c0d5f77d1afaf3659e9ddb35844338b8ea..5d018d84ae54bfcb3039955586bca6b8963fe86b 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) diff --git a/lib/std/special/compiler_rt/extendXfYf2.zig b/lib/std/special/compiler_rt/extendXfYf2.zig index 9a42a938b95b3f860118539e49bf3874853f8743..1c95fd68c1c114e4045a86d05cc6ae26114641be 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 6a53dc5b44d2ebde3c49079e899be36b6ab5f9d6..89545576a206d5c79af50f10983e2b62e93f8603 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 f827f22a4a7f7fe9e4d692f8bf680e2b11cc470f..11b50091294ed250563d21e1856efc02a8eee8b3 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 c8220b532d05a7d20490ed61d533f0c1d7502ec2..a9182cb7235da0c2690a4fad14ead8201838483c 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 2e9fab2297ccb9fe69759a811f618ea145b5dc34..8a6d8da34203bdd102de75614a46610d2ed5efc6 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 c9ebcbeddc9a4d78a41221347496cc2d766f8207..b3f0953160d1b0b42da9a3a770280bace912ca90 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 88072de0632ec862b4bb148297610c7b297030c7..0e21f0ba192147cee20614c3c63657ed90dd8baa 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 76f08f985db70ea04e1e91f2f52d7e98d52bb528..a66dc0eeef3b8658de64e19d73c24a9913352391 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 2947154d203487158feafe72360495139c0e60c9..6ef647410580d358253f53fb29494bb03173c9c6 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 86bc32e6424a25069025d5274bb654e55b27436f..e8249813d467fadce6372786cca69fa83bc2f569 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 9563af1a56a949201dc4496e3a2df0ca50505970..d0d958cdd6b310c295307c0644ae56981b79c4aa 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 e18a15d9a363e5f51f51653314b42d15e0a78652..d184f934edb7f1dba429604a9e8d43914a122855 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 f1a32d9f77a2acc17d2e5c67685b845e8549c637..84395d0fa67a8689a3e12f1ed1602d16774eb115 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 6bc451a697975e3819a1aadd45e5502c5acb04c0..588a76c9d438e6594ac49ccf0a1d75f1cd35d361 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 75c0a2fe1d70fe0efeabdf014b7f34b7c647bf06..d7ce4b3a602d6ffe9184e418270404fb3d63ab12 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 792716d5d3c5b73598ddf14f34fb224d84e71b76..220984a37eb34fd0fa00cf9d3b7fe38a4836f074 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 a9e37b777fed5052ca19fa7d75c086a34ac50552..0ef3aa225937ad6b4af07c725efdce8a1cbba70b 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 ef72e6527c873c5a24bafb6d880f061364b409cf..663023a475d20e1a2f3f820a82801baa1d04765c 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 cd92a972c49aaf473777e365907f2b0ee4fe0346..15e89a11b0b0820fda7bd70ead0a3e36d14b3ac8 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 61a963b07dbef18779cc37be873b80f527ca157a..2e2637f53b3914955abb2dbde91869cf44e453a8 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 cfae7c249b1069696d4048159bd94cc29e0dfd8c..733fa1eed1b0be8f4b89f480f2144712db3f039f 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 23ec67a737e4efa4a97c88b6d6a0512ec2ca3534..354e835f2758353ac28d5180bd0cbc31a9e7308b 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 518b5de4e49f0279604a68b2fc6f770b97b58a00..c51b80fbdb0bdf6ab5918f83d3b92effc6e424df 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 24a88236e002ccc97432180638d5487e55422c6f..800c9b1148ad4d3074dc7b1e9f48cee630e2fd17 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 dcccb076d4a8f75afbecc921a445e85f1231b263..59591cf18196208ef2e972ad9c041973fcd7adf6 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 416ffc59af32de4781415cdcc485bdd2616026ac..156c21a887b10dea35836310d96435541b22317b 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 059eb208c7f68d78a6e07dd61c50aa5f827ae2bf..b4b7ec8840f423c65e91f64f4e17e8dd9c134a49 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 02836a6f75a6f0af6713dec4dd91405802cd20de..3dcec6bf8987635352c1841137f88f331e9f422a 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 89098afb336e84b8656ed6a93dbee9ddae602767..d9e1424836b9af3572525611160ec8c60ab67429 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 77077b4344dd5cc1c0cdc545841e49340f07ad9d..ec00a7ee35c50814414320465012b127eed644b8 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 005e005a9b886922da48070b102cef8fc7ee8f7f..3c46511b6de4c3eeb50ad3758815e66907211f97 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 9c63424629efe14944d72ceb24428a86a1a165b5..a4e5a323f5927e856d9f33e34c1df024145fbad3 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 90cb2022309a1d844d342a90d65934d4ec736fb3..4bf90e4bff288093fda7691553721f9f8a90862d 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 ab5b95ec7f1827d2ce2d92a92090d7a68f0d3b24..dff9eb74980f6136a8af30ea350c3f42d1160ae7 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 6dabae8ba84f04f3cdf7043f7be9b30abb4cfec9..3c1a314e91f581b60885568d8684176df88a4609 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 2053b948e0391bf8a7d870e564c698ee40a55f67..907116c1650ee53ba9d5b3417ef5ec6253513be9 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 ca7a8c8c0dc03400c975427f96838b54ddea355c..aa746799b7248a72172284bdf1e3609af3f4d61b 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 3c317cd7fe02eebb2ea5080ae39cb633ca4d7cb2..c66a3f18b492a2bfa05a91324dbe5784a5db6847 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 f445edb59cab0e78682b3da2b8c0345a5865b9c2..206161bef593ac42f6f16f57d30747d106f36cae 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 b089fedd3ff2cc23370e9169e0da5c7b305268e3..1867c69234ba49606f774885efba862449e7dedb 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 94ec32302ae969e8d882083cc2c396d3a30437bf..e35e2a65be8923fad90e82cf39461877f6c37b9c 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 4ce97c98f69eb23b88d760c2771412d99781959b..b02ff5f622e13d2b12f3ff92e9e2391f918545a8 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 2e07c91dd56003c2a4e309eb950584df02c2474a..afe9e906fd81533a71072ec193bad214bfb85802 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 d20e6b39aa349add2fcb32137099d3bd371aa052..6b01ac5f3f6d425eb7c904a5e7e61e1550922d56 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 a90326e943a55cfc8c3a35a5c7bd0d68b7c94816..010c4faddd6b35542105562b8afc962b55bcc034 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 a06f66e71ea03c06a8943e5726d8211c4d31ec0a..581a0e0532bc45f5348db802f4718b6aced93c44 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 bec8384dce1ccda2d133b6ff454c0a077d47771b..cf8a81c68cca4f7408f60cf4f9294827f2e5c152 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 91e52ac50a8306c4aa852f1200e2a95b16808bef..23d5cb1e3c157ed24673ed7287921e42207bae14 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 2fa5fee4005bacc3097cbab681f03752273f9c83..6b5013287b9e45f8a8bdc9ea6e5990a68876a029 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 826b73f8a143120bcd96b94650fb22557be72e91..62b131744f30adb1500fd7b4eba013b8b2c8bfc0 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 28df0b54ea5622a3838dbd46d6d2075af07dafaa..30b36c3f9f73296e7542877199aa1cbf1ac79094 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 a577b6dc10de42b35d56ce73d4a39f698a4e45f6..90bc241306fe2be609e32800a4362547eaed911c 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 cf0aa138a96791af64e0013e6f50501c530645bc..76dfc8fbfcb61e39d65becb46a740df2184e4795 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 e079dabced8f6f5a5cb4eddd669746d60471f6b2..1efe55da4062babf326dfcddc78b84b0137b7d61 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 309439632611c3269beed952e8c455c50e2b5d60..71bfdd3087448214f69689f86cff78e7a44c8e4d 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 23674168471ef4c31ab36c10a828a632c0619071..aca30ee3099204f26419006da9e75ce7ef7613ab 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 59c433b372d15cfa35929b44cc825ffb86ef384a..dda5dd6ea523678f026856a7683b6ef16338d17d 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 20dca4df4e03c088a4bc980c25d323b994753594..ae6834c08231fe7a254331be510bf4939273c26e 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 e3f54e8042905ba480eb11f26e3b99c65df70c60..555d4f5657a364e9105fb9bfaf587d300e39811d 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 1ff11c6388e0d53590e38ac5f0234d7d1af75387..c8a654ff7a7d98da12515a2e3fa04f03fb3dc9bf 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 1220e31b894588786bc8f4887a8b4e8074b4044b..a430471f3a7a953a327d50675d992422ffe84623 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 a6a446dd4f89998749726eda0748501471c0ea85..7ae7c4328123d3bd67cb0c5d57c9fdec328b05f1 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 6e1fe3b117c9f1e5a93387e855756bb455b01727..5b5adc04910af64e03de2a12765896f0b2660d2f 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 735b5bcdbb5699e332917e15954d9f5e955df731..5fc6a471507d0d4fd608dabcc071461eccf80ad8 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 dd173945bab44736e1fabff6a5b2b4daa5d874b1..33e6e41a84fcb28ecdf21f8d447ba58227208ca9 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 5657db1c82219b3165ba2f397116e40739cae630..dd06b7e3d7a27fd28b49e56635358b99da48d276 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 9759268b93214402e9f4a4e8051131b2950dc15a..0b96076206dbdb69368519a94cd4121032151abf 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 41057aa38c453fa82d6d29bef6a6326366e80990..5afbf348c6e065d14c7ab1546669c610c2d6356b 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 4533d10ab9bad24cc21834de6182cdcafa2c0452..e4d9df7a22c1b4825229b9d8ab1bb3640c68052f 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 1e3270711e6452de113441deafa92562f7d61051..acae7a999a9451cec8f3b0702a761134dc5d81bc 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 3cb134f777dab9dafdf16cb8a7a64d6bcf9a35b2..a7db70024e2eb9f44184f2c9c594472afbc41533 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 298a488dc221b3177f5630d92780070e39ba1dc0..915b2b95668c629be3a720fa21d8688673bb8c6c 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 e0539417300982ff54ea55ca7d47bcdb7108fe41..c7cee57f8bea6c473a9052335f807db4b49bbe74 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 20828badd3846185ffe28377e2e5cad954d9875f..f050cb1711bb6dabb826c576be17b607eaa1194c 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 2de681b067664684202bb8ac7524a2e1fcda4d05..396b69bcd0de7f6b3088ce693595965eeff78a03 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 d367721cb261a628c933a15088dd80c272940763..359484da09aaefcf17897da7fd4811d2838bbf8e 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 914e42bd15d04664d594794bd59e28dade509e15..6e005d67c86be3476f719f8cb859e1a3b98414aa 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 ed90b4d38263ba2495549e56d1fb4fc3e0cb54a2..94ed6752cc087302b0961e2213ccf82c83042907 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 c865b7a0c523ff3b03d5994b112bab92137bec17..b9fea2553f1d158d9875ac2cc58caa3da49af38c 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 30054ac7513f05c9625eedd80c8c34139abf3efd..b36a32666a5095af44f164ecd9cf7e668685dd9c 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 34c1d2daab42b4c4e7b28f9f7ed4cf520b16f08a..08450797fad9f0e04f94ac996c42128d9ac0aafc 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 e0e992835f81165e18068aed90d21f31d007ffdb..47343613300e870f94755647067b217a3b33d98d 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 a9ac76009975ffb64483dba8122d5b2b77ce43ff..e9eafc05dead09bcbdb607586d968724e256fa1c 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 8c7010cccb435b9bf824505037e2d8cd8110f5cb..06528b75706d27119b7d02bd2721b39cc5501012 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 8495068339fee3b4b318d5a61d44155399989dac..b7e7220c7b8c109ab8f49e74d1b0e067e561c0fd 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 056b9827efef12301ad6130d6c6b5ec2eb08b72e..736d04dac1454de6a77a0e657a2dfed2bf34c81f 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 e1a1a0489340525b1508b579ea72b31f940ccbc9..28109ce9cd7bc9d12c795f62c7a8ec9cb7359ee8 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 12c9de888ab6faff4a63d08547183b1b20bb4a4e..3f2cbd86b5a365d668be08a75fd7d574a70ac5f1 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 f35afc3a6aa9b185b0d179ed5cfc2bf8b995421f..78f8a2f8bfa730b91810e6d4cdb5b233d1eb7df7 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 9f34812199f346d65e9d152eed0060ef43e4b55f..737d0e330f8cfba898b92b7fc407e21999b4524a 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 9e581fd636c59e8d2d06cc23d117fd894fd59853..23c83afd9fa7af739dff4ef34e140c11778abcfd 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 badfd97ad8a31915f26aaebd9ba5b8276bf0ebfd..3d9618f797949091fae9b6dc83716deb3d471ebc 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 edc07bc1dbe6fcf848d3f81e1d4eb7956c8da23a..2861d33b3c39f7f603cf8e9b9b62fe2c437bcf57 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 310f4dce42f009839976ff09d65fb90c836bde52..cc1141dbbca1e8f7faa7dab8ec4516602db04c0c 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 5d39470f53d09ef57c7edb5ea80d52a340c685e5..cb05500bee95b1f3841d0e9cc1e757d2f7dfb16d 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 8d95624edcadcf82b33128cb3c7f613319ff0d87..52afa0420f5d6dd8a7ca92e80491589c3e56c32a 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 98160039a1c82f2d66fa14fe2ef0f656864c0c56..29eb572892b404f7e81599a79e47e9563b50de06 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 6eda11b2e2fa02cbdad9a1dbb46380db5990a097..7bc5cef8139637f84b5c13a732f8894b977c7770 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 f8411c036bdbb4ec2bd9f18867c0177b56e86948..4ca627d133ec6489e6ecfca233e23b350272f8e6 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 b8e26869f010e14bb86bdd82471280007ef7f860..a3035231df909033314aefff98d5541ac5b3d8cb 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 354a10c2612c0f5dd15a4da58edf36a406fb25eb..4b6db8bb4810d04d81ec757113d319154e4a16a7 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 d4545717742f2cb68881fe4fbbcbb29651401f23..39991ce305b3548e2235064b61beab501671fc82 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; diff --git a/lib/std/target.zig b/lib/std/target.zig index 1b9f0084c83a1e3c792a5e75290b395c8365212d..c94b7a4386746efabbc15db54028e491566c84a1 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 3323ee239b71296cf2fb2d48d7ed35333caa65b6..ae3757b5138e2c925bd9f3c7beaa8f48563e7fa0 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 570050762d43f659f012299ddffeb04560cd1065..d8b243d0fae5172d4421fc58cf654098348f060f 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 a0430049cfae48854f2b4d3c8319c87dc6142bcc..23065307533fcf29b8c8d61bfd29e6f7cc03bf5e 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; diff --git a/lib/std/time/epoch.zig b/lib/std/time/epoch.zig index 75bddc71c390bb1f1f1c8dcb9b17ae79daac80ec..126c4fceb7386266e28102644dd65ed53e84bcbf 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 eddc2cb7ec273b70791a8e59ea11ef5f27b78bdf..b93b5e361f9a21cbdef2e91841002562d74bb541 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 e49da8ceaf89c1ec9b71498c8513641c8d00826b..2117564961cbe0d9ff44e637b624f54089f631ef 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 d149e56f493e3b2fb89a958a80d833347d09efba..b8ca05a4c7276023fe7cab5a13ee1300abb0f527 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 d29e1903fb3444b3ca91c078d3aa682d1312ba9d..6c7dadf1e196d2870f9a03a10196cf0125eedb46 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 41657c8a664be01d14e7acf00c98237136241d98..489abac2f65de7364d93f18f4792bd35d7cf0bbc 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 aebbb3b163ef32858cd970ba62d3ba08bbbc995a..b7923fd0151faa6dee7a38250e16ebfe50967a91 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 3ac8b10f4a04a4baa7c6cca9559ba9afd6f7ee62..be0ab25e7a67bd0630a4f25e9205d280c22b0825 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 409a8ebadfc595bcb52a2daae0a2d8bd0218e794..a3f5dfecf6ee310a69345eec9020acadf0f0c63f 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 25efbae67310989284f480dc4ca1ec3248f5085a..5e02b68e9c922f755b260e8602ab98b983e398da 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 d94692693257a4947994acb44020c8d854647ee1..cca9bc0ffa665ec80c2b24d152ee878400b929ab 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 9da74d5b0ea26306a5d3e42f39de0d4c2f196c2a..33fc4971d752d7584bca2fa94a07e18b025a75b5 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 59e4b177f71817406ef851a293b3e4d83df17542..895d4c80017a1e813ff2a809057dd826a8435f6e 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; diff --git a/lib/std/x/os/socket_windows.zig b/lib/std/x/os/socket_windows.zig index c08931fedf01c3d270137cdcec3be512da0fdf19..bcc722fcfe9cb8d4fbb13ad13a879645ed434ec9 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 303c930b93829577311e29aac95be87f55d03034..85ad4d2c81f355d365b9a7316e60bbb30ed2955a 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 61969d96993f2ad88b3c855adf22c0912c89978b..ee2b0982a9feab44d0ddcb27a601846dd8c160ec 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; diff --git a/lib/std/zig/c_builtins.zig b/lib/std/zig/c_builtins.zig index 479f7a3b0e4b624673b31ca6c54cf0939a096df7..6d7dc52bb89935911ef3fc420c451ad36d6756e2 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 7b21fba93ab2d9c0ee3997a09ca49910f0a7e183..bb8a699f69abe0162b3ef5eb2ca5bc661f85cf0d 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 4a8879db57a3288d4387b41d6d86e696c90e3b5b..5243d0eb9db5941545fac42ce45633a5c47432a0 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 24c34a95363103fe13900c113e8da9693556e488..922b1e9858c094d47703b3b81270c7a195df5001 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; diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index f67b0c61791299f47a6908938a6ea531b4d9e258..fed63ba21f1ac01269606230c088f8f4d1074583 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 49a19a067cb1356b46094edd5a9f6f5aaef79171..00292507994bf07028f0c99158e4db69ef612a25 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 df91da8a0304aff4a30e330ce4c8e7b2fad3d87c..20ec7d3bfa688e4273e559f4c3e7f80d3f536961 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; diff --git a/lib/std/zig/string_literal.zig b/lib/std/zig/string_literal.zig index b1dc53c47f4127a395a31104d8ed997e439053a3..64242038d3be5accfebf1dc361bf5a50f95ca813 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 c5c62911ccf85a8cc62802a0034b06049c397427..a2a92b39df97e380001d76d021068b5a93afd128 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 1e8d9e4b48ea29f9bba7b073f23da615dba9cdb4..30496e7d26dfd699726fab6a113ed06307e58722 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 c8f48800c548a374d919bf5c4644f1d3620791a6..509faaef290ba288a500544458ddeabf3dbcf732 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 d32b28f60719549f5b94d5145cf615c6afc89002..595dac627882d247191a6f5d8cb9a3aa751b9a0d 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 1d9a22d5d20a8a4a2d7c4facb6a6276414080abe..06a11c81ae15918b84c21ed02f7d341735e5ffb4 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 3008aecdc35852d6c3cfca64c46e184a7610239e..1db2967c52f8f90b7f3904b1b582db0670f42cfc 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; diff --git a/tools/update-license-headers.zig b/tools/update-license-headers.zig new file mode 100644 index 0000000000000000000000000000000000000000..4cc60ca4ea8f95d2c3b1d9a3e778836873852f81 --- /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); + } +} -- 2.54.0 From f1f28af1880a79bb2d7210d3a704c78698f0b45b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 24 Aug 2021 13:42:31 -0700 Subject: [PATCH 45/54] fix stage2 test cases expecting wrong line numbers Previous commit shifted everything down in the start.zig file, and unfortunately our stage2 test harness depends on absolute line numbers for a couple tests. --- test/cases.zig | 2 +- test/stage2/darwin.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cases.zig b/test/cases.zig index e8479b792ef96ee73fa05d1a53eaa0b0bbfab9d4..4dc4499e609e3b4d1a88d117284103f6428d1c98 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/stage2/darwin.zig b/test/stage2/darwin.zig index 3f05d6c19817a2f6198e9bc6372534bc796fdf03..87b04d1dff0c6ba289045e10cd33b005dde8d02c 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 -- 2.54.0 From 9c95f38a7c1defc7f63a4815bfc2d76a5f9f83f6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 24 Aug 2021 18:56:16 -0700 Subject: [PATCH 46/54] stage1: remove incorrect compile error for var redeclaration Locals are not allowed to shadow declarations, but declarations are allowed to shadow each other, as long as there are no ambiguous references. closes #678 --- src/stage1/analyze.cpp | 43 ++++------------------------------------ src/stage1/astgen.cpp | 43 +++++++++++++++++++++++----------------- test/behavior/error.zig | 12 +++++------ test/behavior/misc.zig | 17 ++++++++++++++++ test/behavior/struct.zig | 4 ++-- test/compile_errors.zig | 31 ++++++++++++----------------- 6 files changed, 67 insertions(+), 83 deletions(-) diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index cf61bf79b76a4dc5f7ac4214726066eb55c4a55c..402c86d86f2352112f63a31654a61093267a431f 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -4171,46 +4171,11 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf } 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")); - } + 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 { - 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; - } - } - } } } diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp index e7c4eacb3f707efab96aaa49a70d72a4abd8cb57..86c18abc1ec5cebbb503b50769bd4a28e34852a5 100644 --- a/src/stage1/astgen.cpp +++ b/src/stage1/astgen.cpp @@ -3200,23 +3200,6 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, 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; - } } } } @@ -3875,7 +3858,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) { diff --git a/test/behavior/error.zig b/test/behavior/error.zig index b1ef55af9ebf9e30e73ac2e65e48eb7cf5bbc1a0..74bf105799709c3658126406e3a5224876970cd3 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/misc.zig b/test/behavior/misc.zig index 466be00bd398dedde92e99c9597d519808830a7f..fe53ca23046a74f32128ae91f0b249d5354ced92 100644 --- a/test/behavior/misc.zig +++ b/test/behavior/misc.zig @@ -505,3 +505,20 @@ 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); +} diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 4f7e0c2d7104fe11ac70f71662eb690d3ee6768a..d9e1c02aa17c40c7cbab5b9bbe0503a52235ee61 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/compile_errors.zig b/test/compile_errors.zig index 14d2a98e02880246dd076463f2bcb67dabf6cf67..ce5c80fa2cfda470b449a6fda4f0b89950d9710e 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", -- 2.54.0 From 04cafd81377b9c57006a28407b0d97bc1164345e Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Wed, 25 Aug 2021 20:37:40 +0200 Subject: [PATCH 47/54] stage2 ARM: Add qadd, qsub, qdadd, qdsub instructions These are integer saturating arithmetic instructions --- src/codegen/arm.zig | 119 +++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 34 deletions(-) diff --git a/src/codegen/arm.zig b/src/codegen/arm.zig index d30479e1f1a55544499de4802d91ae2c875043bc..3743afd50f85e14c7efc3bae5f45689047513582 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, @@ -1294,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| { -- 2.54.0 From 311797f68619f3de66cbdecabc2af7d2022e8874 Mon Sep 17 00:00:00 2001 From: Lee Cannon Date: Fri, 27 Aug 2021 00:53:23 +0100 Subject: [PATCH 48/54] Rework build system `build_options` API (#9623) * rework `build_options` to integrate with the FileSource abstraction * support mapping as an arbitrarily named package * support mapping to multiple different artifacts * use hash of contents for options filename --- build.zig | 53 ++++--- lib/std/build.zig | 211 ++-------------------------- lib/std/build/OptionsStep.zig | 257 ++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+), 224 deletions(-) create mode 100644 lib/std/build/OptionsStep.zig diff --git a/build.zig b/build.zig index d727e1cac2c8278f73e1b8c9baa75815266268f5..e2665557b8f87f96330de2ac41306c0dc1907e19 100644 --- a/build.zig +++ b/build.zig @@ -109,9 +109,13 @@ pub fn build(b: *Builder) !void { b.default_step.dependOn(&exe.step); exe.single_threaded = single_threaded; - 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); + 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); + if (enable_llvm) { const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option); @@ -218,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, @@ -248,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); diff --git a/lib/std/build.zig b/lib/std/build.zig index 1533f93085965a3cc472cd7afd5bd53f51469d77..afbe580f6da7a5da7cb0d079dd363835fe8d53ba 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -23,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, @@ -247,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)); } @@ -1375,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; @@ -1434,9 +1429,6 @@ pub const LibExeObjStep = struct { 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, @@ -1603,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, @@ -2038,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; } @@ -2176,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| { @@ -2393,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})); @@ -3141,6 +2986,7 @@ pub const Step = struct { run, check_file, install_raw, + options, custom, }; @@ -3312,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/OptionsStep.zig b/lib/std/build/OptionsStep.zig new file mode 100644 index 0000000000000000000000000000000000000000..2440fce16de366459f957976802fc798bed130b2 --- /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); +} -- 2.54.0 From 3a3704be05adcf929353e836222399885d1d99fb Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Wed, 25 Aug 2021 02:55:35 +0200 Subject: [PATCH 49/54] Don't use .none_or_ref for for(expr) We can already know whether the user want the expression to be a pointer or ref based on whether the asterisk token is used, like with if and switch. --- src/AstGen.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 2b2bbd4f2275d18453dbb5967d653e1ff05b9958..ae1c6be0da0e692b5ae45e5b901841271d602b26 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -5418,12 +5418,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: { -- 2.54.0 From 3aa533519da073695a56a56159b7ea3c487fb1b2 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Wed, 25 Aug 2021 02:58:19 +0200 Subject: [PATCH 50/54] Store to mutable pointer in analyzeRef This function previously attempted to store a value to an immutable pointer, after which storePtr would yield an error. --- src/Sema.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index a11bdec66dfc9cc1bfec7dedce44110fd752ba8c..90505c68066550c3e624852f4c6dfff82bcb18d5 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -8818,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( -- 2.54.0 From cfae70ec8e736af3fcd465c78bd80e160968eea8 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Wed, 25 Aug 2021 03:44:43 +0200 Subject: [PATCH 51/54] Make slice always return a reference Previously this returned an rvalue, which leads to unexpected behaviour when writing expressions such as `x[1..][1..].` --- src/AstGen.zig | 24 +++++++++++++++++++++--- src/Zir.zig | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index ae1c6be0da0e692b5ae45e5b901841271d602b26..0b0de11ea986d53afc50a71fbd457acc059f35ee 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -698,7 +698,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 +716,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 +736,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 => { diff --git a/src/Zir.zig b/src/Zir.zig index 2110122580365be8a2bba7f596e8de1681cae5b0..2092a7b5e4c1cb5eec8e7c15365dd77debab731e 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`. -- 2.54.0 From f30aa25cbf9c9a415963b4ea69d7efa09237a704 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 27 Aug 2021 21:34:13 -0700 Subject: [PATCH 52/54] declarations may collide with primitives with @"" syntax * stage2 AstGen: add missing compile error for declaring a local that shadows a primitive. Even with `@""` syntax, it may not have the same name as a primitive. * stage2 AstGen: add a compile error for a global declaration whose name matches a primitive. However it is allowed when using `@""` syntax. * stage1: delete all "declaration shadows primitive" compile errors because they are now handled by stage2 AstGen. * stage1/stage2 AstGen: notice when using `@""` syntax and: - treat `_` as a regular identifier - skip checking if an identifire is a primitive Check the new test cases for clarifications on semantics. closes #6062 --- src/AstGen.zig | 100 ++++++++++++++++++++++++++------------- src/stage1/all_types.hpp | 1 + src/stage1/analyze.cpp | 13 ----- src/stage1/astgen.cpp | 60 +++++++++++------------ src/stage1/parser.cpp | 19 ++++++-- src/stage1/parser.hpp | 1 + test/behavior/misc.zig | 12 +++++ test/compile_errors.zig | 35 ++++++++++++-- 8 files changed, 156 insertions(+), 85 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 0b0de11ea986d53afc50a71fbd457acc059f35ee..2b8e6a76a8c827827eb21a39f727d7c99595553d 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2891,7 +2891,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. @@ -3160,7 +3160,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, @@ -6319,34 +6319,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); + } } } @@ -10031,8 +10033,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) { @@ -10060,7 +10075,20 @@ 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, @@ -10068,13 +10096,19 @@ fn detectLocalShadowing( name_token: ast.TokenIndex, ) !void { const gpa = astgen.gpa; + const name_slice = mem.spanZ(astgen.nullTerminatedString(ident_name)); + if (isPrimitive(name_slice)) { + const name = try gpa.dupe(u8, name_slice); + defer gpa.free(name); + return astgen.failTok(name_token, "local shadows primitive '{s}'", .{name}); + } 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 = 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, @@ -10091,7 +10125,7 @@ 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 = 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, @@ -10111,7 +10145,7 @@ fn detectLocalShadowing( s = ns.parent; continue; }; - const name = try gpa.dupe(u8, mem.spanZ(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/stage1/all_types.hpp b/src/stage1/all_types.hpp index dfebc66cfdfec63f6903828469472d89d7ca2ab0..fc3b00d6dbdfe80200dd403d2c0dfc1ceb29fc7e 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 402c86d86f2352112f63a31654a61093267a431f..2eb609ef1a5526bdd76ccec88f0aca835cbb601a 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,13 +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); - - 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; - } } Scope *child_scope; diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp index 86c18abc1ec5cebbb503b50769bd4a28e34852a5..367fd8ac08b29b1e5e0df17f0a81addc8ebe18f0 100644 --- a/src/stage1/astgen.cpp +++ b/src/stage1/astgen.cpp @@ -3194,13 +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 { @@ -3815,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); + } } } diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp index 9a429364b10518c76ae938d01056ac7d1864cf9b..b06a9441721e58932de06fba7ae1e007903dfbd9 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 9f73444cb84ec1f85fc3b2177f9d3797265f6f1e..8ac8ce6de1beb2f6c0ab58a6248a623682c6ebeb 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/test/behavior/misc.zig b/test/behavior/misc.zig index fe53ca23046a74f32128ae91f0b249d5354ced92..60528eaeb86e95c001c598606b971ded0aa814a0 100644 --- a/test/behavior/misc.zig +++ b/test/behavior/misc.zig @@ -522,3 +522,15 @@ fn A() type { 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); +} diff --git a/test/compile_errors.zig b/test/compile_errors.zig index ce5c80fa2cfda470b449a6fda4f0b89950d9710e..89cb292663cf892f4b26c6d5812d9dd19248564d 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -7258,14 +7258,41 @@ 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; + ctx.objErrStage1("locally shadowing a primitive type", + \\export fn foo() void { + \\ const u8 = u16; + \\ const a: u8 = 300; + \\ _ = a; + \\} + \\export fn bar() void { + \\ const @"u8" = u16; + \\ const a: @"u8" = 300; + \\ _ = a; + \\} + , &[_][]const u8{ + "tmp.zig:2:11: error: local shadows primitive 'u8'", + "tmp.zig:7:11: error: local shadows primitive 'u8'", + }); + + 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: u16 = 300; + \\ const a: u8 = 300; \\ _ = a; \\} , &[_][]const u8{ - "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", + "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", -- 2.54.0 From 6a6e2cd64f3ebb1919dd0ac53d8a1f29c56e6ec2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 28 Aug 2021 10:17:47 -0700 Subject: [PATCH 53/54] AstGen: allow locals with same name as primitives with `@""` syntax This makes local names follow the same rule as declaration names. --- src/AstGen.zig | 57 +++++++++++++++++++++++++---------------- test/behavior/misc.zig | 4 +++ test/compile_errors.zig | 9 ++----- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 2b8e6a76a8c827827eb21a39f727d7c99595553d..a425540a386aae66814e99807f9a00a90f993b71 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2385,7 +2385,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", .{}); @@ -2952,12 +2952,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) { @@ -5035,7 +5036,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, @@ -5054,11 +5055,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, @@ -5100,7 +5102,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, @@ -5291,11 +5293,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, @@ -5316,9 +5319,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, @@ -5374,9 +5378,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, @@ -5523,7 +5528,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, @@ -5543,11 +5548,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, @@ -10059,7 +10065,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, @@ -10094,13 +10100,17 @@ fn detectLocalShadowing( scope: *Scope, ident_name: u32, name_token: ast.TokenIndex, + token_bytes: []const u8, ) !void { const gpa = astgen.gpa; - const name_slice = mem.spanZ(astgen.nullTerminatedString(ident_name)); - if (isPrimitive(name_slice)) { - const name = try gpa.dupe(u8, name_slice); - defer gpa.free(name); - return astgen.failTok(name_token, "local shadows primitive '{s}'", .{name}); + 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; @@ -10108,6 +10118,7 @@ fn detectLocalShadowing( .local_val => { const local_val = s.cast(Scope.LocalVal).?; if (local_val.name == 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}'", .{ @@ -10125,6 +10136,7 @@ fn detectLocalShadowing( .local_ptr => { const local_ptr = s.cast(Scope.LocalPtr).?; if (local_ptr.name == 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}'", .{ @@ -10145,6 +10157,7 @@ fn detectLocalShadowing( s = ns.parent; continue; }; + 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}'", .{ diff --git a/test/behavior/misc.zig b/test/behavior/misc.zig index 60528eaeb86e95c001c598606b971ded0aa814a0..8e63ad81dda6b25cf13240ee0fe85387c6c212b6 100644 --- a/test/behavior/misc.zig +++ b/test/behavior/misc.zig @@ -533,4 +533,8 @@ test "use of declaration with same name as primitive" { const b: S.alias = 300; try expect(b == 300); + + const @"u8" = u16; + const c: @"u8" = 300; + try expect(c == 300); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 89cb292663cf892f4b26c6d5812d9dd19248564d..6e910b1b3e12fc0aa52cd18a883c4077970f5c88 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -7264,14 +7264,9 @@ pub fn addCases(ctx: *TestContext) !void { \\ const a: u8 = 300; \\ _ = a; \\} - \\export fn bar() void { - \\ const @"u8" = u16; - \\ const a: @"u8" = 300; - \\ _ = a; - \\} , &[_][]const u8{ - "tmp.zig:2:11: error: local shadows primitive 'u8'", - "tmp.zig:7:11: error: local shadows primitive 'u8'", + "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", -- 2.54.0 From 05cf44933d753f7a5a53ab289ea60fd43761de57 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 28 Aug 2021 10:54:14 -0700 Subject: [PATCH 54/54] stage2: delete keywords `true`, `false`, `undefined`, `null` The grammar does not need these as keywords; they are merely primitives provided by the language the same as `void`, `u32`, etc. --- doc/docgen.zig | 29 ++++++++++++++--------------- doc/langref.html.in | 16 ++++------------ lib/std/zig/ast.zig | 16 ---------------- lib/std/zig/parse.zig | 36 ------------------------------------ lib/std/zig/render.zig | 4 ---- lib/std/zig/tokenizer.zig | 12 ------------ src/AstGen.zig | 20 -------------------- src/translate_c/ast.zig | 20 ++++++++++---------- 8 files changed, 28 insertions(+), 125 deletions(-) diff --git a/doc/docgen.zig b/doc/docgen.zig index f2d2e2845b8ed359454697cc897dc5b4e4603e3e..8d920dcf6a56350065b675950dcb92eb00f0d062 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 336db082f160de8669b52754be31368dfc267cf8..62e3da72778580671e31f3e12401187350e787ef 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -11564,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 @@ -11937,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 @@ -11945,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 @@ -11959,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 @@ -11974,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/std/zig/ast.zig b/lib/std/zig/ast.zig index ee2b0982a9feab44d0ddcb27a601846dd8c160ec..535dc994839e40772340ac97c023d68837554e43 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -346,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, @@ -711,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, @@ -2757,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/parse.zig b/lib/std/zig/parse.zig index 922b1e9858c094d47703b3b81270c7a195df5001..5904e1816f1463d0772c7dce8f0ee6cfe2515eeb 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -2226,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 @@ -2273,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/render.zig b/lib/std/zig/render.zig index 20ec7d3bfa688e4273e559f4c3e7f80d3f536961..71b071d6fb50594267107b6ff9d52cc5a1311508 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -187,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/tokenizer.zig b/lib/std/zig/tokenizer.zig index 1db2967c52f8f90b7f3904b1b582db0670f42cfc..3fdbb3ec7b038b16c4d38a55ea0091899fa6cead 100644 --- a/lib/std/zig/tokenizer.zig +++ b/lib/std/zig/tokenizer.zig @@ -32,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 }, @@ -40,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 }, @@ -54,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 }, @@ -157,7 +153,6 @@ pub const Token = struct { keyword_error, keyword_export, keyword_extern, - keyword_false, keyword_fn, keyword_for, keyword_if, @@ -165,7 +160,6 @@ pub const Token = struct { keyword_noalias, keyword_noinline, keyword_nosuspend, - keyword_null, keyword_opaque, keyword_or, keyword_orelse, @@ -179,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, @@ -280,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", @@ -288,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", @@ -302,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/AstGen.zig b/src/AstGen.zig index a425540a386aae66814e99807f9a00a90f993b71..0a34e9a0cafd3d25ae7bd6921f0281c6bfd452f3 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, @@ -759,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); @@ -7852,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, @@ -8092,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, @@ -8265,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, diff --git a/src/translate_c/ast.zig b/src/translate_c/ast.zig index e1da1c7d05127a33b63111aa1e328b2d4d77ea52..105893619107a691b57afdf9676af28934311255 100644 --- a/src/translate_c/ast.zig +++ b/src/translate_c/ast.zig @@ -928,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(.{ @@ -1599,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, ")"); -- 2.54.0