diff options
| author | Loris Cro <kappaloris@gmail.com> | 2023-06-18 09:06:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-18 09:06:40 +0200 |
| commit | 216ef10dc471e4db60a30208be178d6c59efeaaf (patch) | |
| tree | 8c239dab283ae9cb3b7fe099bae240bcc53f894e /lib/std/builtin.zig | |
| parent | 0fc1d396495c1ab482197021dedac8bea3f9401c (diff) | |
| parent | 729a051e9e38674233190aea23c0ac8c134f2d67 (diff) | |
| download | zig-216ef10dc471e4db60a30208be178d6c59efeaaf.tar.gz zig-216ef10dc471e4db60a30208be178d6c59efeaaf.zip | |
Merge branch 'master' into autodoc-searchkey
Diffstat (limited to 'lib/std/builtin.zig')
| -rw-r--r-- | lib/std/builtin.zig | 152 |
1 files changed, 10 insertions, 142 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 3523c5ac12..54781e4465 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -51,7 +51,7 @@ pub const StackTrace = struct { const debug_info = std.debug.getSelfDebugInfo() catch |err| { return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}); }; - const tty_config = std.debug.detectTTYConfig(std.io.getStdErr()); + const tty_config = std.io.tty.detectConfig(std.io.getStdErr()); try writer.writeAll("\n"); std.debug.writeStackTrace(self, writer, arena.allocator(), debug_info, tty_config) catch |err| { try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)}); @@ -143,7 +143,7 @@ pub const Mode = OptimizeMode; /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -pub const CallingConvention = enum { +pub const CallingConvention = enum(u8) { /// This is the default Zig calling convention used when not using `export` on `fn` /// and no other calling convention is specified. Unspecified, @@ -190,7 +190,7 @@ pub const CallingConvention = enum { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -pub const AddressSpace = enum { +pub const AddressSpace = enum(u5) { generic, gs, fs, @@ -221,7 +221,6 @@ pub const SourceLocation = struct { }; pub const TypeId = std.meta.Tag(Type); -pub const TypeInfo = @compileError("deprecated; use Type"); /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. @@ -283,7 +282,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. - pub const Size = enum { + pub const Size = enum(u2) { One, Many, Slice, @@ -388,8 +387,6 @@ pub const Type = union(enum) { decls: []const Declaration, }; - pub const FnArg = @compileError("deprecated; use Fn.Param"); - /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const Fn = struct { @@ -488,139 +485,6 @@ pub const WasiExecModel = enum { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -pub const Version = struct { - major: u32, - minor: u32, - patch: u32 = 0, - - pub const Range = struct { - min: Version, - max: Version, - - pub fn includesVersion(self: Range, ver: Version) bool { - if (self.min.order(ver) == .gt) return false; - if (self.max.order(ver) == .lt) return false; - return true; - } - - /// Checks if system is guaranteed to be at least `version` or older than `version`. - /// Returns `null` if a runtime check is required. - pub fn isAtLeast(self: Range, ver: Version) ?bool { - if (self.min.order(ver) != .lt) return true; - if (self.max.order(ver) == .lt) return false; - return null; - } - }; - - pub fn order(lhs: Version, rhs: Version) std.math.Order { - if (lhs.major < rhs.major) return .lt; - if (lhs.major > rhs.major) return .gt; - if (lhs.minor < rhs.minor) return .lt; - if (lhs.minor > rhs.minor) return .gt; - if (lhs.patch < rhs.patch) return .lt; - if (lhs.patch > rhs.patch) return .gt; - return .eq; - } - - pub fn parse(text: []const u8) !Version { - var end: usize = 0; - while (end < text.len) : (end += 1) { - const c = text[end]; - if (!std.ascii.isDigit(c) and c != '.') break; - } - // found no digits or '.' before unexpected character - if (end == 0) return error.InvalidVersion; - - var it = std.mem.split(u8, text[0..end], "."); - // substring is not empty, first call will succeed - const major = it.first(); - if (major.len == 0) return error.InvalidVersion; - const minor = it.next() orelse "0"; - // ignore 'patch' if 'minor' is invalid - const patch = if (minor.len == 0) "0" else (it.next() orelse "0"); - - return Version{ - .major = try std.fmt.parseUnsigned(u32, major, 10), - .minor = try std.fmt.parseUnsigned(u32, if (minor.len == 0) "0" else minor, 10), - .patch = try std.fmt.parseUnsigned(u32, if (patch.len == 0) "0" else patch, 10), - }; - } - - pub fn format( - self: Version, - comptime fmt: []const u8, - options: std.fmt.FormatOptions, - out_stream: anytype, - ) !void { - _ = options; - if (fmt.len == 0) { - if (self.patch == 0) { - if (self.minor == 0) { - return std.fmt.format(out_stream, "{d}", .{self.major}); - } else { - return std.fmt.format(out_stream, "{d}.{d}", .{ self.major, self.minor }); - } - } else { - return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch }); - } - } else { - std.fmt.invalidFmtError(fmt, self); - } - } -}; - -test "Version.parse" { - @setEvalBranchQuota(3000); - try testVersionParse(); - comptime (try testVersionParse()); -} - -fn testVersionParse() !void { - const f = struct { - fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void { - const v = try Version.parse(text); - try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3); - } - - fn err(text: []const u8, expected_err: anyerror) !void { - _ = Version.parse(text) catch |actual_err| { - if (actual_err == expected_err) return; - return actual_err; - }; - return error.Unreachable; - } - }; - - try f.eql("2.6.32.11-svn21605", 2, 6, 32); // Debian PPC - try f.eql("2.11.2(0.329/5/3)", 2, 11, 2); // MinGW - try f.eql("5.4.0-1018-raspi", 5, 4, 0); // Ubuntu - try f.eql("5.7.12_3", 5, 7, 12); // Void - try f.eql("2.13-DEVELOPMENT", 2, 13, 0); // DragonFly - try f.eql("2.3-35", 2, 3, 0); - try f.eql("1a.4", 1, 0, 0); - try f.eql("3.b1.0", 3, 0, 0); - try f.eql("1.4beta", 1, 4, 0); - try f.eql("2.7.pre", 2, 7, 0); - try f.eql("0..3", 0, 0, 0); - try f.eql("8.008.", 8, 8, 0); - try f.eql("01...", 1, 0, 0); - try f.eql("55", 55, 0, 0); - try f.eql("4294967295.0.1", 4294967295, 0, 1); - try f.eql("429496729_6", 429496729, 0, 0); - - try f.err("foobar", error.InvalidVersion); - try f.err("", error.InvalidVersion); - try f.err("-1", error.InvalidVersion); - try f.err("+4", error.InvalidVersion); - try f.err(".", error.InvalidVersion); - try f.err("....3", error.InvalidVersion); - try f.err("4294967296", error.Overflow); - try f.err("5000877755", error.Overflow); - // error.InvalidCharacter is not possible anymore -} - -/// This data structure is used by the Zig language code generation and -/// therefore must be kept in sync with the compiler implementation. pub const CallModifier = enum { /// Equivalent to function call syntax. auto, @@ -646,7 +510,7 @@ pub const CallModifier = enum { /// If this is not possible, a compile error is emitted instead. always_tail, - /// Guarantees that the call will inlined at the callsite. + /// Guarantees that the call will be inlined at the callsite. /// If this is not possible, a compile error is emitted instead. always_inline, @@ -749,7 +613,7 @@ pub const PrefetchOptions = struct { /// 3 means high temporal locality. That is, the data should be kept in /// the cache as it is likely to be accessed again soon. locality: u2 = 3, - /// The cache that the prefetch should be preformed on. + /// The cache that the prefetch should be performed on. cache: Cache = .data, pub const Rw = enum(u1) { @@ -836,6 +700,9 @@ pub const CompilerBackend = enum(u64) { /// The reference implementation self-hosted compiler of Zig, using the /// sparc64 backend. stage2_sparc64 = 10, + /// The reference implementation self-hosted compiler of Zig, using the + /// spirv backend. + stage2_spirv64 = 11, _, }; @@ -1003,6 +870,7 @@ pub const panic_messages = struct { pub const for_len_mismatch = "for loop over objects with non-equal lengths"; pub const memcpy_len_mismatch = "@memcpy arguments have non-equal lengths"; pub const memcpy_alias = "@memcpy arguments alias"; + pub const noreturn_returned = "'noreturn' function returned"; }; pub noinline fn returnError(st: *StackTrace) void { |
