Allow _d_arrayappendT to call impure functions#3662
Allow _d_arrayappendT to call impure functions#3662teodutu wants to merge 1 commit intodlang:masterfrom
_d_arrayappendT to call impure functions#3662Conversation
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
|
Thanks for your pull request and interest in making D better, @teodutu! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + druntime#3662" |
|
Does this mean that currently a |
ibuclaw
left a comment
There was a problem hiding this comment.
Casting away impurity is the wrong approach.
No. The compiler still checks the purity of |
Then why does it need to fake purity, does |
|
@ibuclaw @dkorpel, I've updated the PR's description in the hope of better clarifying why it's needed. I expressed myself poorly that it's about Either way, this is a hack for a stop-gap solution, as the current templated hook still ends up calling the old |
|
@ibuclaw @dkorpel It all boils down to the fact that we want to allow |
|
If current code is using an invalid assumption by the compiler, it's best to fix that sooner rather than later. If we are going to allow purity violations, we must do so in a way that alerts the user of the error, and then we will deprecate and remove it. Unfortunately, it looks like you can't overload a function solely based on purity (which would make this easy). In this case, the compiler needs to help it by calling different hooks based on the context. Is this possible? Specifically, we need to print a deprecation message (along with where the function is called) in the case where:
|
Yes, it is possible for the compiler to call a different hook based on the purity of the current function context. I agree, that a pure implementation should be done instead that lives alongside the old impure one. Having a grep through the rest of core.lifetime, it's unfortunate that this style of subverting purity has made it's way into other hooks that have been "templatized". |
|
@teodutu is this still needed? |
The compiler will lower
a ~= bto an expression containing a call to_d_arrayappendT. The hook callscopyEmplace, which might be impure. This would have made_d_arrayappendTimpure as well.As
a ~= bis allowed inpurecontexts,_d_arrayappendTneeds to bepureas well. However, the current stop-gap implementations of_d_arrayappend{cTX,T}use mixins and still call the old_d_arrayappendcTXhook, which sometimes falsely make them impure. This is why the hook itself has to be declaredpure.But when
_d_arrayappendThas to call an impure postblit or copy ctor, for example, the impurity of the latter conflicts with the hooks purity. For this reason, this PR fakes the purity of_d_arrayappendTwhile allowing the functions it calls be impure. to be pure regardless of the purity ofcopyEmplace, by an indirect call and a forced cast. This is required by dlang/dmd#13495.