authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-30 17:50:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-30 17:51:55-05:00
log17c8f108a4d4c753e087e23ff5722718a6cd7a6a
treeae936bd071b9675125d6d64b31aec5620d145cbd
parent4d2fed62325d0ef7326c791ab4957154f7ba4c59
signaturelock-open Commit is signed but in an unrecognized format.

drop @newStackCall

this was causing unrelated behavior tests to fail. if this commit is reverted, the docs are good, but `@newStackCall` is already deprecated in favor of `@call`, supplying the `stack` property.

7 files changed, 2 insertions(+), 108 deletions(-)

doc/langref.html.in-34
...@@ -7001,40 +7001,6 @@ pub const CallOptions = struct {...@@ -7001,40 +7001,6 @@ pub const CallOptions = struct {
7001 };7001 };
7002};7002};
7003 {#code_end#}7003 {#code_end#}
7004
7005 {#header_open|Calling with a New Stack#}
7006 <p>
7007 When the {#syntax#}stack{#endsyntax#} option is provided, instead of using the same stack as the caller, the function uses the provided stack.
7008 </p>
7009 {#code_begin|test|new_stack_call#}
7010const std = @import("std");
7011const assert = std.debug.assert;
7012
7013var new_stack_bytes: [1024]u8 align(16) = undefined;
7014
7015test "calling a function with a new stack" {
7016 const arg = 1234;
7017
7018 const a = @call(.{.stack = new_stack_bytes[0..512]}, targetFunction, .{arg});
7019 const b = @call(.{.stack = new_stack_bytes[512..]}, targetFunction, .{arg});
7020 _ = targetFunction(arg);
7021
7022 assert(arg == 1234);
7023 assert(a < b);
7024}
7025
7026fn targetFunction(x: i32) usize {
7027 assert(x == 1234);
7028
7029 var local_variable: i32 = 42;
7030 const ptr = &local_variable;
7031 ptr.* += 1;
7032
7033 assert(local_variable == 43);
7034 return @ptrToInt(ptr);
7035}
7036 {#code_end#}
7037 {#header_close#}
7038 {#header_close#}7004 {#header_close#}
70397005
7040 {#header_open|@cDefine#}7006 {#header_open|@cDefine#}
lib/std/builtin.zig+2
...@@ -408,6 +408,8 @@ pub const Version = struct {...@@ -408,6 +408,8 @@ pub const Version = struct {
408/// therefore must be kept in sync with the compiler implementation.408/// therefore must be kept in sync with the compiler implementation.
409pub const CallOptions = struct {409pub const CallOptions = struct {
410 modifier: Modifier = .auto,410 modifier: Modifier = .auto,
411
412 /// Only valid when `Modifier` is `Modifier.async_kw`.
411 stack: ?[]align(std.Target.stack_align) u8 = null,413 stack: ?[]align(std.Target.stack_align) u8 = null,
412414
413 pub const Modifier = enum {415 pub const Modifier = enum {
src/all_types.hpp-1
...@@ -1767,7 +1767,6 @@ enum BuiltinFnId {...@@ -1767,7 +1767,6 @@ enum BuiltinFnId {
1767 BuiltinFnIdFieldParentPtr,1767 BuiltinFnIdFieldParentPtr,
1768 BuiltinFnIdByteOffsetOf,1768 BuiltinFnIdByteOffsetOf,
1769 BuiltinFnIdBitOffsetOf,1769 BuiltinFnIdBitOffsetOf,
1770 BuiltinFnIdNewStackCall,
1771 BuiltinFnIdAsyncCall,1770 BuiltinFnIdAsyncCall,
1772 BuiltinFnIdTypeId,1771 BuiltinFnIdTypeId,
1773 BuiltinFnIdShlExact,1772 BuiltinFnIdShlExact,
src/codegen.cpp-1
...@@ -8215,7 +8215,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8215,7 +8215,6 @@ static void define_builtin_fns(CodeGen *g) {
8215 create_builtin_fn(g, BuiltinFnIdNearbyInt, "nearbyInt", 1);8215 create_builtin_fn(g, BuiltinFnIdNearbyInt, "nearbyInt", 1);
8216 create_builtin_fn(g, BuiltinFnIdRound, "round", 1);8216 create_builtin_fn(g, BuiltinFnIdRound, "round", 1);
8217 create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);8217 create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);
8218 create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);
8219 create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);8218 create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);
8220 create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);8219 create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);
8221 create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);8220 create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);
src/ir.cpp-33
...@@ -7145,39 +7145,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod...@@ -7145,39 +7145,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
7145 IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);7145 IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
7146 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);7146 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
7147 }7147 }
7148 case BuiltinFnIdNewStackCall:
7149 {
7150 if (node->data.fn_call_expr.params.length < 2) {
7151 add_node_error(irb->codegen, node,
7152 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,
7153 node->data.fn_call_expr.params.length));
7154 return irb->codegen->invalid_inst_src;
7155 }
7156
7157 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);
7158 IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope);
7159 if (new_stack == irb->codegen->invalid_inst_src)
7160 return new_stack;
7161
7162 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
7163 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
7164 if (fn_ref == irb->codegen->invalid_inst_src)
7165 return fn_ref;
7166
7167 size_t arg_count = node->data.fn_call_expr.params.length - 2;
7168
7169 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
7170 for (size_t i = 0; i < arg_count; i += 1) {
7171 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
7172 args[i] = ir_gen_node(irb, arg_node, scope);
7173 if (args[i] == irb->codegen->invalid_inst_src)
7174 return args[i];
7175 }
7176
7177 IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
7178 nullptr, CallModifierNone, false, new_stack, result_loc);
7179 return ir_lval_wrap(irb, scope, call, lval, result_loc);
7180 }
7181 case BuiltinFnIdCall: {7148 case BuiltinFnIdCall: {
7182 // Cast the options parameter to the options type7149 // Cast the options parameter to the options type
7183 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");7150 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");
test/stage1/behavior.zig-1
...@@ -80,7 +80,6 @@ comptime {...@@ -80,7 +80,6 @@ comptime {
80 _ = @import("behavior/misc.zig");80 _ = @import("behavior/misc.zig");
81 _ = @import("behavior/muladd.zig");81 _ = @import("behavior/muladd.zig");
82 _ = @import("behavior/namespace_depends_on_compile_var.zig");82 _ = @import("behavior/namespace_depends_on_compile_var.zig");
83 _ = @import("behavior/new_stack_call.zig");
84 _ = @import("behavior/null.zig");83 _ = @import("behavior/null.zig");
85 _ = @import("behavior/optional.zig");84 _ = @import("behavior/optional.zig");
86 _ = @import("behavior/pointers.zig");85 _ = @import("behavior/pointers.zig");
test/stage1/behavior/new_stack_call.zig deleted-38
...@@ -1,38 +0,0 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4var new_stack_bytes: [1024]u8 align(16) = undefined;
5
6test "calling a function with a new stack" {
7 // TODO: https://github.com/ziglang/zig/issues/3268
8 if (@import("builtin").arch == .aarch64) return error.SkipZigTest;
9 if (@import("builtin").arch == .mipsel) return error.SkipZigTest;
10
11 if (@import("builtin").arch == .riscv64) {
12 // TODO: https://github.com/ziglang/zig/issues/3338
13 return error.SkipZigTest;
14 }
15 if (comptime !std.Target.current.supportsNewStackCall()) {
16 return error.SkipZigTest;
17 }
18
19 const arg = 1234;
20
21 const a = @call(.{ .stack = new_stack_bytes[0..512] }, targetFunction, .{arg});
22 const b = @call(.{ .stack = new_stack_bytes[512..] }, targetFunction, .{arg});
23 _ = targetFunction(arg);
24
25 expect(arg == 1234);
26 expect(a < b);
27}
28
29fn targetFunction(x: i32) usize {
30 expect(x == 1234);
31
32 var local_variable: i32 = 42;
33 const ptr = &local_variable;
34 ptr.* += 1;
35
36 expect(local_variable == 43);
37 return @ptrToInt(ptr);
38}