Skip to content

Conversation

jckarter
Copy link
Contributor

The upper bound on a nominal type's generic argument can have more requirements imposed on it than those written in the original nominal type's generic signature, depending on the requirements imposed on the nominal type itself, thanks to conditional conformances. IsBindableVisitor failed to take this into account when visiting the bindings of generic type arguments. This could cause Type::isBindableTo to provide a false positive for a substituted type that doesn't satisfy conditional conformances, but more importantly, SIL type lowering uses the same visitor to extract an upper bound generic signature for substituted SIL function types, and if it doesn't preserve requirements from conditional conformances on nominal types in that signature, it can end up building an incorrect substitution map. Fix this by passing down the upper bound from generic arguments even when visiting nominal types, and using those upper bounds to check for conditional conformances that add requirements to generic arguments while visiting them.

@jckarter jckarter requested a review from slavapestov August 20, 2021 18:14
In order to correctly handle upper bound requirements arising from conditional conformances,
we need to be able to ingest requirements introduced by conditional conformance extensions,
which means recursively visiting the parent is no longer possible to do cleanly. It is
simpler to substitute the generic type's entire generic context as a whole.
The upper bound on a nominal type's generic argument can have more requirements imposed on it than those written in the original nominal type's generic signature, depending on the requirements imposed on the nominal type itself, thanks to conditional conformances. IsBindableVisitor failed to take this into account when visiting the bindings of generic type arguments. This could cause Type::isBindableTo to provide a false positive for a substituted type that doesn't satisfy conditional conformances, but more importantly, SIL type lowering uses the same visitor to extract an upper bound generic signature for substituted SIL function types, and if it doesn't preserve requirements from conditional conformances on nominal types in that signature, it can end up building an incorrect substitution map. Fix this by passing down the upper bound from generic arguments even when visiting nominal types, and using those upper bounds to check for conditional conformances that add requirements to generic arguments while visiting them.
@jckarter jckarter force-pushed the subst-function-type-lowering-conditional-conformance branch from e4f13ec to db823e0 Compare September 13, 2021 17:00
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - db823e0

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - db823e0

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