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

pure -> immutable fixes #3085

Merged
merged 5 commits into from Jan 26, 2014
Merged

Conversation

dnadlinger
Copy link
Member

https://d.puremagic.com/issues/show_bug.cgi?id=11503
https://d.puremagic.com/issues/show_bug.cgi?id=11909

The actual changes are in 3c0342e and ac4aed5, the rest are just cleanup commits.

@@ -616,7 +616,7 @@ Expression *CallExp::implicitCastTo(Scope *sc, Type *t)
* convert to immutable
*/
if (f && f->isolateReturn() &&
type->immutableOf()->equals(t->immutableOf()))
type->immutableOf()->equals(t))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beat me to it. :o)
That said, my fix was different. Are you sure the expressed goal of 'Avoid emitting CastExp' is still adequately met by the modified code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now removed the code altogether, see next commit.

@dnadlinger
Copy link
Member Author

Anybody knows what's up with Darwin_32? (Edit: There was a transitory failure, see https://d.puremagic.com/test-results/pull.ghtml?projectid=1&runid=858475.)

@dnadlinger
Copy link
Member Author

@andralex: That's the second part I was talking about before.

@dnadlinger
Copy link
Member Author

Note: Without the functionSemantic commit, the current Phobos build (i.e. without dlang/phobos#1852) segfaults. I didn't have time to find a reduced test case yet, but it is not related to the actual issues covered here.

@andralex
Copy link
Member

Unittests lgtm. Compiler experts, please review, thanks!

@dnadlinger
Copy link
Member Author

Regarding the tests: I find that squashing multiple failings tests into a single file using TEST_OUTPUT gets confusing rather quickly (e.g. like in fail_compilation/testInference, where similar passing and failing tests are mixed), but if the majority disagrees, I'd be happy to adapt them.

@yebblies
Copy link
Member

As the person who wrote the initial code for the conversion to immutable, it's both encouraging and troubling that I no longer understand how it works!

@9rnsr
Copy link
Contributor

9rnsr commented Jan 13, 2014

To: @klickverbot

Note: Without the functionSemantic commit, the current Phobos build (i.e. without dlang/phobos#1852) segfaults.

Maybe the ICE is related to bug 11822, bug 11850, 11857? If so, it is timely fixed by #3081 in git-head.

@9rnsr
Copy link
Contributor

9rnsr commented Jan 13, 2014

To fix issue 11503, we should disable immutable -> mutable conversion on pure return, but we should continue to enable mutable -> immutable conversion at the same place. So completely removing CallExp::implicitCastTo would be wrong.

On the other hand, fixing 11503 would break currently implemented unique constructor feature (#1726) so that it relies on the possibility of immutable to mutable conversion on pure constructor. That's why I'm proposing DIP53 before fixing the bug.

@dnadlinger
Copy link
Member Author

@9rnsr: Regarding CallExp::implicitCastTo, see the commit message – that case is handled in CallExp::implicitConvTo too.

Regarding unique constructors, all the current test cases still work. Specifically, I didn't touch the constructor conversion rules in functionResolve.

If you think that this breaks valid code, could you please provide a test case?

@dnadlinger
Copy link
Member Author

@yebblies: Better? ;)

@9rnsr
Copy link
Contributor

9rnsr commented Jan 13, 2014

CallExp::implicitCastTo is added by my refactoring #2702. See the reason comment in the function.

        /* Avoid emitting CastExp for:
         *  T[] make() pure { ...  }
         *  immutable T[] arr = make();  // unique return
         */

@dnadlinger
Copy link
Member Author

@9rnsr: Backed out the functionResolve change, as it indeed should be fixed by #3081. But regarding CallExp::implicitCastTo, if you don't agree with my analysis in the commit message, could you please be more specific as to why? The example from your comment doesn't produce a CastExp without the (horribly broken!) special case either.

@9rnsr
Copy link
Contributor

9rnsr commented Jan 13, 2014

@klickverbot In past, if CallExp::implicitCastTo does not exist, NRVO form detection in AssignExp::toElem was blocked by the redundant CastExp. If I remember correctly, bug 11394 test in runnable/inline.d is one of the cases.

@dnadlinger
Copy link
Member Author

@9rnsr: Well, that test case certainly seems to pass now. ;) If there is a way that Expression::implicitConvTo can find a different match that leads to a CastExp being emitted, I must have missed it.

@MartinNowak
Copy link
Member

Why the unrelated commits?

@dnadlinger
Copy link
Member Author

@MartinNowak: They are refactorings concerning same piece of code, and were made when I worked on the issue resp. add documentation to the original code in response to review comments. Just click on the individual commits to review them one by one. The changes are well-separated, so each commit itself should be almost trivial (except for the actual fixes, of course).

I could of course submit a pull request for each, but they would be interdependent, just making life harder for everyone. Just throwing everything into a single commit with the message "Issue 11503 - immutable return value from pure function implicitly converts to mutable." would of course also be an option. ;P

The pure -> immutable case is checked in implicitConvTo as well,
and since it yields MATCHexact, the castTo() in
Expression::implicitCastTo is a no-op anyway.
No functional change intended.
@dnadlinger
Copy link
Member Author

Ping?

@MartinNowak: I separated out the one hardly related commit into #3149. If it helps review, I can also split it up even further, but using the commit view things should be fairly clear…

@MartinNowak
Copy link
Member

Looks reasonable, but I didn't dig very deep into this.

MartinNowak added a commit that referenced this pull request Jan 26, 2014
@MartinNowak MartinNowak merged commit 01ca07b into dlang:master Jan 26, 2014
@dnadlinger dnadlinger deleted the pure-return-immutable branch January 26, 2014 21:51
@CyberShadow
Copy link
Member

This pull request introduced a regression: https://d.puremagic.com/issues/show_bug.cgi?id=12177

Sorry, I think that was a fluke.

@CyberShadow
Copy link
Member

This pull request may have introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=17635

@WalterBright
Copy link
Member

This function is utterly baffling to me, especially how it swaps source and target around, swaps ta and tb around independently, arggh.

The bug in it is it falsely returns true for ta = const(immutable(int)*) and tb = immutable(int)*. I don't know if it is a detail or the whole algorithm is wrong. @klickverbot can you please help?

@dnadlinger
Copy link
Member Author

@WalterBright: The code was originally written by Kenji – I just fixed some small bugs and made it moderately more legible. I'm having a quick look at the problem (and at cleaning up the source/target things) right now, though.

@andralex
Copy link
Member

andralex commented Oct 3, 2017

@klickverbot much appreciated!

@WalterBright
Copy link
Member

@klickverbot thanks for taking a look. I wrote this: #7179 and it now passes the test suite and the regression, but I am not terribly happy with it. I'd like a more understandable solution. For one thing it needs better comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants