Skip to content

[SILGen] Emit unreachable code diagnostic for single expression closures with implicit returns too #33604

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

Merged
merged 2 commits into from
Sep 21, 2020

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Aug 23, 2020

We don't emit unreachable code diagnostic for single expression closures if it has an implicit return. For example:

func map<T>(_ block: (Never) -> T) {}
map { _ in return 5 } // warning: will never be executed
map { _ in 5 } // no warning

This is because we skip implicit statements in SILGen if we encounter an unreachable location.

For implicit return statements in single expression closure or functions, the result expression is not implicit. So, let's use this knowledge to prevent skipping over the return statement.


Resolves SR-13432

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test macOS

@theblixguy
Copy link
Collaborator Author

Ping. @slavapestov @jckarter can you review? thanks!

@theblixguy
Copy link
Collaborator Author

Ping.

1 similar comment
@theblixguy
Copy link
Collaborator Author

Ping.

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy theblixguy merged commit 6ef4b0d into swiftlang:master Sep 21, 2020
@theblixguy theblixguy deleted the fix/SR-13432 branch September 21, 2020 20:58
ainu-bot pushed a commit to google/swift that referenced this pull request Sep 21, 2020
* 'master' of github.com:apple/swift:
  [SILGen] Emit unreachable code diagnostic for single expression closures with implicit returns too (swiftlang#33604)
  Resolve ASTScope Issues
  [NFC] Only Register Primaries As Dependency Sources
  Drop Legacy Tests
  Remove DependencyRecorder::Mode
  Remove appendHolderOfCascadingMembers
  Remove LegacyCascadingDependencies
  Remove Cascading Computations from ASTScope
  Remove unnecessary dependency sources
  Remove Reference::cascades
  Remove DependencyScope
  Remove evaluator::getScopeForAccessLevel
  Remove DeclContext::isCascadingContextForLookup
  Remove NLOptions::NL_Known*
  Remove NameLookupFlags::KnownPrivate
  Remove UnqualifiedLookupFlags::KnownPrivate
  Remove TypeResolutionFlags::KnownNonCascadingDependency
  [leaks-checker] Add verbose flag to dump out raw output from runtime to help debug failures on bots.
ainu-bot pushed a commit to google/swift that referenced this pull request Sep 21, 2020
* 'master' of github.com:apple/swift:
  [SILGen] Emit unreachable code diagnostic for single expression closures with implicit returns too (swiftlang#33604)
  Resolve ASTScope Issues
  [NFC] Only Register Primaries As Dependency Sources
  Drop Legacy Tests
  Remove DependencyRecorder::Mode
  Remove appendHolderOfCascadingMembers
  Remove LegacyCascadingDependencies
  Remove Cascading Computations from ASTScope
  Remove unnecessary dependency sources
  Remove Reference::cascades
  Remove DependencyScope
  Remove evaluator::getScopeForAccessLevel
  Remove DeclContext::isCascadingContextForLookup
  Remove NLOptions::NL_Known*
  Remove NameLookupFlags::KnownPrivate
  Remove UnqualifiedLookupFlags::KnownPrivate
  Remove TypeResolutionFlags::KnownNonCascadingDependency
  [leaks-checker] Add verbose flag to dump out raw output from runtime to help debug failures on bots.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants