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

DIP 1034: detect noreturn statements #12222

Merged
merged 1 commit into from
Feb 24, 2021
Merged

Conversation

WalterBright
Copy link
Member

Meaning we now get warnings for unreachable code.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12222"

Comment on lines +41 to +43
fail_compilation/warn12809.d(108): Warning: statement is not reachable
fail_compilation/warn12809.d(115): Warning: statement is not reachable
fail_compilation/warn12809.d(122): Warning: statement is not reachable
Copy link
Contributor

@12345swordy 12345swordy Feb 22, 2021

Choose a reason for hiding this comment

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

The warning message is too vague. How about "Warning: statement 'statement description' is not reachable"?

Copy link
Member Author

Choose a reason for hiding this comment

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

We've had that same message for many years. A better message would be off topic for this PR, but you can submit one that addresses that if you like.

@UplinkCoder
Copy link
Member

Could the error message be : statement is not reachable because 'foo' does not return?

@WalterBright
Copy link
Member Author

Could the error message be

That would require some complex modifications to the code, as that information is not collected by blockExit().

@Geod24
Copy link
Member

Geod24 commented Feb 23, 2021

The test cases raise the question of throwing. If we flag those statements as not reachable, does it mean that noreturn functions are implicitly nothrow ?

@12345swordy
Copy link
Contributor

12345swordy commented Feb 23, 2021

The test cases raise the question of throwing. If we flag those statements as not reachable, does it mean that noreturn functions are implicitly nothrow ?

That is a good question. However that shouldn't be the justification to stall this pr, as that would be better off discuss in the ng.

@Geod24
Copy link
Member

Geod24 commented Feb 24, 2021

However that shouldn't be the justification to stall this pr, as that would be better off discuss in the ng.

I disagree.

@12345swordy
Copy link
Contributor

12345swordy commented Feb 24, 2021

However that shouldn't be the justification to stall this pr, as that would be better off discuss in the ng.

I disagree.

What are you suggesting then? Making noreturn functions nothrow? In this PR?

@@ -107,6 +107,8 @@ int blockExit(Statement s, FuncDeclaration func, bool mustNotThrow)
return;
}
}
if (s.exp.type.toBasetype().isTypeNoreturn())
result = BE.halt;
if (canThrow(s.exp, func, mustNotThrow))
result |= BE.throw_;
Copy link
Member Author

Choose a reason for hiding this comment

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

@Geod24 line 113 answers your question.

@WalterBright
Copy link
Member Author

If we flag those statements as not reachable, does it mean that noreturn functions are implicitly nothrow ?

Throwing is orthogonal from returning, so no, noreturn does not imply nothrow. You can see that in the blockExit() code where throwing is "ORed" in.

Copy link
Member

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

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

Thanks. For some reason I got confused and was thinking of catch. It makes perfect sense now.

@Geod24 Geod24 merged commit 0fc1fc0 into dlang:master Feb 24, 2021
@WalterBright WalterBright deleted the expNoreturn branch February 24, 2021 02:54
@Geod24
Copy link
Member

Geod24 commented Feb 26, 2021

For reference: This was temporarily reverted in #12228 as it broke one project on Buildkite, and will be re-introduced soon.

@WalterBright
Copy link
Member Author

@Geod24 a better solution would be to change abort() from noreturn back to void, rather than stopping progress in implementing DIP1034.

@Geod24
Copy link
Member

Geod24 commented Feb 26, 2021

I just reverted the PR that caused the CI to go red, but point taken.
Note that this wouldn't have been a problem with a -preview switch, because this change is likely to break other people's code.

Geod24 pushed a commit to Geod24/dmd that referenced this pull request Feb 26, 2021
This re-introduce commit 0fc1fc0,
which was merged in dlang#12222 and subsequently reverted in commit
3c84532 (PR dlang#12228) as it broke
some projects on Buildkite. The project has had a new release,
so it should be safe to re-introduce.
dlang-bot pushed a commit that referenced this pull request Mar 1, 2021
This re-introduce commit 0fc1fc0,
which was merged in #12222 and subsequently reverted in commit
3c84532 (PR #12228) as it broke
some projects on Buildkite. The project has had a new release,
so it should be safe to re-introduce.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants