fix handling of static impure functions nested in pure functions (issues 20047 and 20050)#10172
Conversation
…nter to impure static nested function
|
Thanks for your pull request and interest in making D better, @aG0aep6G! 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 references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#10172" |
|
I've tried to understand that code in the past and failed. It looks much more cleaner now. |
src/dmd/expression.d
Outdated
There was a problem hiding this comment.
please factor this out into a function, e.g:
if (!f.isPure() && checkPureCall(sc.func))
return true;
There was a problem hiding this comment.
please factor this out into a function
Done. I've called it checkImpure, though.
thewilsonator
left a comment
There was a problem hiding this comment.
Otherwise looks good.
|
|
||
| /* | ||
| Check if sc.func is impure or can be made impure. | ||
| Returns true on error, i.e. if sc.func is pure and cannot be made impure. |
There was a problem hiding this comment.
@aG0aep6G @thewilsonator when writing function comments, please use the Ddoc form.
Also, the function is not checking for an error, and it does more than check - it sets an impure state.
The phrase "cannot be made impure" makes little sense, as a pure function can always be called by an impure one.
There was a problem hiding this comment.
Also, the function is not checking for an error, and it does more than check - it sets an impure state.
How about:
/*********************************************
* Try marking sc.func as impure.
* Returns true if sc.func is pure and cannot be made impure.
*/
private static bool tryMakingImpure(Scope* sc) { ... }The phrase "cannot be made impure" makes little sense, as a pure function can always be called by an impure one.
This is about the case where a (pure) function tries calling an impure one. sc.func is the calling function, and we try to mark it as impure. But that might fail (because of an explicit pure attribute). In that case, sc.func "cannot be made impure". Makes sense?
There was a problem hiding this comment.
Or maybe this name and comment:
/*********************************************
* An impure function is called in sc. Propagate the impurity to the
* surrounding function (sc.func).
* Returns true if sc.func is pure and cannot be made impure.
*/
private static bool propagateImpure(Scope* sc)|
Great! I've tried to do something like this before but didn't get the test suite to pass. |
This is mostly deleting a bunch of code. As far as I can tell, it was all based on a wrong, overly complicated model of how things should work. But it's very possible that I'm missing crucial details.