Skip to content

[Sema] NFC: Simplify type coercion of ClosureExprs #12468

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

Conversation

davezarzycki
Copy link
Contributor

  • If we have an updatable ClosureExpr, then both fromEI.isAutoClosure() and toEI.isAutoClosure() must be false because the type system ensures that normal closures and functions do not convert to auto-closures.
  • If we have a throwing ClosureExpr, then fromEI.throws() and toEI.throws() must be true, otherwise an erroneous throwing to non-throwing closure/function conversions would be possible. From a different perspective, updating the 'throws' bit would make sense if overloading on 'throws' wasn't possible.

* If we have an updatable ClosureExpr, then both fromEI.isAutoClosure()
  and toEI.isAutoClosure() must be false because the type system ensures
  that normal closures and functions do not convert to auto-closures.
* If we have a throwing ClosureExpr, then fromEI.throws() and
  toEI.throws() must be true, otherwise an erroneous throwing to
  non-throwing closure/function conversions would be possible. From a
  different perspective, updating the 'throws' bit would make sense if
  overloading on 'throws' wasn't possible.
@davezarzycki
Copy link
Contributor Author

@swift-ci please test

@davezarzycki davezarzycki requested review from lattner and removed request for lattner October 16, 2017 20:51
@davezarzycki
Copy link
Contributor Author

Hi @lattner – Sorry for the stray click that turned into a GitHub review request. Carry on :-)

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Definitely a lot cleaner, thank you!

swift::AnyFunctionType::ExtInfo newEI(fromEI.getRepresentation(),
toEI.isAutoClosure(),
toEI.isNoEscape() | fromEI.isNoEscape(),
toEI.throws() & fromEI.throws());
Copy link
Member

Choose a reason for hiding this comment

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

This is such a weird computation. We take the "autoclosure" bit from the "to" type, "noescape" from either type (even though it's only on the "to" type based on the "if" statement above) and "throws" from both types (which makes no sense).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Don't forget that this goofiness only happened when the no escape bit and only the no escape bit needed propagating. Thanks for the review!

@davezarzycki davezarzycki merged commit a6444b2 into swiftlang:master Oct 16, 2017
@davezarzycki davezarzycki deleted the nfc_simplify_ClosureExpr_coercion branch October 16, 2017 23:19
@lattner
Copy link
Contributor

lattner commented Oct 17, 2017

nice patch @davezarzycki !

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.

3 participants