| author | |
| committer | |
| log | 77fdd76c16196441dce0f38ccea2eae01436c4be |
| tree | 3300be415c21a5b5903d2cf6e5893abb2a19f5b9 |
| parent | 1e207f1edd500707032be093a5c8a91f0e16609a |
ccf670c made using `return` from within a comptime block in a non-inline
function illegal, since it is a use of runtime control flow in a
comptime block. It is allowed if the function in question is `inline`,
since no actual control flow occurs in this case. A few functions from
std (notably `std.fmt.comptimePrint`) needed to be marked `inline` to
support this change.4 files changed, 10 insertions(+), 13 deletions(-)
lib/std/enums.zig+1-1| ... | @@ -32,7 +32,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def | ... | @@ -32,7 +32,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def |
| 32 | /// Looks up the supplied fields in the given enum type. | 32 | /// Looks up the supplied fields in the given enum type. |
| 33 | /// Uses only the field names, field values are ignored. | 33 | /// Uses only the field names, field values are ignored. |
| 34 | /// The result array is in the same order as the input. | 34 | /// The result array is in the same order as the input. |
| 35 | pub fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E { | 35 | pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E { |
| 36 | comptime { | 36 | comptime { |
| 37 | var result: [fields.len]E = undefined; | 37 | var result: [fields.len]E = undefined; |
| 38 | for (fields, 0..) |f, i| { | 38 | for (fields, 0..) |f, i| { |
lib/std/fmt.zig+3-3| ... | @@ -2005,7 +2005,7 @@ pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, optio | ... | @@ -2005,7 +2005,7 @@ pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, optio |
| 2005 | return buf[0..formatIntBuf(buf, value, base, case, options)]; | 2005 | return buf[0..formatIntBuf(buf, value, base, case, options)]; |
| 2006 | } | 2006 | } |
| 2007 | 2007 | ||
| 2008 | pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 { | 2008 | pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 { |
| 2009 | comptime { | 2009 | comptime { |
| 2010 | var buf: [count(fmt, args):0]u8 = undefined; | 2010 | var buf: [count(fmt, args):0]u8 = undefined; |
| 2011 | _ = bufPrint(&buf, fmt, args) catch unreachable; | 2011 | _ = bufPrint(&buf, fmt, args) catch unreachable; |
| ... | @@ -2016,8 +2016,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, | ... | @@ -2016,8 +2016,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, |
| 2016 | 2016 | ||
| 2017 | test "comptimePrint" { | 2017 | test "comptimePrint" { |
| 2018 | @setEvalBranchQuota(2000); | 2018 | @setEvalBranchQuota(2000); |
| 2019 | try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100}))); | 2019 | try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptimePrint("{}", .{100}))); |
| 2020 | try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); | 2020 | try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100})); |
| 2021 | } | 2021 | } |
| 2022 | 2022 | ||
| 2023 | test "parse u64 digit too big" { | 2023 | test "parse u64 digit too big" { |
lib/std/mem.zig+1-2| ... | @@ -3492,8 +3492,7 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { | ... | @@ -3492,8 +3492,7 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { |
| 3492 | if (comptime !trait.is(.Pointer)(B) or | 3492 | if (comptime !trait.is(.Pointer)(B) or |
| 3493 | (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8)) | 3493 | (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8)) |
| 3494 | { | 3494 | { |
| 3495 | comptime var buf: [100]u8 = undefined; | 3495 | @compileError(std.fmt.comptimePrint("expected *[{}]u8, passed " ++ @typeName(B), .{size})); |
| 3496 | @compileError(std.fmt.bufPrint(&buf, "expected *[{}]u8, passed " ++ @typeName(B), .{size}) catch unreachable); | ||
| 3497 | } | 3496 | } |
| 3498 | 3497 | ||
| 3499 | return CopyPtrAttrs(B, .One, T); | 3498 | return CopyPtrAttrs(B, .One, T); |
lib/std/os/windows/user32.zig+5-7| ... | @@ -28,13 +28,11 @@ const POINT = windows.POINT; | ... | @@ -28,13 +28,11 @@ const POINT = windows.POINT; |
| 28 | const HCURSOR = windows.HCURSOR; | 28 | const HCURSOR = windows.HCURSOR; |
| 29 | const HBRUSH = windows.HBRUSH; | 29 | const HBRUSH = windows.HBRUSH; |
| 30 | 30 | ||
| 31 | fn selectSymbol(comptime function_static: anytype, function_dynamic: *const @TypeOf(function_static), comptime os: std.Target.Os.WindowsVersion) *const @TypeOf(function_static) { | 31 | inline fn selectSymbol(comptime function_static: anytype, function_dynamic: *const @TypeOf(function_static), comptime os: std.Target.Os.WindowsVersion) *const @TypeOf(function_static) { |
| 32 | comptime { | 32 | const sym_ok = comptime builtin.os.isAtLeast(.windows, os); |
| 33 | const sym_ok = builtin.os.isAtLeast(.windows, os); | 33 | if (sym_ok == true) return function_static; |
| 34 | if (sym_ok == true) return function_static; | 34 | if (sym_ok == null) return function_dynamic; |
| 35 | if (sym_ok == null) return function_dynamic; | 35 | if (sym_ok == false) @compileError("Target OS range does not support function, at least " ++ @tagName(os) ++ " is required"); |
| 36 | if (sym_ok == false) @compileError("Target OS range does not support function, at least " ++ @tagName(os) ++ " is required"); | ||
| 37 | } | ||
| 38 | } | 36 | } |
| 39 | 37 | ||
| 40 | // === Messages === | 38 | // === Messages === |