| author | |
| committer | |
| log | 654e0b6679f3436bacbf685223d6ab68f707a62f |
| tree | 3d643918bf5ab0e1a0754eeca210ee63cdd452e4 |
| parent | 34835bbbcfe81cc87e823d14dc9b25e698ad5edc |
12 files changed, 25 insertions(+), 24 deletions(-)
doc/langref.html.in+2-2| ... | @@ -8043,7 +8043,7 @@ fn func(y: *i32) void { | ... | @@ -8043,7 +8043,7 @@ fn func(y: *i32) void { |
| 8043 | {#header_open|@mulAdd#} | 8043 | {#header_open|@mulAdd#} |
| 8044 | <pre>{#syntax#}@mulAdd(comptime T: type, a: T, b: T, c: T) T{#endsyntax#}</pre> | 8044 | <pre>{#syntax#}@mulAdd(comptime T: type, a: T, b: T, c: T) T{#endsyntax#}</pre> |
| 8045 | <p> | 8045 | <p> |
| 8046 | Fused multiply add, similar to {#syntax#}(a * b) + c{#endsyntax#}, except | 8046 | Fused multiply-add, similar to {#syntax#}(a * b) + c{#endsyntax#}, except |
| 8047 | only rounds once, and is thus more accurate. | 8047 | only rounds once, and is thus more accurate. |
| 8048 | </p> | 8048 | </p> |
| 8049 | <p> | 8049 | <p> |
| ... | @@ -9178,7 +9178,7 @@ pub const FloatMode = enum { | ... | @@ -9178,7 +9178,7 @@ pub const FloatMode = enum { |
| 9178 | <li>Assume the arguments and result are not +/-Inf. Optimizations are required to retain defined behavior over +/-Inf, but the value of the result is undefined.</li> | 9178 | <li>Assume the arguments and result are not +/-Inf. Optimizations are required to retain defined behavior over +/-Inf, but the value of the result is undefined.</li> |
| 9179 | <li>Treat the sign of a zero argument or result as insignificant.</li> | 9179 | <li>Treat the sign of a zero argument or result as insignificant.</li> |
| 9180 | <li>Use the reciprocal of an argument rather than perform division.</li> | 9180 | <li>Use the reciprocal of an argument rather than perform division.</li> |
| 9181 | <li>Perform floating-point contraction (e.g. fusing a multiply followed by an addition into a fused multiply-and-add).</li> | 9181 | <li>Perform floating-point contraction (e.g. fusing a multiply followed by an addition into a fused multiply-add).</li> |
| 9182 | <li>Perform algebraically equivalent transformations that may change results in floating point (e.g. reassociate).</li> | 9182 | <li>Perform algebraically equivalent transformations that may change results in floating point (e.g. reassociate).</li> |
| 9183 | </ul> | 9183 | </ul> |
| 9184 | This is equivalent to <code>-ffast-math</code> in GCC. | 9184 | This is equivalent to <code>-ffast-math</code> in GCC. |
lib/std/math.zig+4-3| ... | @@ -762,14 +762,14 @@ fn testOverflow() !void { | ... | @@ -762,14 +762,14 @@ fn testOverflow() !void { |
| 762 | try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); | 762 | try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | /// Returns the absolute value of x, where x is a value of an integer | 765 | /// Returns the absolute value of x, where x is a value of a signed integer type. |
| 766 | /// type. | 766 | /// See also: `absCast` |
| 767 | pub fn absInt(x: anytype) !@TypeOf(x) { | 767 | pub fn absInt(x: anytype) !@TypeOf(x) { |
| 768 | const T = @TypeOf(x); | 768 | const T = @TypeOf(x); |
| 769 | comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt | 769 | comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt |
| 770 | comptime assert(@typeInfo(T).Int.signedness == .signed); // must pass a signed integer to absInt | 770 | comptime assert(@typeInfo(T).Int.signedness == .signed); // must pass a signed integer to absInt |
| 771 | 771 | ||
| 772 | if (x == minInt(@TypeOf(x))) { | 772 | if (x == minInt(T)) { |
| 773 | return error.Overflow; | 773 | return error.Overflow; |
| 774 | } else { | 774 | } else { |
| 775 | @setRuntimeSafety(false); | 775 | @setRuntimeSafety(false); |
| ... | @@ -977,6 +977,7 @@ pub inline fn fabs(value: anytype) @TypeOf(value) { | ... | @@ -977,6 +977,7 @@ pub inline fn fabs(value: anytype) @TypeOf(value) { |
| 977 | 977 | ||
| 978 | /// Returns the absolute value of the integer parameter. | 978 | /// Returns the absolute value of the integer parameter. |
| 979 | /// Result is an unsigned integer. | 979 | /// Result is an unsigned integer. |
| 980 | /// See also: `absInt` | ||
| 980 | pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { | 981 | pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { |
| 981 | .ComptimeInt => comptime_int, | 982 | .ComptimeInt => comptime_int, |
| 982 | .Int => |int_info| std.meta.Int(.unsigned, int_info.bits), | 983 | .Int => |int_info| std.meta.Int(.unsigned, int_info.bits), |
lib/std/testing.zig+4-4| ... | @@ -213,8 +213,8 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt | ... | @@ -213,8 +213,8 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt |
| 213 | /// This function is intended to be used only in tests. When the actual value is | 213 | /// This function is intended to be used only in tests. When the actual value is |
| 214 | /// not approximately equal to the expected value, prints diagnostics to stderr | 214 | /// not approximately equal to the expected value, prints diagnostics to stderr |
| 215 | /// to show exactly how they are not equal, then returns a test failure error. | 215 | /// to show exactly how they are not equal, then returns a test failure error. |
| 216 | /// See `math.approxEqAbs` for more informations on the tolerance parameter. | 216 | /// See `math.approxEqAbs` for more information on the tolerance parameter. |
| 217 | /// The types must be floating point. | 217 | /// The types must be floating-point. |
| 218 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { | 218 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { |
| 219 | const T = @TypeOf(expected); | 219 | const T = @TypeOf(expected); |
| 220 | 220 | ||
| ... | @@ -245,8 +245,8 @@ test "expectApproxEqAbs" { | ... | @@ -245,8 +245,8 @@ test "expectApproxEqAbs" { |
| 245 | /// This function is intended to be used only in tests. When the actual value is | 245 | /// This function is intended to be used only in tests. When the actual value is |
| 246 | /// not approximately equal to the expected value, prints diagnostics to stderr | 246 | /// not approximately equal to the expected value, prints diagnostics to stderr |
| 247 | /// to show exactly how they are not equal, then returns a test failure error. | 247 | /// to show exactly how they are not equal, then returns a test failure error. |
| 248 | /// See `math.approxEqRel` for more informations on the tolerance parameter. | 248 | /// See `math.approxEqRel` for more information on the tolerance parameter. |
| 249 | /// The types must be floating point. | 249 | /// The types must be floating-point. |
| 250 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { | 250 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { |
| 251 | const T = @TypeOf(expected); | 251 | const T = @TypeOf(expected); |
| 252 | 252 |
src/Sema.zig+6-6| ... | @@ -5039,7 +5039,7 @@ fn analyzeBlockBody( | ... | @@ -5039,7 +5039,7 @@ fn analyzeBlockBody( |
| 5039 | const valid_rt = try sema.validateRunTimeType(child_block, type_src, resolved_ty, false); | 5039 | const valid_rt = try sema.validateRunTimeType(child_block, type_src, resolved_ty, false); |
| 5040 | if (!valid_rt) { | 5040 | if (!valid_rt) { |
| 5041 | const msg = msg: { | 5041 | const msg = msg: { |
| 5042 | const msg = try sema.errMsg(child_block, type_src, "value with comptime only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); | 5042 | const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); |
| 5043 | errdefer msg.destroy(sema.gpa); | 5043 | errdefer msg.destroy(sema.gpa); |
| 5044 | 5044 | ||
| 5045 | const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?; | 5045 | const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?; |
| ... | @@ -5801,12 +5801,12 @@ fn addComptimeReturnTypeNote( | ... | @@ -5801,12 +5801,12 @@ fn addComptimeReturnTypeNote( |
| 5801 | break :blk func_src.toSrcLoc(src_decl); | 5801 | break :blk func_src.toSrcLoc(src_decl); |
| 5802 | }; | 5802 | }; |
| 5803 | if (return_ty.tag() == .generic_poison) { | 5803 | if (return_ty.tag() == .generic_poison) { |
| 5804 | return sema.mod.errNoteNonLazy(src_loc, parent, "generic function is instantiated with a comptime only return type", .{}); | 5804 | return sema.mod.errNoteNonLazy(src_loc, parent, "generic function is instantiated with a comptime-only return type", .{}); |
| 5805 | } | 5805 | } |
| 5806 | try sema.mod.errNoteNonLazy( | 5806 | try sema.mod.errNoteNonLazy( |
| 5807 | src_loc, | 5807 | src_loc, |
| 5808 | parent, | 5808 | parent, |
| 5809 | "function is being called at comptime because it returns a comptime only type '{}'", | 5809 | "function is being called at comptime because it returns a comptime-only type '{}'", |
| 5810 | .{return_ty.fmt(sema.mod)}, | 5810 | .{return_ty.fmt(sema.mod)}, |
| 5811 | ); | 5811 | ); |
| 5812 | try sema.explainWhyTypeIsComptime(block, func_src, parent, src_loc, return_ty); | 5812 | try sema.explainWhyTypeIsComptime(block, func_src, parent, src_loc, return_ty); |
| ... | @@ -6343,7 +6343,7 @@ fn analyzeInlineCallArg( | ... | @@ -6343,7 +6343,7 @@ fn analyzeInlineCallArg( |
| 6343 | new_fn_info.param_types[arg_i.*] = param_ty; | 6343 | new_fn_info.param_types[arg_i.*] = param_ty; |
| 6344 | const uncasted_arg = uncasted_args[arg_i.*]; | 6344 | const uncasted_arg = uncasted_args[arg_i.*]; |
| 6345 | if (try sema.typeRequiresComptime(param_ty)) { | 6345 | if (try sema.typeRequiresComptime(param_ty)) { |
| 6346 | _ = sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to parameter with comptime only type must be comptime known") catch |err| { | 6346 | _ = sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to parameter with comptime-only type must be comptime known") catch |err| { |
| 6347 | if (err == error.AnalysisFail and sema.err != null) { | 6347 | if (err == error.AnalysisFail and sema.err != null) { |
| 6348 | try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty); | 6348 | try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty); |
| 6349 | } | 6349 | } |
| ... | @@ -8026,7 +8026,7 @@ fn funcCommon( | ... | @@ -8026,7 +8026,7 @@ fn funcCommon( |
| 8026 | return sema.failWithOwnedErrorMsg(msg); | 8026 | return sema.failWithOwnedErrorMsg(msg); |
| 8027 | } | 8027 | } |
| 8028 | 8028 | ||
| 8029 | // If the return type is comptime only but not dependent on parameters then all parameter types also need to be comptime | 8029 | // If the return type is comptime-only but not dependent on parameters then all parameter types also need to be comptime |
| 8030 | if (!sema.is_generic_instantiation and has_body and ret_ty_requires_comptime) comptime_check: { | 8030 | if (!sema.is_generic_instantiation and has_body and ret_ty_requires_comptime) comptime_check: { |
| 8031 | for (block.params.items) |param| { | 8031 | for (block.params.items) |param| { |
| 8032 | if (!param.is_comptime) break; | 8032 | if (!param.is_comptime) break; |
| ... | @@ -8035,7 +8035,7 @@ fn funcCommon( | ... | @@ -8035,7 +8035,7 @@ fn funcCommon( |
| 8035 | const msg = try sema.errMsg( | 8035 | const msg = try sema.errMsg( |
| 8036 | block, | 8036 | block, |
| 8037 | ret_ty_src, | 8037 | ret_ty_src, |
| 8038 | "function with comptime only return type '{}' requires all parameters to be comptime", | 8038 | "function with comptime-only return type '{}' requires all parameters to be comptime", |
| 8039 | .{return_type.fmt(sema.mod)}, | 8039 | .{return_type.fmt(sema.mod)}, |
| 8040 | ); | 8040 | ); |
| 8041 | try sema.explainWhyTypeIsComptime(block, ret_ty_src, msg, ret_ty_src.toSrcLoc(sema.owner_decl), return_type); | 8041 | try sema.explainWhyTypeIsComptime(block, ret_ty_src, msg, ret_ty_src.toSrcLoc(sema.owner_decl), return_type); |
src/type.zig+1-1| ... | @@ -2318,7 +2318,7 @@ pub const Type = extern union { | ... | @@ -2318,7 +2318,7 @@ pub const Type = extern union { |
| 2318 | /// * the type has only one possible value, making its ABI size 0. | 2318 | /// * the type has only one possible value, making its ABI size 0. |
| 2319 | /// - an enum with an explicit tag type has the ABI size of the integer tag type, | 2319 | /// - an enum with an explicit tag type has the ABI size of the integer tag type, |
| 2320 | /// making it one-possible-value only if the integer tag type has 0 bits. | 2320 | /// making it one-possible-value only if the integer tag type has 0 bits. |
| 2321 | /// When `ignore_comptime_only` is true, then types that are comptime only | 2321 | /// When `ignore_comptime_only` is true, then types that are comptime-only |
| 2322 | /// may return false positives. | 2322 | /// may return false positives. |
| 2323 | pub fn hasRuntimeBitsAdvanced( | 2323 | pub fn hasRuntimeBitsAdvanced( |
| 2324 | ty: Type, | 2324 | ty: Type, |
test/behavior/array.zig+1-1| ... | @@ -564,7 +564,7 @@ test "type coercion of pointer to anon struct literal to pointer to array" { | ... | @@ -564,7 +564,7 @@ test "type coercion of pointer to anon struct literal to pointer to array" { |
| 564 | comptime try S.doTheTest(); | 564 | comptime try S.doTheTest(); |
| 565 | } | 565 | } |
| 566 | 566 | ||
| 567 | test "array with comptime only element type" { | 567 | test "array with comptime-only element type" { |
| 568 | const a = [_]type{ u32, i32 }; | 568 | const a = [_]type{ u32, i32 }; |
| 569 | try testing.expect(a[0] == u32); | 569 | try testing.expect(a[0] == u32); |
| 570 | try testing.expect(a[1] == i32); | 570 | try testing.expect(a[1] == i32); |
test/cases/compile_errors/error_in_typeof_param.zig+1-1| ... | @@ -11,4 +11,4 @@ pub export fn entry() void { | ... | @@ -11,4 +11,4 @@ pub export fn entry() void { |
| 11 | // target=native | 11 | // target=native |
| 12 | // | 12 | // |
| 13 | // :6:31: error: unable to resolve comptime value | 13 | // :6:31: error: unable to resolve comptime value |
| 14 | // :6:31: note: argument to parameter with comptime only type must be comptime known | 14 | // :6:31: note: argument to parameter with comptime-only type must be comptime known |
test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig+1-1| ... | @@ -18,6 +18,6 @@ pub export fn entry() void { | ... | @@ -18,6 +18,6 @@ pub export fn entry() void { |
| 18 | // | 18 | // |
| 19 | // :12:13: error: unable to resolve comptime value | 19 | // :12:13: error: unable to resolve comptime value |
| 20 | // :12:13: note: argument to function being called at comptime must be comptime known | 20 | // :12:13: note: argument to function being called at comptime must be comptime known |
| 21 | // :7:25: note: function is being called at comptime because it returns a comptime only type 'tmp.S' | 21 | // :7:25: note: function is being called at comptime because it returns a comptime-only type 'tmp.S' |
| 22 | // :2:12: note: struct requires comptime because of this field | 22 | // :2:12: note: struct requires comptime because of this field |
| 23 | // :2:12: note: use '*const fn() void' for a function pointer type | 23 | // :2:12: note: use '*const fn() void' for a function pointer type |
test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig+1-1| ... | @@ -19,4 +19,4 @@ pub export fn entry() void { | ... | @@ -19,4 +19,4 @@ pub export fn entry() void { |
| 19 | // | 19 | // |
| 20 | // :14:13: error: unable to resolve comptime value | 20 | // :14:13: error: unable to resolve comptime value |
| 21 | // :14:13: note: argument to function being called at comptime must be comptime known | 21 | // :14:13: note: argument to function being called at comptime must be comptime known |
| 22 | // :9:38: note: generic function is instantiated with a comptime only return type | 22 | // :9:38: note: generic function is instantiated with a comptime-only return type |
test/cases/compile_errors/non-const_switch_number_literal.zig+1-1| ... | @@ -14,5 +14,5 @@ fn bar() i32 { | ... | @@ -14,5 +14,5 @@ fn bar() i32 { |
| 14 | // backend=stage2 | 14 | // backend=stage2 |
| 15 | // target=native | 15 | // target=native |
| 16 | // | 16 | // |
| 17 | // :2:15: error: value with comptime only type 'comptime_int' depends on runtime control flow | 17 | // :2:15: error: value with comptime-only type 'comptime_int' depends on runtime control flow |
| 18 | // :2:26: note: runtime control flow here | 18 | // :2:26: note: runtime control flow here |
test/cases/compile_errors/non_comptime_param_in_comptime_function.zig+2-2| ... | @@ -26,10 +26,10 @@ export fn entry2() void { | ... | @@ -26,10 +26,10 @@ export fn entry2() void { |
| 26 | // backend=stage2 | 26 | // backend=stage2 |
| 27 | // target=native | 27 | // target=native |
| 28 | // | 28 | // |
| 29 | // :1:20: error: function with comptime only return type 'type' requires all parameters to be comptime | 29 | // :1:20: error: function with comptime-only return type 'type' requires all parameters to be comptime |
| 30 | // :1:20: note: types are not available at runtime | 30 | // :1:20: note: types are not available at runtime |
| 31 | // :1:6: note: param 'val' is required to be comptime | 31 | // :1:6: note: param 'val' is required to be comptime |
| 32 | // :11:16: error: function with comptime only return type 'tmp.S' requires all parameters to be comptime | 32 | // :11:16: error: function with comptime-only return type 'tmp.S' requires all parameters to be comptime |
| 33 | // :9:10: note: struct requires comptime because of this field | 33 | // :9:10: note: struct requires comptime because of this field |
| 34 | // :9:10: note: use '*const fn() void' for a function pointer type | 34 | // :9:10: note: use '*const fn() void' for a function pointer type |
| 35 | // :11:8: note: param is required to be comptime | 35 | // :11:8: note: param is required to be comptime |
test/compile_errors.zig+1-1| ... | @@ -204,7 +204,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -204,7 +204,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 204 | , &[_][]const u8{ | 204 | , &[_][]const u8{ |
| 205 | ":3:12: error: unable to resolve comptime value", | 205 | ":3:12: error: unable to resolve comptime value", |
| 206 | ":3:12: note: argument to function being called at comptime must be comptime known", | 206 | ":3:12: note: argument to function being called at comptime must be comptime known", |
| 207 | ":2:55: note: generic function is instantiated with a comptime only return type", | 207 | ":2:55: note: generic function is instantiated with a comptime-only return type", |
| 208 | }); | 208 | }); |
| 209 | } | 209 | } |
| 210 | 210 |