diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-12-13 18:15:18 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-13 18:15:18 -0500 |
| commit | 6378644d4ea561a79edf44056609681e6d1438d1 (patch) | |
| tree | 84094f36ee3dd9e3befaf33a5a7da82fc5388da7 | |
| parent | 65270cdc3345e9840427179168a09ef6e4dd34b9 (diff) | |
| parent | 51ed5416ab2969a366c8c6bdc487f357bad267c3 (diff) | |
| download | zig-6378644d4ea561a79edf44056609681e6d1438d1.tar.gz zig-6378644d4ea561a79edf44056609681e6d1438d1.zip | |
Merge pull request #13907 from Vexu/call-merge
Remove `stack` option from `@call`
38 files changed, 248 insertions, 320 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in index 4ff1504627..2e235aa80f 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -4270,7 +4270,7 @@ test "using @typeInfo with runtime values" { } // Calls to `isFieldOptional` on `Struct1` get unrolled to an equivalent -// of this function: +// of this function: fn isFieldOptionalUnrolled(field_index: usize) !bool { return switch (field_index) { 0 => false, @@ -7801,7 +7801,7 @@ comptime { {#header_close#} {#header_open|@call#} - <pre>{#syntax#}@call(options: std.builtin.CallOptions, function: anytype, args: anytype) anytype{#endsyntax#}</pre> + <pre>{#syntax#}@call(modifier: std.builtin.CallModifier, function: anytype, args: anytype) anytype{#endsyntax#}</pre> <p> Calls a function, in the same way that invoking an expression with parentheses does: </p> @@ -7809,7 +7809,7 @@ comptime { const expect = @import("std").testing.expect; test "noinline function call" { - try expect(@call(.{}, add, .{3, 9}) == 12); + try expect(@call(.auto, add, .{3, 9}) == 12); } fn add(a: i32, b: i32) i32 { @@ -7818,48 +7818,41 @@ fn add(a: i32, b: i32) i32 { {#code_end#} <p> {#syntax#}@call{#endsyntax#} allows more flexibility than normal function call syntax does. The - {#syntax#}CallOptions{#endsyntax#} struct is reproduced here: + {#syntax#}CallModifier{#endsyntax#} enum is reproduced here: </p> - {#syntax_block|zig|builtin.CallOptions struct#} -pub const CallOptions = struct { - modifier: Modifier = .auto, - - /// Only valid when `Modifier` is `Modifier.async_kw`. - stack: ?[]align(std.Target.stack_align) u8 = null, - - pub const Modifier = enum { - /// Equivalent to function call syntax. - auto, + {#syntax_block|zig|builtin.CallModifier struct#} +pub const CallModifier = enum { + /// Equivalent to function call syntax. + auto, - /// Equivalent to async keyword used with function call syntax. - async_kw, + /// Equivalent to async keyword used with function call syntax. + async_kw, - /// Prevents tail call optimization. This guarantees that the return - /// address will point to the callsite, as opposed to the callsite's - /// callsite. If the call is otherwise required to be tail-called - /// or inlined, a compile error is emitted instead. - never_tail, + /// Prevents tail call optimization. This guarantees that the return + /// address will point to the callsite, as opposed to the callsite's + /// callsite. If the call is otherwise required to be tail-called + /// or inlined, a compile error is emitted instead. + never_tail, - /// Guarantees that the call will not be inlined. If the call is - /// otherwise required to be inlined, a compile error is emitted instead. - never_inline, + /// Guarantees that the call will not be inlined. If the call is + /// otherwise required to be inlined, a compile error is emitted instead. + never_inline, - /// Asserts that the function call will not suspend. This allows a - /// non-async function to call an async function. - no_async, + /// Asserts that the function call will not suspend. This allows a + /// non-async function to call an async function. + no_async, - /// Guarantees that the call will be generated with tail call optimization. - /// If this is not possible, a compile error is emitted instead. - always_tail, + /// Guarantees that the call will be generated with tail call optimization. + /// If this is not possible, a compile error is emitted instead. + always_tail, - /// Guarantees that the call will inlined at the callsite. - /// If this is not possible, a compile error is emitted instead. - always_inline, + /// Guarantees that the call will inlined at the callsite. + /// If this is not possible, a compile error is emitted instead. + always_inline, - /// Evaluates the call at compile-time. If the call cannot be completed at - /// compile-time, a compile error is emitted instead. - compile_time, - }; + /// Evaluates the call at compile-time. If the call cannot be completed at + /// compile-time, a compile error is emitted instead. + compile_time, }; {#end_syntax_block#} {#header_close#} diff --git a/lib/compiler_rt/stack_probe.zig b/lib/compiler_rt/stack_probe.zig index c24b927809..09d535bd51 100644 --- a/lib/compiler_rt/stack_probe.zig +++ b/lib/compiler_rt/stack_probe.zig @@ -236,27 +236,27 @@ fn win_probe_stack_adjust_sp() void { pub fn _chkstk() callconv(.Naked) void { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}); + @call(.always_inline, win_probe_stack_adjust_sp, .{}); } pub fn __chkstk() callconv(.Naked) void { @setRuntimeSafety(false); if (comptime arch.isAARCH64()) { - @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}); + @call(.always_inline, win_probe_stack_only, .{}); } else switch (arch) { - .x86 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}), - .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}), + .x86 => @call(.always_inline, win_probe_stack_adjust_sp, .{}), + .x86_64 => @call(.always_inline, win_probe_stack_only, .{}), else => unreachable, } } pub fn ___chkstk() callconv(.Naked) void { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}); + @call(.always_inline, win_probe_stack_adjust_sp, .{}); } pub fn __chkstk_ms() callconv(.Naked) void { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}); + @call(.always_inline, win_probe_stack_only, .{}); } pub fn ___chkstk_ms() callconv(.Naked) void { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}); + @call(.always_inline, win_probe_stack_only, .{}); } diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index e2e17a2925..fc4f676a1f 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -387,10 +387,10 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) { switch (@typeInfo(@typeInfo(@TypeOf(f)).Fn.return_type.?)) { .NoReturn => { - @call(.{}, f, args); + @call(.auto, f, args); }, .Void => { - @call(.{}, f, args); + @call(.auto, f, args); return default_value; }, .Int => |info| { @@ -398,7 +398,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) { @compileError(bad_fn_ret); } - const status = @call(.{}, f, args); + const status = @call(.auto, f, args); if (Impl != PosixThreadImpl) { return status; } @@ -411,7 +411,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) { @compileError(bad_fn_ret); } - @call(.{}, f, args) catch |err| { + @call(.auto, f, args) catch |err| { std.debug.print("error: {s}\n", .{@errorName(err)}); if (@errorReturnTrace()) |trace| { std.debug.dumpStackTrace(trace.*); diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 4ee9d4306b..eb1212607d 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -591,45 +591,38 @@ fn testVersionParse() !void { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -pub const CallOptions = struct { - modifier: Modifier = .auto, - - /// Only valid when `Modifier` is `Modifier.async_kw`. - stack: ?[]align(std.Target.stack_align) u8 = null, - - pub const Modifier = enum { - /// Equivalent to function call syntax. - auto, - - /// Equivalent to async keyword used with function call syntax. - async_kw, - - /// Prevents tail call optimization. This guarantees that the return - /// address will point to the callsite, as opposed to the callsite's - /// callsite. If the call is otherwise required to be tail-called - /// or inlined, a compile error is emitted instead. - never_tail, - - /// Guarantees that the call will not be inlined. If the call is - /// otherwise required to be inlined, a compile error is emitted instead. - never_inline, - - /// Asserts that the function call will not suspend. This allows a - /// non-async function to call an async function. - no_async, - - /// Guarantees that the call will be generated with tail call optimization. - /// If this is not possible, a compile error is emitted instead. - always_tail, - - /// Guarantees that the call will inlined at the callsite. - /// If this is not possible, a compile error is emitted instead. - always_inline, - - /// Evaluates the call at compile-time. If the call cannot be completed at - /// compile-time, a compile error is emitted instead. - compile_time, - }; +pub const CallModifier = enum { + /// Equivalent to function call syntax. + auto, + + /// Equivalent to async keyword used with function call syntax. + async_kw, + + /// Prevents tail call optimization. This guarantees that the return + /// address will point to the callsite, as opposed to the callsite's + /// callsite. If the call is otherwise required to be tail-called + /// or inlined, a compile error is emitted instead. + never_tail, + + /// Guarantees that the call will not be inlined. If the call is + /// otherwise required to be inlined, a compile error is emitted instead. + never_inline, + + /// Asserts that the function call will not suspend. This allows a + /// non-async function to call an async function. + no_async, + + /// Guarantees that the call will be generated with tail call optimization. + /// If this is not possible, a compile error is emitted instead. + always_tail, + + /// Guarantees that the call will inlined at the callsite. + /// If this is not possible, a compile error is emitted instead. + always_inline, + + /// Evaluates the call at compile-time. If the call cannot be completed at + /// compile-time, a compile error is emitted instead. + compile_time, }; /// This data structure is used by the Zig language code generation and diff --git a/lib/std/crypto/siphash.zig b/lib/std/crypto/siphash.zig index dff8005b31..e960a3476b 100644 --- a/lib/std/crypto/siphash.zig +++ b/lib/std/crypto/siphash.zig @@ -78,12 +78,10 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round pub fn update(self: *Self, b: []const u8) void { std.debug.assert(b.len % 8 == 0); - const inl = std.builtin.CallOptions{ .modifier = .always_inline }; - var off: usize = 0; while (off < b.len) : (off += 8) { const blob = b[off..][0..8].*; - @call(inl, round, .{ self, blob }); + @call(.always_inline, round, .{ self, blob }); } self.msg_len +%= @truncate(u8, b.len); @@ -105,12 +103,9 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round self.v2 ^= 0xff; } - // TODO this is a workaround, should be able to supply the value without a separate variable - const inl = std.builtin.CallOptions{ .modifier = .always_inline }; - comptime var i: usize = 0; inline while (i < d_rounds) : (i += 1) { - @call(inl, sipRound, .{self}); + @call(.always_inline, sipRound, .{self}); } const b1 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3; @@ -122,7 +117,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round comptime var j: usize = 0; inline while (j < d_rounds) : (j += 1) { - @call(inl, sipRound, .{self}); + @call(.always_inline, sipRound, .{self}); } const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3; @@ -133,11 +128,9 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round const m = mem.readIntLittle(u64, b[0..8]); self.v3 ^= m; - // TODO this is a workaround, should be able to supply the value without a separate variable - const inl = std.builtin.CallOptions{ .modifier = .always_inline }; comptime var i: usize = 0; inline while (i < c_rounds) : (i += 1) { - @call(inl, sipRound, .{self}); + @call(.always_inline, sipRound, .{self}); } self.v0 ^= m; @@ -163,8 +156,8 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round pub fn hash(msg: []const u8, key: *const [key_length]u8) T { const aligned_len = msg.len - (msg.len % 8); var c = Self.init(key); - @call(.{ .modifier = .always_inline }, c.update, .{msg[0..aligned_len]}); - return @call(.{ .modifier = .always_inline }, c.final, .{msg[aligned_len..]}); + @call(.always_inline, c.update, .{msg[0..aligned_len]}); + return @call(.always_inline, c.final, .{msg[aligned_len..]}); } }; } diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 90fb88c5be..2ab798dcd7 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -381,7 +381,7 @@ pub const DlDynlib = struct { pub fn lookup(self: *DlDynlib, comptime T: type, name: [:0]const u8) ?T { // dlsym (and other dl-functions) secretly take shadow parameter - return address on stack // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 - if (@call(.{ .modifier = .never_tail }, system.dlsym, .{ self.handle, name.ptr })) |symbol| { + if (@call(.never_tail, system.dlsym, .{ self.handle, name.ptr })) |symbol| { return @ptrCast(T, symbol); } else { return null; diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 76cbab8698..aac4b0feaf 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -66,7 +66,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { const Key = @TypeOf(key); if (strat == .Shallow and comptime meta.trait.hasUniqueRepresentation(Key)) { - @call(.{ .modifier = .always_inline }, hasher.update, .{mem.asBytes(&key)}); + @call(.always_inline, hasher.update, .{mem.asBytes(&key)}); return; } @@ -89,12 +89,12 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { // TODO Check if the situation is better after #561 is resolved. .Int => { if (comptime meta.trait.hasUniqueRepresentation(Key)) { - @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)}); + @call(.always_inline, hasher.update, .{std.mem.asBytes(&key)}); } else { // Take only the part containing the key value, the remaining // bytes are undefined and must not be hashed! const byte_size = comptime std.math.divCeil(comptime_int, @bitSizeOf(Key), 8) catch unreachable; - @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)[0..byte_size]}); + @call(.always_inline, hasher.update, .{std.mem.asBytes(&key)[0..byte_size]}); } }, @@ -103,7 +103,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { .ErrorSet => hash(hasher, @errorToInt(key), strat), .AnyFrame, .Fn => hash(hasher, @ptrToInt(key), strat), - .Pointer => @call(.{ .modifier = .always_inline }, hashPointer, .{ hasher, key, strat }), + .Pointer => @call(.always_inline, hashPointer, .{ hasher, key, strat }), .Optional => if (key) |k| hash(hasher, k, strat), diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 7c8e42f105..23b3ce02da 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -185,7 +185,7 @@ pub const CityHash64 = struct { } fn hashLen16(u: u64, v: u64) u64 { - return @call(.{ .modifier = .always_inline }, hash128To64, .{ u, v }); + return @call(.always_inline, hash128To64, .{ u, v }); } fn hashLen16Mul(low: u64, high: u64, mul: u64) u64 { @@ -198,7 +198,7 @@ pub const CityHash64 = struct { } fn hash128To64(low: u64, high: u64) u64 { - return @call(.{ .modifier = .always_inline }, hashLen16Mul, .{ low, high, 0x9ddfea08eb382d69 }); + return @call(.always_inline, hashLen16Mul, .{ low, high, 0x9ddfea08eb382d69 }); } fn hashLen0To16(str: []const u8) u64 { @@ -279,7 +279,7 @@ pub const CityHash64 = struct { } fn weakHashLen32WithSeeds(ptr: [*]const u8, a: u64, b: u64) WeakPair { - return @call(.{ .modifier = .always_inline }, weakHashLen32WithSeedsHelper, .{ + return @call(.always_inline, weakHashLen32WithSeedsHelper, .{ fetch64(ptr, 0), fetch64(ptr, 8), fetch64(ptr, 16), @@ -334,7 +334,7 @@ pub const CityHash64 = struct { } pub fn hashWithSeed(str: []const u8, seed: u64) u64 { - return @call(.{ .modifier = .always_inline }, Self.hashWithSeeds, .{ str, k2, seed }); + return @call(.always_inline, Self.hashWithSeeds, .{ str, k2, seed }); } pub fn hashWithSeeds(str: []const u8, seed0: u64, seed1: u64) u64 { diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index 44b411bb2c..2e1ae4b801 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -9,7 +9,7 @@ pub const Murmur2_32 = struct { const Self = @This(); pub fn hash(str: []const u8) u32 { - return @call(.{ .modifier = .always_inline }, Self.hashWithSeed, .{ str, default_seed }); + return @call(.always_inline, Self.hashWithSeed, .{ str, default_seed }); } pub fn hashWithSeed(str: []const u8, seed: u32) u32 { @@ -45,7 +45,7 @@ pub const Murmur2_32 = struct { } pub fn hashUint32(v: u32) u32 { - return @call(.{ .modifier = .always_inline }, Self.hashUint32WithSeed, .{ v, default_seed }); + return @call(.always_inline, Self.hashUint32WithSeed, .{ v, default_seed }); } pub fn hashUint32WithSeed(v: u32, seed: u32) u32 { @@ -65,7 +65,7 @@ pub const Murmur2_32 = struct { } pub fn hashUint64(v: u64) u32 { - return @call(.{ .modifier = .always_inline }, Self.hashUint64WithSeed, .{ v, default_seed }); + return @call(.always_inline, Self.hashUint64WithSeed, .{ v, default_seed }); } pub fn hashUint64WithSeed(v: u64, seed: u32) u32 { @@ -94,7 +94,7 @@ pub const Murmur2_64 = struct { const Self = @This(); pub fn hash(str: []const u8) u64 { - return @call(.{ .modifier = .always_inline }, Self.hashWithSeed, .{ str, default_seed }); + return @call(.always_inline, Self.hashWithSeed, .{ str, default_seed }); } pub fn hashWithSeed(str: []const u8, seed: u64) u64 { @@ -128,7 +128,7 @@ pub const Murmur2_64 = struct { } pub fn hashUint32(v: u32) u64 { - return @call(.{ .modifier = .always_inline }, Self.hashUint32WithSeed, .{ v, default_seed }); + return @call(.always_inline, Self.hashUint32WithSeed, .{ v, default_seed }); } pub fn hashUint32WithSeed(v: u32, seed: u64) u64 { @@ -145,7 +145,7 @@ pub const Murmur2_64 = struct { } pub fn hashUint64(v: u64) u64 { - return @call(.{ .modifier = .always_inline }, Self.hashUint64WithSeed, .{ v, default_seed }); + return @call(.always_inline, Self.hashUint64WithSeed, .{ v, default_seed }); } pub fn hashUint64WithSeed(v: u64, seed: u64) u64 { @@ -173,7 +173,7 @@ pub const Murmur3_32 = struct { } pub fn hash(str: []const u8) u32 { - return @call(.{ .modifier = .always_inline }, Self.hashWithSeed, .{ str, default_seed }); + return @call(.always_inline, Self.hashWithSeed, .{ str, default_seed }); } pub fn hashWithSeed(str: []const u8, seed: u32) u32 { @@ -221,7 +221,7 @@ pub const Murmur3_32 = struct { } pub fn hashUint32(v: u32) u32 { - return @call(.{ .modifier = .always_inline }, Self.hashUint32WithSeed, .{ v, default_seed }); + return @call(.always_inline, Self.hashUint32WithSeed, .{ v, default_seed }); } pub fn hashUint32WithSeed(v: u32, seed: u32) u32 { @@ -247,7 +247,7 @@ pub const Murmur3_32 = struct { } pub fn hashUint64(v: u64) u32 { - return @call(.{ .modifier = .always_inline }, Self.hashUint64WithSeed, .{ v, default_seed }); + return @call(.always_inline, Self.hashUint64WithSeed, .{ v, default_seed }); } pub fn hashUint64WithSeed(v: u64, seed: u32) u32 { diff --git a/lib/std/hash/wyhash.zig b/lib/std/hash/wyhash.zig index 05340592a9..9dda198a06 100644 --- a/lib/std/hash/wyhash.zig +++ b/lib/std/hash/wyhash.zig @@ -65,7 +65,7 @@ const WyhashStateless = struct { var off: usize = 0; while (off < b.len) : (off += 32) { - @call(.{ .modifier = .always_inline }, self.round, .{b[off .. off + 32]}); + @call(.always_inline, self.round, .{b[off .. off + 32]}); } self.msg_len += b.len; @@ -121,8 +121,8 @@ const WyhashStateless = struct { const aligned_len = input.len - (input.len % 32); var c = WyhashStateless.init(seed); - @call(.{ .modifier = .always_inline }, c.update, .{input[0..aligned_len]}); - return @call(.{ .modifier = .always_inline }, c.final, .{input[aligned_len..]}); + @call(.always_inline, c.update, .{input[0..aligned_len]}); + return @call(.always_inline, c.final, .{input[aligned_len..]}); } }; diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 534e8a570d..25b2ebc0a8 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -3587,7 +3587,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void { const dst_i = src_i + limb_shift; const src_digit = a[src_i]; - r[dst_i] = carry | @call(.{ .modifier = .always_inline }, math.shr, .{ + r[dst_i] = carry | @call(.always_inline, math.shr, .{ Limb, src_digit, limb_bits - @intCast(Limb, interior_limb_shift), @@ -3615,7 +3615,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void { const src_digit = a[src_i]; r[dst_i] = carry | (src_digit >> interior_limb_shift); - carry = @call(.{ .modifier = .always_inline }, math.shl, .{ + carry = @call(.always_inline, math.shl, .{ Limb, src_digit, limb_bits - @intCast(Limb, interior_limb_shift), diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index a001af709c..7f227ffec4 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -263,7 +263,7 @@ pub fn fork() usize { /// the compiler is not aware of how vfork affects control flow and you may /// see different results in optimized builds. pub inline fn vfork() usize { - return @call(.{ .modifier = .always_inline }, syscall0, .{.vfork}); + return @call(.always_inline, syscall0, .{.vfork}); } pub fn futimens(fd: i32, times: *const [2]timespec) usize { diff --git a/lib/std/start.zig b/lib/std/start.zig index 8a0febf1a1..b8c74a6373 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -229,15 +229,15 @@ fn _DllMainCRTStartup( fn wasm_freestanding_start() callconv(.C) void { // This is marked inline because for some reason LLVM in // release mode fails to inline it, and we want fewer call frames in stack traces. - _ = @call(.{ .modifier = .always_inline }, callMain, .{}); + _ = @call(.always_inline, callMain, .{}); } fn wasi_start() callconv(.C) void { // The function call is marked inline because for some reason LLVM in // release mode fails to inline it, and we want fewer call frames in stack traces. switch (builtin.wasi_exec_model) { - .reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}), - .command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})), + .reactor => _ = @call(.always_inline, callMain, .{}), + .command => std.os.wasi.proc_exit(@call(.always_inline, callMain, .{})), } } @@ -373,7 +373,7 @@ fn _start() callconv(.Naked) noreturn { } // If LLVM inlines stack variables into _start, they will overwrite // the command line argument data. - @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{}); + @call(.never_inline, posixCallMainAndExit, .{}); } fn WinStartup() callconv(std.os.windows.WINAPI) noreturn { @@ -459,7 +459,7 @@ fn posixCallMainAndExit() callconv(.C) noreturn { expandStackSize(phdrs); } - std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp })); + std.os.exit(@call(.always_inline, callMainWithArgs, .{ argc, argv, envp })); } fn expandStackSize(phdrs: []elf.Phdr) void { @@ -510,12 +510,12 @@ fn main(c_argc: c_int, c_argv: [*c][*c]u8, c_envp: [*c][*c]u8) callconv(.C) c_in expandStackSize(phdrs); } - return @call(.{ .modifier = .always_inline }, callMainWithArgs, .{ @intCast(usize, c_argc), @ptrCast([*][*:0]u8, c_argv), envp }); + return @call(.always_inline, callMainWithArgs, .{ @intCast(usize, c_argc), @ptrCast([*][*:0]u8, c_argv), envp }); } fn mainWithoutEnv(c_argc: c_int, c_argv: [*c][*c]u8) callconv(.C) c_int { std.os.argv = @ptrCast([*][*:0]u8, c_argv)[0..@intCast(usize, c_argc)]; - return @call(.{ .modifier = .always_inline }, callMain, .{}); + return @call(.always_inline, callMain, .{}); } // General error message for a malformed return type @@ -545,7 +545,7 @@ inline fn initEventLoopAndCallMain() u8 { // This is marked inline because for some reason LLVM in release mode fails to inline it, // and we want fewer call frames in stack traces. - return @call(.{ .modifier = .always_inline }, callMain, .{}); + return @call(.always_inline, callMain, .{}); } // This is marked inline because for some reason LLVM in release mode fails to inline it, @@ -574,7 +574,7 @@ inline fn initEventLoopAndCallWinMain() std.os.windows.INT { // This is marked inline because for some reason LLVM in release mode fails to inline it, // and we want fewer call frames in stack traces. - return @call(.{ .modifier = .always_inline }, call_wWinMain, .{}); + return @call(.always_inline, call_wWinMain, .{}); } fn callMainAsync(loop: *std.event.Loop) callconv(.Async) u8 { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 6a75999f71..af0074a549 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -828,7 +828,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime var failing_allocator_inst = std.testing.FailingAllocator.init(backing_allocator, std.math.maxInt(usize)); args.@"0" = failing_allocator_inst.allocator(); - try @call(.{}, test_fn, args); + try @call(.auto, test_fn, args); break :x failing_allocator_inst.index; }; @@ -837,7 +837,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime var failing_allocator_inst = std.testing.FailingAllocator.init(backing_allocator, fail_index); args.@"0" = failing_allocator_inst.allocator(); - if (@call(.{}, test_fn, args)) |_| { + if (@call(.auto, test_fn, args)) |_| { if (failing_allocator_inst.has_induced_failure) { return error.SwallowedOutOfMemoryError; } else { diff --git a/lib/std/unicode/throughput_test.zig b/lib/std/unicode/throughput_test.zig index 5c2dfda768..66014ad48d 100644 --- a/lib/std/unicode/throughput_test.zig +++ b/lib/std/unicode/throughput_test.zig @@ -25,7 +25,7 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount { var r: usize = undefined; while (i < N) : (i += 1) { r = try @call( - .{ .modifier = .never_inline }, + .never_inline, std.unicode.utf8CountCodepoints, .{buf}, ); diff --git a/src/AstGen.zig b/src/AstGen.zig index 021990883a..8df3d56a88 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -8297,11 +8297,11 @@ fn builtinCall( return rvalue(gz, ri, result, node); }, .call => { - const options = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .call_options_type } }, params[0]); + const modifier = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .modifier_type } }, params[0]); const callee = try calleeExpr(gz, scope, params[1]); const args = try expr(gz, scope, .{ .rl = .none }, params[2]); const result = try gz.addPlNode(.builtin_call, node, Zir.Inst.BuiltinCall{ - .options = options, + .modifier = modifier, .callee = callee, .args = args, .flags = .{ @@ -8674,7 +8674,7 @@ fn callExpr( const astgen = gz.astgen; const callee = try calleeExpr(gz, scope, call.ast.fn_expr); - const modifier: std.builtin.CallOptions.Modifier = blk: { + const modifier: std.builtin.CallModifier = blk: { if (gz.force_comptime) { break :blk .compile_time; } diff --git a/src/Sema.zig b/src/Sema.zig index 3bad0b2b5f..885cdeb277 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5986,7 +5986,7 @@ fn zirCall( const extra = sema.code.extraData(Zir.Inst.Call, inst_data.payload_index); const args_len = extra.data.flags.args_len; - const modifier = @intToEnum(std.builtin.CallOptions.Modifier, extra.data.flags.packed_modifier); + const modifier = @intToEnum(std.builtin.CallModifier, extra.data.flags.packed_modifier); const ensure_result_used = extra.data.flags.ensure_result_used; const pop_error_return_trace = extra.data.flags.pop_error_return_trace; @@ -6222,7 +6222,7 @@ fn analyzeCall( func: Air.Inst.Ref, func_src: LazySrcLoc, call_src: LazySrcLoc, - modifier: std.builtin.CallOptions.Modifier, + modifier: std.builtin.CallModifier, ensure_result_used: bool, uncasted_args: []const Air.Inst.Ref, bound_arg_src: ?LazySrcLoc, @@ -20751,118 +20751,66 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. }); } -fn resolveCallOptions( - sema: *Sema, - block: *Block, - src: LazySrcLoc, - zir_ref: Zir.Inst.Ref, - is_comptime: bool, - is_nosuspend: bool, - func: Air.Inst.Ref, - func_src: LazySrcLoc, -) CompileError!std.builtin.CallOptions.Modifier { - const call_options_ty = try sema.getBuiltinType("CallOptions"); - const air_ref = try sema.resolveInst(zir_ref); - const options = try sema.coerce(block, call_options_ty, air_ref, src); - - const modifier_src = sema.maybeOptionsSrc(block, src, "modifier"); - const stack_src = sema.maybeOptionsSrc(block, src, "stack"); - - const modifier = try sema.fieldVal(block, src, options, "modifier", modifier_src); - const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier, "call modifier must be comptime-known"); - const wanted_modifier = modifier_val.toEnum(std.builtin.CallOptions.Modifier); +fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { + const tracy = trace(@src()); + defer tracy.end(); - const stack = try sema.fieldVal(block, src, options, "stack", stack_src); - const stack_val = try sema.resolveConstValue(block, stack_src, stack, "call stack value must be comptime-known"); + const inst_data = sema.code.instructions.items(.data)[inst].pl_node; + const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; + const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; + const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; + const call_src = inst_data.src(); - if (!stack_val.isNull()) { - return sema.fail(block, stack_src, "TODO: implement @call with stack", .{}); - } + const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; + var func = try sema.resolveInst(extra.callee); - switch (wanted_modifier) { + const modifier_ty = try sema.getBuiltinType("CallModifier"); + const air_ref = try sema.resolveInst(extra.modifier); + const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); + const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known"); + var modifier = modifier_val.toEnum(std.builtin.CallModifier); + switch (modifier) { // These can be upgraded to comptime or nosuspend calls. .auto, .never_tail, .no_async => { - if (is_comptime) { - if (wanted_modifier == .never_tail) { + if (extra.flags.is_comptime) { + if (modifier == .never_tail) { return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{}); } - return .compile_time; - } - if (is_nosuspend) { - return .no_async; + modifier = .compile_time; + } else if (extra.flags.is_nosuspend) { + modifier = .no_async; } - return wanted_modifier; }, // These can be upgraded to comptime. nosuspend bit can be safely ignored. .always_inline, .compile_time => { _ = (try sema.resolveDefinedValue(block, func_src, func)) orelse { - return sema.fail(block, func_src, "modifier '{s}' requires a comptime-known function", .{@tagName(wanted_modifier)}); + return sema.fail(block, func_src, "modifier '{s}' requires a comptime-known function", .{@tagName(modifier)}); }; - if (is_comptime) { - return .compile_time; + if (extra.flags.is_comptime) { + modifier = .compile_time; } - return wanted_modifier; }, .always_tail => { - if (is_comptime) { - return .compile_time; + if (extra.flags.is_comptime) { + modifier = .compile_time; } - return wanted_modifier; }, .async_kw => { - if (is_nosuspend) { + if (extra.flags.is_nosuspend) { return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used inside nosuspend block", .{}); } - if (is_comptime) { + if (extra.flags.is_comptime) { return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used in combination with comptime function call", .{}); } - return wanted_modifier; }, .never_inline => { - if (is_comptime) { + if (extra.flags.is_comptime) { return sema.fail(block, modifier_src, "unable to perform 'never_inline' call at compile-time", .{}); } - return wanted_modifier; }, } -} - -fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { - const tracy = trace(@src()); - defer tracy.end(); - const inst_data = sema.code.instructions.items(.data)[inst].pl_node; - const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; - const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; - const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; - const call_src = inst_data.src(); - - const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; - var func = try sema.resolveInst(extra.callee); - const modifier = sema.resolveCallOptions( - block, - .unneeded, - extra.options, - extra.flags.is_comptime, - extra.flags.is_nosuspend, - func, - func_src, - ) catch |err| switch (err) { - error.NeededSourceLocation => { - _ = try sema.resolveCallOptions( - block, - options_src, - extra.options, - extra.flags.is_comptime, - extra.flags.is_nosuspend, - func, - func_src, - ); - return error.AnalysisFail; - }, - else => |e| return e, - }; const args = try sema.resolveInst(extra.args); const args_ty = sema.typeOf(args); @@ -29558,7 +29506,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -29823,7 +29771,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { .address_space => return sema.getBuiltinType("AddressSpace"), .float_mode => return sema.getBuiltinType("FloatMode"), .reduce_op => return sema.getBuiltinType("ReduceOp"), - .call_options => return sema.getBuiltinType("CallOptions"), + .modifier => return sema.getBuiltinType("CallModifier"), .prefetch_options => return sema.getBuiltinType("PrefetchOptions"), else => return ty, @@ -30841,7 +30789,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -31164,7 +31112,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { .address_space => return .address_space_type, .float_mode => return .float_mode_type, .reduce_op => return .reduce_op_type, - .call_options => return .call_options_type, + .modifier => return .modifier_type, .prefetch_options => return .prefetch_options_type, .export_options => return .export_options_type, .extern_options => return .extern_options_type, @@ -31557,7 +31505,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -32387,7 +32335,7 @@ fn enumHasInt( .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 980bacf94f..fde5ed27db 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -71,7 +71,7 @@ fn join(pool: *ThreadPool, spawned: usize) void { pub fn spawn(pool: *ThreadPool, comptime func: anytype, args: anytype) !void { if (builtin.single_threaded) { - @call(.{}, func, args); + @call(.auto, func, args); return; } @@ -84,7 +84,7 @@ pub fn spawn(pool: *ThreadPool, comptime func: anytype, args: anytype) !void { fn runFn(runnable: *Runnable) void { const run_node = @fieldParentPtr(RunQueue.Node, "data", runnable); const closure = @fieldParentPtr(@This(), "run_node", run_node); - @call(.{}, func, closure.arguments); + @call(.auto, func, closure.arguments); // The thread pool's allocator is protected by the mutex. const mutex = &closure.pool.mutex; diff --git a/src/TypedValue.zig b/src/TypedValue.zig index 3c1972c78d..805448d540 100644 --- a/src/TypedValue.zig +++ b/src/TypedValue.zig @@ -136,7 +136,7 @@ pub fn print( .address_space_type => return writer.writeAll("std.builtin.AddressSpace"), .float_mode_type => return writer.writeAll("std.builtin.FloatMode"), .reduce_op_type => return writer.writeAll("std.builtin.ReduceOp"), - .call_options_type => return writer.writeAll("std.builtin.CallOptions"), + .modifier_type => return writer.writeAll("std.builtin.CallModifier"), .prefetch_options_type => return writer.writeAll("std.builtin.PrefetchOptions"), .export_options_type => return writer.writeAll("std.builtin.ExportOptions"), .extern_options_type => return writer.writeAll("std.builtin.ExternOptions"), diff --git a/src/Zir.zig b/src/Zir.zig index ed425ea73e..6e7164878c 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -2070,7 +2070,7 @@ pub const Inst = struct { address_space_type, float_mode_type, reduce_op_type, - call_options_type, + modifier_type, prefetch_options_type, export_options_type, extern_options_type, @@ -2345,9 +2345,9 @@ pub const Inst = struct { .ty = Type.initTag(.type), .val = Value.initTag(.reduce_op_type), }, - .call_options_type = .{ + .modifier_type = .{ .ty = Type.initTag(.type), - .val = Value.initTag(.call_options_type), + .val = Value.initTag(.modifier_type), }, .prefetch_options_type = .{ .ty = Type.initTag(.type), @@ -2832,7 +2832,7 @@ pub const Inst = struct { callee: Ref, pub const Flags = packed struct { - /// std.builtin.CallOptions.Modifier in packed form + /// std.builtin.CallModifier in packed form pub const PackedModifier = u3; pub const PackedArgsLen = u27; @@ -2844,7 +2844,7 @@ pub const Inst = struct { comptime { if (@sizeOf(Flags) != 4 or @bitSizeOf(Flags) != 32) @compileError("Layout of Call.Flags needs to be updated!"); - if (@bitSizeOf(std.builtin.CallOptions.Modifier) != @bitSizeOf(PackedModifier)) + if (@bitSizeOf(std.builtin.CallModifier) != @bitSizeOf(PackedModifier)) @compileError("Call.Flags.PackedModifier needs to be updated!"); } }; @@ -2860,7 +2860,7 @@ pub const Inst = struct { // Note: Flags *must* come first so that unusedResultExpr // can find it when it goes to modify them. flags: Flags, - options: Ref, + modifier: Ref, callee: Ref, args: Ref, diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 2edc6cb7f9..e09664598a 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -4110,7 +4110,7 @@ fn airFence(self: *Self) !void { //return self.finishAirBookkeeping(); } -fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) !void { +fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { if (modifier == .always_tail) return self.fail("TODO implement tail calls for aarch64", .{}); const pl_op = self.air.instructions.items(.data)[inst].pl_op; const callee = pl_op.operand; diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 6125ef1914..8197d85b48 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4097,7 +4097,7 @@ fn airFence(self: *Self) !void { //return self.finishAirBookkeeping(); } -fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) !void { +fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { if (modifier == .always_tail) return self.fail("TODO implement tail calls for arm", .{}); const pl_op = self.air.instructions.items(.data)[inst].pl_op; const callee = pl_op.operand; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 6a54ffeea2..58661926bb 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -1672,7 +1672,7 @@ fn airFence(self: *Self) !void { //return self.finishAirBookkeeping(); } -fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) !void { +fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { if (modifier == .always_tail) return self.fail("TODO implement tail calls for riscv64", .{}); const pl_op = self.air.instructions.items(.data)[inst].pl_op; const fn_ty = self.air.typeOf(pl_op.operand); diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 604fd3e69f..6eac6ba4fc 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -1155,7 +1155,7 @@ fn airBreakpoint(self: *Self) !void { return self.finishAirBookkeeping(); } -fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) !void { +fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { if (modifier == .always_tail) return self.fail("TODO implement tail calls for {}", .{self.target.cpu.arch}); const pl_op = self.air.instructions.items(.data)[inst].pl_op; diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index f6c380aeb3..99c0facb1a 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2099,7 +2099,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { return func.finishAir(inst, .none, &.{un_op}); } -fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) InnerError!void { +fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) InnerError!void { if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{}); const pl_op = func.air.instructions.items(.data)[inst].pl_op; const extra = func.air.extraData(Air.Call, pl_op.payload); diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index cd36642b03..bfb60bf74a 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -3899,7 +3899,7 @@ fn airFence(self: *Self) !void { //return self.finishAirBookkeeping(); } -fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) !void { +fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { if (modifier == .always_tail) return self.fail("TODO implement tail calls for x86_64", .{}); const pl_op = self.air.instructions.items(.data)[inst].pl_op; const callee = pl_op.operand; diff --git a/src/codegen/c.zig b/src/codegen/c.zig index b78c9e9b1a..55b9cd4b77 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -3874,7 +3874,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue { fn airCall( f: *Function, inst: Air.Inst.Index, - modifier: std.builtin.CallOptions.Modifier, + modifier: std.builtin.CallModifier, ) !CValue { // Not even allowed to call panic in a naked function. if (f.object.dg.decl.ty.fnCallingConvention() == .Naked) return .none; diff --git a/src/crash_report.zig b/src/crash_report.zig index cdb475ec6c..ba08db8266 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -549,8 +549,8 @@ const PanicSwitch = struct { // TODO: Tailcall is broken right now, but eventually this should be used // to avoid blowing up the stack. It's ok for now though, there are no // cycles in the state machine so the max stack usage is bounded. - //@call(.{.modifier = .always_tail}, func, args); - @call(.{}, func, args); + //@call(.always_tail, func, args); + @call(.auto, func, args); } fn recover( diff --git a/src/print_zir.zig b/src/print_zir.zig index 542f0e977d..6dbaf51bc3 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -801,7 +801,7 @@ const Writer = struct { try self.writeFlag(stream, "nosuspend ", extra.flags.is_nosuspend); try self.writeFlag(stream, "comptime ", extra.flags.is_comptime); - try self.writeInstRef(stream, extra.options); + try self.writeInstRef(stream, extra.modifier); try stream.writeAll(", "); try self.writeInstRef(stream, extra.callee); try stream.writeAll(", "); @@ -1170,7 +1170,7 @@ const Writer = struct { if (extra.data.flags.ensure_result_used) { try stream.writeAll("nodiscard "); } - try stream.print(".{s}, ", .{@tagName(@intToEnum(std.builtin.CallOptions.Modifier, extra.data.flags.packed_modifier))}); + try stream.print(".{s}, ", .{@tagName(@intToEnum(std.builtin.CallModifier, extra.data.flags.packed_modifier))}); try self.writeInstRef(stream, extra.data.callee); try stream.writeAll(", ["); diff --git a/src/type.zig b/src/type.zig index e64f310d79..93e8c4b502 100644 --- a/src/type.zig +++ b/src/type.zig @@ -129,7 +129,6 @@ pub const Type = extern union { .empty_struct, .empty_struct_literal, .@"struct", - .call_options, .prefetch_options, .export_options, .extern_options, @@ -147,6 +146,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, + .modifier, => return .Enum, .@"union", @@ -885,7 +885,6 @@ pub const Type = extern union { // we can't compare these based on tags because it wouldn't detect if, // for example, a was resolved into .@"struct" but b was one of these tags. - .call_options, .prefetch_options, .export_options, .extern_options, @@ -914,6 +913,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, + .modifier, => unreachable, // needed to resolve the type before now .@"union", .union_safety_tagged, .union_tagged => { @@ -1194,7 +1194,6 @@ pub const Type = extern union { }, // we can't hash these based on tags because they wouldn't match the expanded version. - .call_options, .prefetch_options, .export_options, .extern_options, @@ -1222,6 +1221,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, + .modifier, => unreachable, // needed to resolve the type before now .@"union", .union_safety_tagged, .union_tagged => { @@ -1333,7 +1333,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -1665,7 +1665,7 @@ pub const Type = extern union { .address_space => return writer.writeAll("std.builtin.AddressSpace"), .float_mode => return writer.writeAll("std.builtin.FloatMode"), .reduce_op => return writer.writeAll("std.builtin.ReduceOp"), - .call_options => return writer.writeAll("std.builtin.CallOptions"), + .modifier => return writer.writeAll("std.builtin.CallModifier"), .prefetch_options => return writer.writeAll("std.builtin.PrefetchOptions"), .export_options => return writer.writeAll("std.builtin.ExportOptions"), .extern_options => return writer.writeAll("std.builtin.ExternOptions"), @@ -1943,7 +1943,7 @@ pub const Type = extern union { .address_space => unreachable, .float_mode => unreachable, .reduce_op => unreachable, - .call_options => unreachable, + .modifier => unreachable, .prefetch_options => unreachable, .export_options => unreachable, .extern_options => unreachable, @@ -2311,7 +2311,7 @@ pub const Type = extern union { .address_space => return Value.initTag(.address_space_type), .float_mode => return Value.initTag(.float_mode_type), .reduce_op => return Value.initTag(.reduce_op_type), - .call_options => return Value.initTag(.call_options_type), + .modifier => return Value.initTag(.modifier_type), .prefetch_options => return Value.initTag(.prefetch_options_type), .export_options => return Value.initTag(.export_options_type), .extern_options => return Value.initTag(.extern_options_type), @@ -2385,7 +2385,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -2631,7 +2631,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -2873,7 +2873,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -3257,7 +3257,7 @@ pub const Type = extern union { .inferred_alloc_mut => unreachable, .var_args_param => unreachable, .generic_poison => unreachable, - .call_options => unreachable, // missing call to resolveTypeFields + .modifier => unreachable, // missing call to resolveTypeFields .prefetch_options => unreachable, // missing call to resolveTypeFields .export_options => unreachable, // missing call to resolveTypeFields .extern_options => unreachable, // missing call to resolveTypeFields @@ -3753,7 +3753,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -4279,7 +4279,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -4306,7 +4306,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -4990,7 +4990,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -5165,7 +5165,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -5483,7 +5483,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -5565,7 +5565,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -5878,7 +5878,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -5926,7 +5926,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, @@ -5991,7 +5991,7 @@ pub const Type = extern union { address_space, float_mode, reduce_op, - call_options, + modifier, prefetch_options, export_options, extern_options, @@ -6131,7 +6131,7 @@ pub const Type = extern union { .address_space, .float_mode, .reduce_op, - .call_options, + .modifier, .prefetch_options, .export_options, .extern_options, diff --git a/src/value.zig b/src/value.zig index dc0b150abc..f37fec13bb 100644 --- a/src/value.zig +++ b/src/value.zig @@ -71,7 +71,7 @@ pub const Value = extern union { address_space_type, float_mode_type, reduce_op_type, - call_options_type, + modifier_type, prefetch_options_type, export_options_type, extern_options_type, @@ -264,7 +264,7 @@ pub const Value = extern union { .address_space_type, .float_mode_type, .reduce_op_type, - .call_options_type, + .modifier_type, .prefetch_options_type, .export_options_type, .extern_options_type, @@ -467,7 +467,7 @@ pub const Value = extern union { .address_space_type, .float_mode_type, .reduce_op_type, - .call_options_type, + .modifier_type, .prefetch_options_type, .export_options_type, .extern_options_type, @@ -723,7 +723,7 @@ pub const Value = extern union { .address_space_type => return out_stream.writeAll("std.builtin.AddressSpace"), .float_mode_type => return out_stream.writeAll("std.builtin.FloatMode"), .reduce_op_type => return out_stream.writeAll("std.builtin.ReduceOp"), - .call_options_type => return out_stream.writeAll("std.builtin.CallOptions"), + .modifier_type => return out_stream.writeAll("std.builtin.CallModifier"), .prefetch_options_type => return out_stream.writeAll("std.builtin.PrefetchOptions"), .export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"), .extern_options_type => return out_stream.writeAll("std.builtin.ExternOptions"), @@ -963,7 +963,7 @@ pub const Value = extern union { .address_space_type => Type.initTag(.address_space), .float_mode_type => Type.initTag(.float_mode), .reduce_op_type => Type.initTag(.reduce_op), - .call_options_type => Type.initTag(.call_options), + .modifier_type => Type.initTag(.modifier), .prefetch_options_type => Type.initTag(.prefetch_options), .export_options_type => Type.initTag(.export_options), .extern_options_type => Type.initTag(.extern_options), diff --git a/stage1/zig1.wasm b/stage1/zig1.wasm Binary files differindex 25b6c42ab8..fd166c5ae0 100644 --- a/stage1/zig1.wasm +++ b/stage1/zig1.wasm diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index e5e28cddb3..43574db06f 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -966,8 +966,8 @@ test "generic function uses return type of other generic function" { fn call( f: anytype, args: anytype, - ) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) { - return @call(.{}, f, args); + ) @TypeOf(@call(.auto, f, @as(@TypeOf(args), undefined))) { + return @call(.auto, f, args); } fn func(arg: anytype) @TypeOf(arg) { diff --git a/test/behavior/call.zig b/test/behavior/call.zig index efda7fbacb..4d8f22d15f 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -9,11 +9,11 @@ test "super basic invocations" { return 1234; } }.foo; - try expect(@call(.{}, foo, .{}) == 1234); - comptime try expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234); + try expect(@call(.auto, foo, .{}) == 1234); + comptime try expect(@call(.always_inline, foo, .{}) == 1234); { // comptime call without comptime keyword - const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234; + const result = @call(.compile_time, foo, .{}) == 1234; comptime try expect(result); } } @@ -31,25 +31,25 @@ test "basic invocations" { return 1234; } }.foo; - try expect(@call(.{}, foo, .{}) == 1234); + try expect(@call(.auto, foo, .{}) == 1234); comptime { // modifiers that allow comptime calls - try expect(@call(.{}, foo, .{}) == 1234); - try expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234); - try expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234); - try expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234); + try expect(@call(.auto, foo, .{}) == 1234); + try expect(@call(.no_async, foo, .{}) == 1234); + try expect(@call(.always_tail, foo, .{}) == 1234); + try expect(@call(.always_inline, foo, .{}) == 1234); } { // comptime call without comptime keyword - const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234; + const result = @call(.compile_time, foo, .{}) == 1234; comptime try expect(result); } { // call of non comptime-known function var alias_foo = &foo; - try expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234); - try expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234); - try expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234); + try expect(@call(.no_async, alias_foo, .{}) == 1234); + try expect(@call(.never_tail, alias_foo, .{}) == 1234); + try expect(@call(.never_inline, alias_foo, .{}) == 1234); } } @@ -66,23 +66,23 @@ test "tuple parameters" { }.add; var a: i32 = 12; var b: i32 = 34; - try expect(@call(.{}, add, .{ a, 34 }) == 46); - try expect(@call(.{}, add, .{ 12, b }) == 46); - try expect(@call(.{}, add, .{ a, b }) == 46); - try expect(@call(.{}, add, .{ 12, 34 }) == 46); + try expect(@call(.auto, add, .{ a, 34 }) == 46); + try expect(@call(.auto, add, .{ 12, b }) == 46); + try expect(@call(.auto, add, .{ a, b }) == 46); + try expect(@call(.auto, add, .{ 12, 34 }) == 46); if (false) { - comptime try expect(@call(.{}, add, .{ 12, 34 }) == 46); // TODO + comptime try expect(@call(.auto, add, .{ 12, 34 }) == 46); // TODO } - try expect(comptime @call(.{}, add, .{ 12, 34 }) == 46); + try expect(comptime @call(.auto, add, .{ 12, 34 }) == 46); { const separate_args0 = .{ a, b }; const separate_args1 = .{ a, 34 }; const separate_args2 = .{ 12, 34 }; const separate_args3 = .{ 12, b }; - try expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46); - try expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46); - try expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46); - try expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46); + try expect(@call(.always_inline, add, separate_args0) == 46); + try expect(@call(.always_inline, add, separate_args1) == 46); + try expect(@call(.always_inline, add, separate_args2) == 46); + try expect(@call(.always_inline, add, separate_args3) == 46); } } @@ -281,7 +281,7 @@ test "forced tail call" { if (n == 0) return a; if (n == 1) return b; return @call( - .{ .modifier = .always_tail }, + .always_tail, fibonacciTailInternal, .{ n - 1, b, a + b }, ); @@ -322,7 +322,7 @@ test "inline call preserves tail call" { var buf: [max]u16 = undefined; buf[a] = a; a += 1; - return @call(.{ .modifier = .always_tail }, foo, .{}); + return @call(.always_tail, foo, .{}); } }; S.foo(); @@ -341,6 +341,6 @@ test "inline call doesn't re-evaluate non generic struct" { } }; const ArgTuple = std.meta.ArgsTuple(@TypeOf(S.foo)); - try @call(.{ .modifier = .always_inline }, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); - comptime try @call(.{ .modifier = .always_inline }, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); + try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); + comptime try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); } diff --git a/test/cases/compile_errors/bad_usage_of_call.zig b/test/cases/compile_errors/bad_usage_of_call.zig index 9e8fb7d188..c0b632bef6 100644 --- a/test/cases/compile_errors/bad_usage_of_call.zig +++ b/test/cases/compile_errors/bad_usage_of_call.zig @@ -1,22 +1,22 @@ export fn entry1() void { - @call(.{}, foo, {}); + @call(.auto, foo, {}); } export fn entry2() void { - comptime @call(.{ .modifier = .never_inline }, foo, .{}); + comptime @call(.never_inline, foo, .{}); } export fn entry3() void { - comptime @call(.{ .modifier = .never_tail }, foo, .{}); + comptime @call(.never_tail, foo, .{}); } export fn entry4() void { - @call(.{ .modifier = .never_inline }, bar, .{}); + @call(.never_inline, bar, .{}); } export fn entry5(c: bool) void { var baz = if (c) &baz1 else &baz2; - @call(.{ .modifier = .compile_time }, baz, .{}); + @call(.compile_time, baz, .{}); } pub export fn entry() void { var call_me: *const fn () void = undefined; - @call(.{ .modifier = .always_inline }, call_me, .{}); + @call(.always_inline, call_me, .{}); } fn foo() void {} fn bar() callconv(.Inline) void {} @@ -27,9 +27,10 @@ fn baz2() void {} // backend=stage2 // target=native // -// :2:21: error: expected a tuple, found 'void' -// :5:33: error: unable to perform 'never_inline' call at compile-time -// :8:33: error: unable to perform 'never_tail' call at compile-time +// :2:23: error: expected a tuple, found 'void' +// :5:21: error: unable to perform 'never_inline' call at compile-time +// :8:21: error: unable to perform 'never_tail' call at compile-time // :11:5: error: no-inline call of inline function -// :15:43: error: modifier 'compile_time' requires a comptime-known function -// :19:44: error: modifier 'always_inline' requires a comptime-known function +// :15:26: error: modifier 'compile_time' requires a comptime-known function +// :19:27: error: modifier 'always_inline' requires a comptime-known function + diff --git a/test/cases/compile_errors/error_in_call_builtin_args.zig b/test/cases/compile_errors/error_in_call_builtin_args.zig index ca46f7fe77..304fd031f1 100644 --- a/test/cases/compile_errors/error_in_call_builtin_args.zig +++ b/test/cases/compile_errors/error_in_call_builtin_args.zig @@ -1,15 +1,15 @@ fn foo(_: u32, _: u32) void {} pub export fn entry() void { - @call(.{}, foo, .{ 12, 12.34 }); + @call(.auto, foo, .{ 12, 12.34 }); } pub export fn entry1() void { const args = .{ 12, 12.34 }; - @call(.{}, foo, args); + @call(.auto, foo, args); } // error // backend=stage2 // target=native // -// :3:28: error: fractional component prevents float value '12.34' from coercion to type 'u32' -// :7:21: error: fractional component prevents float value '12.34' from coercion to type 'u32' +// :3:30: error: fractional component prevents float value '12.34' from coercion to type 'u32' +// :7:23: error: fractional component prevents float value '12.34' from coercion to type 'u32' diff --git a/test/cases/compile_errors/invalid_tail_call.zig b/test/cases/compile_errors/invalid_tail_call.zig index cdeb9df930..e3ce28709a 100644 --- a/test/cases/compile_errors/invalid_tail_call.zig +++ b/test/cases/compile_errors/invalid_tail_call.zig @@ -2,7 +2,7 @@ fn myFn(_: usize) void { return; } pub export fn entry() void { - @call(.{ .modifier = .always_tail }, myFn, .{0}); + @call(.always_tail, myFn, .{0}); } // error diff --git a/test/cases/taill_call_noreturn.zig b/test/cases/taill_call_noreturn.zig index fabb9e729b..5cd716dd30 100644 --- a/test/cases/taill_call_noreturn.zig +++ b/test/cases/taill_call_noreturn.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = std.builtin; pub fn foo(message: []const u8, stack_trace: ?*builtin.StackTrace) noreturn { - @call(.{ .modifier = .always_tail }, bar, .{ message, stack_trace }); + @call(.always_tail, bar, .{ message, stack_trace }); } pub fn bar(message: []const u8, stack_trace: ?*builtin.StackTrace) noreturn { _ = message; |
