Commit 17c8f108a4
Changed files (7)
lib
std
test
stage1
behavior
doc/langref.html.in
@@ -7001,40 +7001,6 @@ pub const CallOptions = struct {
};
};
{#code_end#}
-
- {#header_open|Calling with a New Stack#}
- <p>
- When the {#syntax#}stack{#endsyntax#} option is provided, instead of using the same stack as the caller, the function uses the provided stack.
- </p>
- {#code_begin|test|new_stack_call#}
-const std = @import("std");
-const assert = std.debug.assert;
-
-var new_stack_bytes: [1024]u8 align(16) = undefined;
-
-test "calling a function with a new stack" {
- const arg = 1234;
-
- const a = @call(.{.stack = new_stack_bytes[0..512]}, targetFunction, .{arg});
- const b = @call(.{.stack = new_stack_bytes[512..]}, targetFunction, .{arg});
- _ = targetFunction(arg);
-
- assert(arg == 1234);
- assert(a < b);
-}
-
-fn targetFunction(x: i32) usize {
- assert(x == 1234);
-
- var local_variable: i32 = 42;
- const ptr = &local_variable;
- ptr.* += 1;
-
- assert(local_variable == 43);
- return @ptrToInt(ptr);
-}
- {#code_end#}
- {#header_close#}
{#header_close#}
{#header_open|@cDefine#}
lib/std/builtin.zig
@@ -408,6 +408,8 @@ pub const Version = struct {
/// 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 {
src/all_types.hpp
@@ -1767,7 +1767,6 @@ enum BuiltinFnId {
BuiltinFnIdFieldParentPtr,
BuiltinFnIdByteOffsetOf,
BuiltinFnIdBitOffsetOf,
- BuiltinFnIdNewStackCall,
BuiltinFnIdAsyncCall,
BuiltinFnIdTypeId,
BuiltinFnIdShlExact,
src/codegen.cpp
@@ -8215,7 +8215,6 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdNearbyInt, "nearbyInt", 1);
create_builtin_fn(g, BuiltinFnIdRound, "round", 1);
create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);
- create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);
create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);
create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);
create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);
src/ir.cpp
@@ -7145,39 +7145,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
}
- case BuiltinFnIdNewStackCall:
- {
- if (node->data.fn_call_expr.params.length < 2) {
- add_node_error(irb->codegen, node,
- buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,
- node->data.fn_call_expr.params.length));
- return irb->codegen->invalid_inst_src;
- }
-
- AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope);
- if (new_stack == irb->codegen->invalid_inst_src)
- return new_stack;
-
- AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
- IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
- if (fn_ref == irb->codegen->invalid_inst_src)
- return fn_ref;
-
- size_t arg_count = node->data.fn_call_expr.params.length - 2;
-
- IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
- for (size_t i = 0; i < arg_count; i += 1) {
- AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
- args[i] = ir_gen_node(irb, arg_node, scope);
- if (args[i] == irb->codegen->invalid_inst_src)
- return args[i];
- }
-
- IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
- nullptr, CallModifierNone, false, new_stack, result_loc);
- return ir_lval_wrap(irb, scope, call, lval, result_loc);
- }
case BuiltinFnIdCall: {
// Cast the options parameter to the options type
ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");
test/stage1/behavior/new_stack_call.zig
@@ -1,38 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-
-var new_stack_bytes: [1024]u8 align(16) = undefined;
-
-test "calling a function with a new stack" {
- // TODO: https://github.com/ziglang/zig/issues/3268
- if (@import("builtin").arch == .aarch64) return error.SkipZigTest;
- if (@import("builtin").arch == .mipsel) return error.SkipZigTest;
-
- if (@import("builtin").arch == .riscv64) {
- // TODO: https://github.com/ziglang/zig/issues/3338
- return error.SkipZigTest;
- }
- if (comptime !std.Target.current.supportsNewStackCall()) {
- return error.SkipZigTest;
- }
-
- const arg = 1234;
-
- const a = @call(.{ .stack = new_stack_bytes[0..512] }, targetFunction, .{arg});
- const b = @call(.{ .stack = new_stack_bytes[512..] }, targetFunction, .{arg});
- _ = targetFunction(arg);
-
- expect(arg == 1234);
- expect(a < b);
-}
-
-fn targetFunction(x: i32) usize {
- expect(x == 1234);
-
- var local_variable: i32 = 42;
- const ptr = &local_variable;
- ptr.* += 1;
-
- expect(local_variable == 43);
- return @ptrToInt(ptr);
-}
test/stage1/behavior.zig
@@ -80,7 +80,6 @@ comptime {
_ = @import("behavior/misc.zig");
_ = @import("behavior/muladd.zig");
_ = @import("behavior/namespace_depends_on_compile_var.zig");
- _ = @import("behavior/new_stack_call.zig");
_ = @import("behavior/null.zig");
_ = @import("behavior/optional.zig");
_ = @import("behavior/pointers.zig");