Fix regression with deleted catch(Exception) block#23126
Conversation
|
Thanks for your pull request and interest in making D better, @adamdruppe! 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 + dmd#23126" |
|
Steve posted one in the linked thread. But first need to see if the old regression can be fixed without introducing new regressions. dmd can't build itself anymore here because nested recursive functions no longer are compatible with nothrow. (though i compiled a few of my programs with the change and there were no problems. it comes down to using |
|
looks like the build succeeds otherwise so added the test case now too. @schveiguy found an old issue #17906 that refers to this and the test case is something he reduced. im running some tests on the opend side too, it looks like a success there but there was obviously some divergence in the patch (the patch on opend was a one liner!) |
|
So this is a hacky whackamole fix rn because of that inferred thing. Make the test function a template and you get the same failure again. I think the real fix is more involved - it probably shouldn't use this same function for both cases of inference and catch elision. Other option is to skip the catch elision logic. It's probably not worth doing in the frontend anyway tbh. |
thewilsonator
left a comment
There was a problem hiding this comment.
otherwise looks good
| bool hasInferredAttributes() const; | ||
| bool hasInferredAttributes(bool v); |
There was a problem hiding this comment.
need to update frontend.h
There was a problem hiding this comment.
kinda nuts the CI checks the useless frontend.h but not the actually important declaration.h
|
but idk my problem is if i change the test to it still fails so i kinda wanna go with the other approach..... |
|
Here's the other approach I had in mind: We can merge one or the other. Or technically could merge both as they attack different parts of the problem, but I'll leave that for y'all to decide. That other approach i think is the one i'll ship with opend as I think I like it better..... |
I think it was introduced in 0be1f3d when you have a recursive function, it stops trying to see if it throws and thus incorrectly marks it as fallthrough. Then later, in statement semantic you get into this block: /* If the try body never throws, we can eliminate any catches * of recoverable exceptions. */ and it elides the whole catch block, which leads to bizarre runtime results. See https://forum.dlang.org/thread/qohwofoqnooswcbgyzja@forum.dlang.org
|
You shouldn't need a new field for this: |
|
nothrow is not in process at the time the function is called, indeed, nothrow is never in process in the test case added here, as attributes are not inferred there at all. It is looking at the try statement in complete isolation as part of TryCatchStatement early semantic, it removes part of the AST before even getting to inference. The reason the other PR fails the code looks like this: And because of it removing that catch branch entirely if it thinks the try part is nothrow, the |
I think it was introduced in 0be1f3d
when you have a recursive function, it stops trying to see if it throws and thus incorrectly marks it as fallthrough. Then later, in statement semantic you get into this block:
and it elides the whole catch block, which leads to bizarre runtime results.
See https://forum.dlang.org/thread/qohwofoqnooswcbgyzja@forum.dlang.org