Merge pull request #13907 from Vexu/call-merge

Remove `stack` option from `@call`
This commit is contained in:
Andrew Kelley 2022-12-13 18:15:18 -05:00 committed by GitHub
commit 6378644d4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 260 additions and 332 deletions

View File

@ -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,
{#syntax_block|zig|builtin.CallModifier struct#}
pub const CallModifier = enum {
/// Equivalent to function call syntax.
auto,
/// Only valid when `Modifier` is `Modifier.async_kw`.
stack: ?[]align(std.Target.stack_align) u8 = null,
/// Equivalent to async keyword used with function call syntax.
async_kw,
pub const Modifier = enum {
/// Equivalent to function call syntax.
auto,
/// 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,
/// Equivalent to async keyword used with function call syntax.
async_kw,
/// 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,
/// 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,
/// 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 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 be generated with tail call optimization.
/// If this is not possible, a compile error is emitted instead.
always_tail,
/// 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 inlined at the callsite.
/// If this is not possible, a compile error is emitted instead.
always_inline,
/// 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,
};
/// 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#}

View File

@ -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, .{});
}

View File

@ -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.*);

View File

@ -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,
pub const CallModifier = enum {
/// Equivalent to function call syntax.
auto,
/// Only valid when `Modifier` is `Modifier.async_kw`.
stack: ?[]align(std.Target.stack_align) u8 = null,
/// Equivalent to async keyword used with function call syntax.
async_kw,
pub const Modifier = enum {
/// Equivalent to function call syntax.
auto,
/// 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,
/// Equivalent to async keyword used with function call syntax.
async_kw,
/// 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,
/// 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,
/// 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 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 be generated with tail call optimization.
/// If this is not possible, a compile error is emitted instead.
always_tail,
/// 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 inlined at the callsite.
/// If this is not possible, a compile error is emitted instead.
always_inline,
/// 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,
};
/// 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

View File

@ -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..]});
}
};
}

View File

@ -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;

View File

@ -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),

View File

@ -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 {

View File

@ -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 {

View File

@ -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..]});
}
};

View File

@ -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),

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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},
);

View File

@ -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;
}

View File

@ -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);
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");
if (!stack_val.isNull()) {
return sema.fail(block, stack_src, "TODO: implement @call with stack", .{});
}
switch (wanted_modifier) {
// These can be upgraded to comptime or nosuspend calls.
.auto, .never_tail, .no_async => {
if (is_comptime) {
if (wanted_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;
}
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)});
};
if (is_comptime) {
return .compile_time;
}
return wanted_modifier;
},
.always_tail => {
if (is_comptime) {
return .compile_time;
}
return wanted_modifier;
},
.async_kw => {
if (is_nosuspend) {
return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used inside nosuspend block", .{});
}
if (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) {
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 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();
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;
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 (extra.flags.is_comptime) {
if (modifier == .never_tail) {
return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{});
}
modifier = .compile_time;
} else if (extra.flags.is_nosuspend) {
modifier = .no_async;
}
},
else => |e| return e,
};
// 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(modifier)});
};
if (extra.flags.is_comptime) {
modifier = .compile_time;
}
},
.always_tail => {
if (extra.flags.is_comptime) {
modifier = .compile_time;
}
},
.async_kw => {
if (extra.flags.is_nosuspend) {
return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used inside nosuspend block", .{});
}
if (extra.flags.is_comptime) {
return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used in combination with comptime function call", .{});
}
},
.never_inline => {
if (extra.flags.is_comptime) {
return sema.fail(block, modifier_src, "unable to perform 'never_inline' call at compile-time", .{});
}
},
}
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,

View File

@ -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;

View File

@ -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"),

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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(

View File

@ -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(", [");

View File

@ -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,

View File

@ -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),

Binary file not shown.

View File

@ -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) {

View File

@ -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 }});
}

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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;