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

frame access regression #19631

Open
dlangBugzillaToGithub opened this issue Oct 20, 2019 · 1 comment
Open

frame access regression #19631

dlangBugzillaToGithub opened this issue Oct 20, 2019 · 1 comment
Labels
P1 Severity:Regression PRs that fix regressions

Comments

@dlangBugzillaToGithub
Copy link

John Colvin (@John-Colvin) reported this on 2019-10-20T20:56:51Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20308

CC List

Description

template OverloadSet(Args ...)
{
    static foreach (Arg; Args)
        alias overloads = Arg;
}

struct S(handlers ...)
{
    static struct HandlerGroup
    {
        static opCall(int a)
        {
            return OverloadSet!(handlers).overloads(a);
        }
    }

    static auto ref call(alias f)()
    {
		return f(HandlerGroup.init);
    }
}

void main()
{
	assert(
		S!((double z) => z, y => y)
			.call!(r => r(1))()
        == 1);
}

onlineapp.d(13): Error: static function onlineapp.main.S!(function (double z) => z, (y) => y).S.HandlerGroup.opCall cannot access frame of function D main
onlineapp.d(26): Error: template instance `onlineapp.main.S!(function (double z) => z, (y) => y)` error instantiating

The regression was introduced by https://github.com/dlang/dmd/pull/10214 and was released in 2.087.1
@dlangBugzillaToGithub
Copy link
Author

timon.gehr commented on 2019-12-13T01:45:19Z

Unfortunately the reason for this regression is that the bug I fixed was masking another unrelated bug. I.e., this is not my fault and I cannot fix it very easily. DMD doesn't know that your handler lambdas do not need a frame pointer at the time it checks for frame pointer accessibility. Due to the bug fixed in https://github.com/dlang/dmd/pull/10214, DMD used to think that the lambdas are not nested in a function.

The following workaround makes the code compile:

void main(){
    static handler0(double z){ return z; }
    static handler1(T)(T y){ return y; }
    assert(
        S!(handler0, handler1)
        .call!(r => r(1))()
    == 1);
}

This allows DMD to see that the handlers are static functions without analyzing their bodies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Severity:Regression PRs that fix regressions
Projects
None yet
Development

No branches or pull requests

1 participant