Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoTailCall option #3732

Closed
daurnimator opened this issue Nov 20, 2019 · 6 comments · Fixed by #3856
Closed

NoTailCall option #3732

daurnimator opened this issue Nov 20, 2019 · 6 comments · Fixed by #3856
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@daurnimator
Copy link
Contributor

daurnimator commented Nov 20, 2019

Originally from #2598

I just recalled something from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826

Now dlsym (and other dl-functions) secretly take shadow parameter - return address on stack

We need a way to ensure that a given call is not a tail call.

LLVM does have a notail option

@daurnimator
Copy link
Contributor Author

daurnimator commented Nov 20, 2019

To avoid proliferation of @inlineCall/@noInlineCall/@newStackCall/@noTailCall, etc.
I propose a @call builtin that takes a structure of options:

const Maybe = enum {
    Default,
    Always,
    Never,
};
@call(comptime options: struct {
    tailCall: Maybe = .Default,
    inlineCall: Maybe = .Default,
    newStack: ?[]align(target_stack_align) u8 = null,
}, function: var, args: ...);

@daurnimator daurnimator added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Nov 20, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Nov 20, 2019
@emekoi
Copy link
Contributor

emekoi commented Nov 20, 2019

perhaps asyncCall could be merged with this?

@ghost
Copy link

ghost commented Nov 20, 2019

Your code example is missing the handle to the function itself, and if we are getting rid of var args (#208) then the args argument should be a var which is filled using anonymous literal syntax. That would end up looking like this:

const result = @call(myFunc, .{ .tailCall = false }, .{ false, 1, "three" });

@fengb
Copy link
Contributor

fengb commented Nov 20, 2019

How about just 1 argument?

 @call(.{
    .tailCall = false,
    .func = myFunc,
    .args = .{ false, 1, "three" })
});

@daurnimator
Copy link
Contributor Author

How about just 1 argument?

I think this looks harder to use. Also the call type needs to be comptime known, while the function and arguments can be runtime known.

@daurnimator
Copy link
Contributor Author

Your code example is missing the handle to the function itself,

Fixed.

and if we are getting rid of var args (#208) then the args argument should be a var which is filled using anonymous literal syntax. That would end up looking like this:

const result = @call(myFunc, .{ .tailCall = false }, .{ false, 1, "three" });

Builtins don't need to follow the rest of the language like this: they aren't normal functions. see e.g. @field

@andrewrk andrewrk added the accepted This proposal is planned. label Dec 4, 2019
andrewrk added a commit that referenced this issue Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants