| author | |
| committer | |
| log | 17c8f108a4d4c753e087e23ff5722718a6cd7a6a |
| tree | ae936bd071b9675125d6d64b31aec5620d145cbd |
| parent | 4d2fed62325d0ef7326c791ab4957154f7ba4c59 |
| signature |
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 | 7001 | }; |
| 7002 | 7002 | }; |
| 7003 | 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#} | |
| 7010 | const std = @import("std"); | |
| 7011 | const assert = std.debug.assert; | |
| 7012 | ||
| 7013 | var new_stack_bytes: [1024]u8 align(16) = undefined; | |
| 7014 | ||
| 7015 | test "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 | ||
| 7026 | fn 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 | 7004 | {#header_close#} |
| 7039 | 7005 | |
| 7040 | 7006 | {#header_open|@cDefine#} |
lib/std/builtin.zig+2| ... | ... | @@ -408,6 +408,8 @@ pub const Version = struct { |
| 408 | 408 | /// therefore must be kept in sync with the compiler implementation. |
| 409 | 409 | pub const CallOptions = struct { |
| 410 | 410 | modifier: Modifier = .auto, |
| 411 | ||
| 412 | /// Only valid when `Modifier` is `Modifier.async_kw`. | |
| 411 | 413 | stack: ?[]align(std.Target.stack_align) u8 = null, |
| 412 | 414 | |
| 413 | 415 | pub const Modifier = enum { |
src/all_types.hpp-1| ... | ... | @@ -1767,7 +1767,6 @@ enum BuiltinFnId { |
| 1767 | 1767 | BuiltinFnIdFieldParentPtr, |
| 1768 | 1768 | BuiltinFnIdByteOffsetOf, |
| 1769 | 1769 | BuiltinFnIdBitOffsetOf, |
| 1770 | BuiltinFnIdNewStackCall, | |
| 1771 | 1770 | BuiltinFnIdAsyncCall, |
| 1772 | 1771 | BuiltinFnIdTypeId, |
| 1773 | 1772 | BuiltinFnIdShlExact, |
src/codegen.cpp-1| ... | ... | @@ -8215,7 +8215,6 @@ static void define_builtin_fns(CodeGen *g) { |
| 8215 | 8215 | create_builtin_fn(g, BuiltinFnIdNearbyInt, "nearbyInt", 1); |
| 8216 | 8216 | create_builtin_fn(g, BuiltinFnIdRound, "round", 1); |
| 8217 | 8217 | create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4); |
| 8218 | create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX); | |
| 8219 | 8218 | create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX); |
| 8220 | 8219 | create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1); |
| 8221 | 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 | 7145 | IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 7146 | 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 | 7148 | case BuiltinFnIdCall: { |
| 7182 | 7149 | // Cast the options parameter to the options type |
| 7183 | 7150 | ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions"); |
test/stage1/behavior.zig-1| ... | ... | @@ -80,7 +80,6 @@ comptime { |
| 80 | 80 | _ = @import("behavior/misc.zig"); |
| 81 | 81 | _ = @import("behavior/muladd.zig"); |
| 82 | 82 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); |
| 83 | _ = @import("behavior/new_stack_call.zig"); | |
| 84 | 83 | _ = @import("behavior/null.zig"); |
| 85 | 84 | _ = @import("behavior/optional.zig"); |
| 86 | 85 | _ = @import("behavior/pointers.zig"); |
test/stage1/behavior/new_stack_call.zig deleted-38| ... | ... | @@ -1,38 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | ||
| 4 | var new_stack_bytes: [1024]u8 align(16) = undefined; | |
| 5 | ||
| 6 | test "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 | ||
| 29 | fn 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 | } |