Skip to content

Commit

Permalink
allow calling with a new stack to regress a bit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewrk committed Dec 6, 2019
1 parent 71b7f4b commit 656cc33
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
15 changes: 4 additions & 11 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -6938,7 +6932,6 @@ fn targetFunction(x: i32) usize {
}
{#code_end#}
{#header_close#}

{#header_close#}

{#header_open|@cDefine#}
Expand Down
14 changes: 4 additions & 10 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 656cc33

Please sign in to comment.