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

@noInlineCall should cause a compile error when called on inline fn #1133

tgschultz opened this Issue Jun 18, 2018 · 2 comments


None yet
2 participants

tgschultz commented Jun 18, 2018

const std = @import("std");
const debug = std.debug;

const MyStruct = struct {
    addr: usize,
    ptr: *MyStruct,
    //Assertion will succeed when inline is removed
    pub inline fn init() *MyStruct {
       var ms: MyStruct = undefined;
       ms.ptr = &ms;
       ms.addr = @ptrToInt(ms.ptr);
       return ms.ptr;

test "@noInlineCall on inline fn" {
    var ms = @noInlineCall(MyStruct.init); //Should cause compile error
    var x: usize = 1000;
    var y: usize = 1001;
    //Assuming stack grows downward.
    debug.assert(@ptrToInt(&y) < @ptrToInt(&x)); //Asserting assumption
    debug.assert(@ptrToInt(&x) > @ptrToInt(ms));

@andrewrk andrewrk added this to the 0.3.0 milestone Jun 18, 2018

@andrewrk andrewrk added the bug label Jun 18, 2018

@andrewrk andrewrk closed this in 869167f Sep 4, 2018


This comment has been minimized.


tgschultz commented Sep 14, 2018

I don't know why, but it occurred to me recently that maybe this should be the behavior. My reasoning being that the desired behavior at the call site should take priority over the declaration site. I don't have a use-case for this mind you, I just imagine that there might be a situation where someone almost always wants to inline a function.


This comment has been minimized.


andrewrk commented Sep 14, 2018

I think it's probably safe to keep this closed until somebody comes up with a use case for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment