Skip to content

SIL: More robust substituted function type lowering. #40112

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

jckarter
Copy link
Contributor

@jckarter jckarter commented Nov 9, 2021

This change separates out the formation of the generic signature and
substitutions for a SIL substituted function type as a pre-pass
before doing the actual function type lowering. The only input we
really need to form this signature is the original abstraction pattern
that a type is being lowered against, and pre-computing it should make
the code less side-effecty and confusing. It also allows us to handle
generic nominal types in a more robust way; we transfer over all of
the nominal type requirements to the generalized generic signature,
then when recursively visiting the bindings, we same-type-constrain
the generic parameters used in those requirements to the newly-generalized
generic arguments. This ensures that the minimized signature preserves
any non-trivial requirements imposed by the nominal type, such as
conditional conformances on its type arguments, same-type constraints
among associated types, etc.

This approach does lead to less-than-optimal generalized generic
signatures getting generated, since nominal type generic arguments
get same-type-bound either to other generic arguments or fixed to
concrete types almost always. It would be useful to do a minimization
pass on the final generic signature to eliminate these unnecessary
generic arguments, but that can be done in a follow-up PR.

Addresses rdar://84827656 | SR-15254

@jckarter jckarter force-pushed the subst-type-lowering-by-abstraction-pattern branch from 87516cf to b289847 Compare November 9, 2021 22:33
@jckarter
Copy link
Contributor Author

jckarter commented Nov 9, 2021

@swift-ci Please test

@jckarter
Copy link
Contributor Author

jckarter commented Nov 9, 2021

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Nov 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - b28984764cdf6ad08cdb34f40f8a39b9604c0945

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b28984764cdf6ad08cdb34f40f8a39b9604c0945

This change separates out the formation of the generic signature and
substitutions for a SIL substituted function type as a pre-pass
before doing the actual function type lowering. The only input we
really need to form this signature is the original abstraction pattern
that a type is being lowered against, and pre-computing it should make
the code less side-effecty and confusing. It also allows us to handle
generic nominal types in a more robust way; we transfer over all of
the nominal type requirements to the generalized generic signature,
then when recursively visiting the bindings, we same-type-constrain
the generic parameters used in those requirements to the newly-generalized
generic arguments. This ensures that the minimized signature preserves
any non-trivial requirements imposed by the nominal type, such as
conditional conformances on its type arguments, same-type constraints
among associated types, etc.

This approach does lead to less-than-optimal generalized generic
signatures getting generated, since nominal type generic arguments
get same-type-bound either to other generic arguments or fixed to
concrete types almost always. It would be useful to do a minimization
pass on the final generic signature to eliminate these unnecessary
generic arguments, but that can be done in a follow-up PR.
@jckarter jckarter force-pushed the subst-type-lowering-by-abstraction-pattern branch from b289847 to 5c404ac Compare November 10, 2021 20:48
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@jckarter
Copy link
Contributor Author

@swift-ci Please test source compatibility

@jckarter jckarter merged commit c45583a into swiftlang:main Nov 11, 2021
jckarter added a commit to jckarter/swift that referenced this pull request Nov 12, 2021
…ing.

To minimize unnecessary abstraction changes, we only want to represent
differences in types that provide interesting representation diversity,
such as between concrete function types with indirect arguments and
generic function types, but not so much between differently-generic
function types. The original subst function type lowering would
handle layout constraints by generalizing them to the most abstract
form that has a similar calling convention, such as
AnyObject -> _RefCountedObject. However, the new implementation
in swiftlang#40112 moved the generic signature formation for function types
earlier in the type lowering process, and much of type lowering was
unaware of layout constraints other than `requiresClass`, so I
backed off on that optimization to be able to land it. This
adds the optimization back, and generalizes type lowering in
other places to correctly handle other layout constraints.
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