From 656cc33f8d49cb5e79cd3f9f8f56963747d43ed6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 6 Dec 2019 15:25:00 -0500 Subject: [PATCH] allow calling with a new stack to regress a bit Calling with a new stack, with a runtime-known stack pointer (e.g. not a global variable) is regressed with this branch. It is now a compile-error, due to the Runtime Hint system not being smart enough to mix a compile-time modifier field with a runtime stack field. I'm OK with this regression because this feature is flawed (see #3268) and may be deleted from the language. --- doc/langref.html.in | 15 ++++----------- lib/std/builtin.zig | 14 ++++---------- src/all_types.hpp | 10 ++++++---- test/compile_errors.zig | 4 ++-- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index ba0aa7a77851..e7b28014bd13 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -6870,16 +6870,6 @@ pub const CallOptions = struct { /// Equivalent to function call syntax. auto, - /// Asserts that the function call will not suspend. This allows a - /// non-async function to call an async function. - no_async, - - /// The function call will return an async function frame instead of - /// the function's result, which is expected to then be awaited. - /// This is equivalent to using the `async` keyword in front of function - /// call syntax. - async_call, - /// 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 @@ -6890,6 +6880,10 @@ pub const CallOptions = struct { /// 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, @@ -6938,7 +6932,6 @@ fn targetFunction(x: i32) usize { } {#code_end#} {#header_close#} - {#header_close#} {#header_open|@cDefine#} diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 8ac58ad2f46d..35188b61e305 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -382,16 +382,6 @@ pub const CallOptions = struct { /// Equivalent to function call syntax. auto, - /// Asserts that the function call will not suspend. This allows a - /// non-async function to call an async function. - no_async, - - /// The function call will return an async function frame instead of - /// the function's result, which is expected to then be awaited. - /// This is equivalent to using the `async` keyword in front of function - /// call syntax. - async_call, - /// 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 @@ -402,6 +392,10 @@ pub const CallOptions = struct { /// 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, diff --git a/src/all_types.hpp b/src/all_types.hpp index c8804ac273bc..a5b080498556 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -409,6 +409,9 @@ struct ZigValue { LLVMValueRef llvm_global; union { + // populated if special == ConstValSpecialLazy + LazyValue *x_lazy; + // populated if special == ConstValSpecialStatic BigInt x_bigint; BigFloat x_bigfloat; @@ -429,7 +432,6 @@ struct ZigValue { ConstPtrValue x_ptr; ConstArgTuple x_arg_tuple; Buf *x_enum_literal; - LazyValue *x_lazy; // populated if special == ConstValSpecialRuntime RuntimeHintErrorUnion rh_error_union; @@ -770,16 +772,16 @@ struct AstNodeUnwrapOptional { // Must be synchronized with std.builtin.CallOptions.Modifier enum CallModifier { CallModifierNone, - CallModifierNoAsync, - CallModifierAsync, CallModifierNeverTail, CallModifierNeverInline, + CallModifierNoAsync, CallModifierAlwaysTail, CallModifierAlwaysInline, CallModifierCompileTime, - // This is an additional tag in the compiler, but not exposed in the std lib. + // These are additional tags in the compiler, but not exposed in the std lib. CallModifierBuiltin, + CallModifierAsync, }; struct AstNodeFnCallExpr { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 9494879f718d..13e666f49ea7 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -45,9 +45,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.addCase(x: { var tc = cases.create("call with new stack on unsupported target", + \\var buf: [10]u8 align(16) = undefined; \\export fn entry() void { - \\ var buf: [10]u8 align(16) = undefined; - \\ @call(.{.stack = &buf}, foo); + \\ @call(.{.stack = &buf}, foo, .{}); \\} \\fn foo() void {} , "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack");