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

Move fix Issue 12153 to frontend #4062

Merged
merged 1 commit into from
Feb 6, 2015
Merged

Move fix Issue 12153 to frontend #4062

merged 1 commit into from
Feb 6, 2015

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Oct 12, 2014

See #3285

Moves the fix into the front-end so everyone benefits.

NB: I haven't yet read any of the comments in that PR.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 12, 2014

Responding to comments in the other PR (From what I gather, Kenji did initially fix it in the frontend?)

This pull changes the behavior of the following code:

import core.stdc.stdio;

bool b;
int[3] x;
int[3] y;

void main()
{
    printf("%p\n", x.ptr);
    printf("%p\n", y.ptr);
    printf("%p\n", (b ? x : y)[].ptr);
}

With gdc and this PR, the behaviour in the above test doesn't change.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 12, 2014

Likewise this code samples does not change behaviour:

int[3] x;
const int[3] y = x;

Nor this:

import core.stdc.stdio;

bool b;
struct Copy
{
    Copy* slice() { return &this; }
}
Copy x;
Copy func()
{
    return x;
};

void main()
{
    printf("%p\n", (b ? func().slice : func().slice));
    printf("%p\n", (b ? func() : func()).slice);
}

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 12, 2014

Pinging @yebblies and @9rnsr - as you were involved in this first.

@yebblies
Copy link
Member

IIUC this implementing what I suggested in this comment but has no effect on my other concerns from that PR. I'll have to take another look because I can't remember how & and ?: are handled.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 13, 2014

IIUC this implementing what I suggested in this comment but has no effect on my other concerns from that PR.

Correct. Here, the transformation is done on the lhs of an AssignExp only.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 18, 2014

Have you had any time to mull over this?

@yebblies
Copy link
Member

Nope.

@yebblies
Copy link
Member

Shouldn't the condition be if (se->e1->type->toBaseType()->ty == Tsarray) instead of if (se->e1->op == TOKquestion)? Are then any cases other than slicing a static array (then assigning to it) that require a modifiable lvalue?

@9rnsr
Copy link
Contributor

9rnsr commented Oct 18, 2014

This change will introduce a regression with following case:

    int[1] i, j;
    bool b = true;
    int n = 0;
    (b ? i : j)[0..1][n..$] = [4];
    assert(i == [4]);

So the better code would be:

        // For conditional operator, both branches need conversion.
        SliceExp *se = (SliceExp *)e1;
        while (se->e1->op == TOKslice)
            se = (SliceExp *)se->e1;
        if (se->e1->type->toBasetype()->ty == Tsarray)
        {
            se->e1 = se->e1->modifiableLvalue(sc, e1);
            if (se->e1->op == TOKerror)
                return se->e1;
        }

Additionally, I'd keep the code in addressElem to make glue layer robust. Because the translation itself is still valid even if it would be a dead code.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 18, 2014

This change will introduce a regression with following case:

Fixed and added regression test.

Additionally, I'd keep the code in addressElem to make glue layer robust. Because the translation itself is still valid even if it would be a dead code.

That's fine, you understand it better than me.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 18, 2014

Are then any cases other than slicing a static array (then assigning to it) that require a modifiable lvalue?

Not that I can think off the top of my head.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 18, 2014

Shouldn't have blindly copied and pasted your proposed fix @9rnsr :)

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 18, 2014

Are then any cases other than slicing a static array (then assigning to it) that require a modifiable lvalue?

Not that I can think off the top of my head.

What you have to watch out for are operations that do not have any side-effects, but may still create a temporary. Conditional operators fall under this category.

@ibuclaw ibuclaw closed this Oct 18, 2014
@ibuclaw ibuclaw reopened this Oct 18, 2014
@ghost
Copy link

ghost commented Dec 6, 2014

Are we ok to go forward with this? @9rnsr @yebblies

@yebblies
Copy link
Member

yebblies commented Feb 6, 2015

Auto-merge toggled on

yebblies added a commit that referenced this pull request Feb 6, 2015
Move fix Issue 12153 to frontend
@yebblies yebblies merged commit e62c349 into dlang:master Feb 6, 2015
@ibuclaw ibuclaw deleted the fix12153 branch February 6, 2015 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants