Skip to content

[Conformance checking] Better handling of escaping function types #15350

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
Mar 19, 2018

Conversation

DougGregor
Copy link
Member

Improve our handling of (non-)escaping function types in conformance checking in two ways to tighten up type soundness:

  • Never infer a non-escaping function type as an associated type witness. In particular, when matching an associated type in a requirement to a potential witness with a noescape function type, adjust the function type to be escaping. This addresses a type soundness issue, where values of non-escaping function type could arbitrarily escape through type witnesses.
  • Allow a witness with a parameter of noescape function type match a requirement with a compatible escaping function type. While this limited form of witness covariance is generally a good idea, it is also necessary because closing the type soundness hole describe above would break some existing code.

Fixes rdar://problem/35297911

…pe ones.

When inferring an associated type witness by matching a function signature,
adjust non-escaping function types to escaping function types, because only
escaping function types could be written as explicit witnesses and
non-escaping function types are not permitted outside of function
parameters.

Addresses the first part of rdar://problem/35297911, eliminating the
type-soundness issue.
…g parameter

Extend protocol conformance checking to allow a requirement with an
escaping parameter (of function type) to be satisfied by a witness
with a corresponding non-escaping parameter. This limited form of
covariance was already supported by SILGen and is needed to address
the source-compatibility "regression" introduced by inferring escaping
function types for associated type witnesses. It's also obviously a
good idea :)

Fixes rdar://problem/35297911.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 49e089c into swiftlang:master Mar 19, 2018
@DougGregor DougGregor deleted the escaping-associated-types branch March 19, 2018 23:51
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