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

fix noreturn/implicit discard check logic #23681

Merged
merged 5 commits into from
Jun 5, 2024
Merged

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Jun 4, 2024

fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677

The false positive in #23677 was caused by behavior in implicitlyDiscardable where only the last node of if/case/try etc expressions were considered, as in the final node of the final branch (in this case else). To fix this we use the same iteration in implicitlyDiscardable that we use in endsInNoReturn, with the difference that for an if/case/try statement to be implicitly discardable, all of its branches must be implicitly discardable. noreturn calls are also considered implicitly discardable for this reason, otherwise stuff like if true: discardableCall() else: error() doesn't compile.

However endsInNoReturn also had bugs, one where finally was considered in noreturn checking when it shouldn't, another where only nkIfStmt was checked and not nkIfExpr, and the node given for the error message was bad. So endsInNoReturn now skips over skipForDiscardable which no longer contains nkIfStmt/nkCaseStmt/nkTryStmt, stores the first encountered returning node in a var parameter for the error message, and handles finally and nkIfExpr.

Fixing #23677 already broke a line in syncio so some package code might be affected.

@Araq
Copy link
Member

Araq commented Jun 5, 2024

Superb work.

@Araq Araq merged commit 42e8472 into nim-lang:devel Jun 5, 2024
19 checks passed
Copy link
Contributor

github-actions bot commented Jun 5, 2024

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 42e8472

Hint: mm: orc; opt: speed; options: -d:release
178683 lines; 8.401s; 753.098MiB peakmem

@metagn metagn mentioned this pull request Jul 15, 2024
narimiran pushed a commit that referenced this pull request Aug 29, 2024
fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677

The false positive in #23677 was caused by behavior in
`implicitlyDiscardable` where only the last node of `if`/`case`/`try`
etc expressions were considered, as in the final node of the final
branch (in this case `else`). To fix this we use the same iteration in
`implicitlyDiscardable` that we use in `endsInNoReturn`, with the
difference that for an `if`/`case`/`try` statement to be implicitly
discardable, all of its branches must be implicitly discardable.
`noreturn` calls are also considered implicitly discardable for this
reason, otherwise stuff like `if true: discardableCall() else: error()`
doesn't compile.

However `endsInNoReturn` also had bugs, one where `finally` was
considered in noreturn checking when it shouldn't, another where only
`nkIfStmt` was checked and not `nkIfExpr`, and the node given for the
error message was bad. So `endsInNoReturn` now skips over
`skipForDiscardable` which no longer contains
`nkIfStmt`/`nkCaseStmt`/`nkTryStmt`, stores the first encountered
returning node in a var parameter for the error message, and handles
`finally` and `nkIfExpr`.

Fixing #23677 already broke a line in `syncio` so some package code
might be affected.

(cherry picked from commit 42e8472)
narimiran pushed a commit that referenced this pull request Aug 30, 2024
narimiran pushed a commit that referenced this pull request Aug 30, 2024
narimiran pushed a commit that referenced this pull request Aug 31, 2024
fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677

The false positive in #23677 was caused by behavior in
`implicitlyDiscardable` where only the last node of `if`/`case`/`try`
etc expressions were considered, as in the final node of the final
branch (in this case `else`). To fix this we use the same iteration in
`implicitlyDiscardable` that we use in `endsInNoReturn`, with the
difference that for an `if`/`case`/`try` statement to be implicitly
discardable, all of its branches must be implicitly discardable.
`noreturn` calls are also considered implicitly discardable for this
reason, otherwise stuff like `if true: discardableCall() else: error()`
doesn't compile.

However `endsInNoReturn` also had bugs, one where `finally` was
considered in noreturn checking when it shouldn't, another where only
`nkIfStmt` was checked and not `nkIfExpr`, and the node given for the
error message was bad. So `endsInNoReturn` now skips over
`skipForDiscardable` which no longer contains
`nkIfStmt`/`nkCaseStmt`/`nkTryStmt`, stores the first encountered
returning node in a var parameter for the error message, and handles
`finally` and `nkIfExpr`.

Fixing #23677 already broke a line in `syncio` so some package code
might be affected.

(cherry picked from commit 42e8472)
narimiran pushed a commit that referenced this pull request Aug 31, 2024
narimiran pushed a commit that referenced this pull request Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment