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

CTFE: Fix binassign evaluation/load order #5966

Merged
merged 2 commits into from
Aug 1, 2016

Conversation

kinke
Copy link
Contributor

@kinke kinke commented Jul 24, 2016

... and add long overdue tests for binops and binassigns.

For binassigns, the lhs is firstly evaluated as lvalue, then the rhs is evaluated, and only then the lhs lvalue is loaded for the underlying binop's lhs. I.e., the rhs side effects are reflected in the binop's lhs.

CTFE used to incorrectly load the lhs before evaluating the rhs, diverging from runtime.

See ldc-developers/ldc#1617 and http://forum.dlang.org/thread/tpucyhjhiwkcxajuuzqg@forum.dlang.org, where @tgehr came up with this CTFE bug. Also pinging @ibuclaw.

... and add long overdue tests for binops and binassigns.

For binassigns, the lhs is firstly evaluated as lvalue, then the rhs is
evaluated, and only then the lhs lvalue is loaded for the underlying
binops' lhs. I.e., the rhs side effects are reflected in the binop's lhs.

CTFE used to incorrectly load the lhs before evaluating the rhs, diverging
from runtime.
@kinke
Copy link
Contributor Author

kinke commented Jul 24, 2016

Oh nice, so DMD seems to be plagued by ldc-developers/ldc#1327 too (edit: only when optimizing). Argh.

@kinke
Copy link
Contributor Author

kinke commented Jul 24, 2016

I created an issue for the other optimizer bug: https://issues.dlang.org/show_bug.cgi?id=16317

@kinke
Copy link
Contributor Author

kinke commented Jul 31, 2016

Pinging @yebblies and @klickverbot can't hurt.

@UplinkCoder
Copy link
Member

This does introduce difference behavior between runtime and CTFE correct ?

@kinke
Copy link
Contributor Author

kinke commented Aug 1, 2016

Nope this makes sure runtime and CTFE behave identically, see the tests.

@dnadlinger
Copy link
Member

Auto-merge toggled on

@dnadlinger
Copy link
Member

Auto-merge toggled off

@dnadlinger
Copy link
Member

Auto-merge toggled on

@UplinkCoder
Copy link
Member

UplinkCoder commented Mar 6, 2017

@klickverbot where is the rational as to what is the correct behavior ?
also having a fix-me comment in a unit-test is a nono.
Then again ... without this comment I would not have noticed that newCTFE actually has the same behavior as the runtime version.

@dnadlinger
Copy link
Member

See https://issues.dlang.org/show_bug.cgi?id=16317 for the FIXME comment, which is linked above. (It would have been better to include the bug id in the commit message or directly in the comment.)

And as for what is correct, see the other links in the PR description – in particular the NG discussion, which is short and unequivocal. dlang/dlang.org#1429 (which clarifies the spec) sadly fizzled out over a discussion about the best way to write down the semantics (but not the behaviour itself).

DMD has had a number of bugs in this area in the past, and this PR was on the tail end of a large change/fix of the behaviour. It is quite plausible that there are still inconsistencies, if that is why you are asking.

@kinke kinke deleted the binAssignFix branch March 6, 2017 09:02
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