Clean up GenericFunctionType substitution #80301
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GenericFunctionType::substGenericArgs()
didn't support parameter packs. This can be fixed by replacing the implementation with a much simpler one: we form a newFunctionType
by dropping the generic signature, and then we callsubst()
.Now, if
subst()
was called directly on aGenericFunctionType
, we would essentially do the same thing as above if the replacement types were not type parameters, and output aFunctionType
. If the substitution replaced type parameters with type parameters though, we would attempt to build a new generic signature, and output a newGenericFunctionType
. The way this was done wasn't really meaningful, except when the substitution map was the identity substitution map, in which case it did manage to rebuild the original signature.Since this is an ongoing source of confusion, clean it up by changing
subst()
to simply assert if the input is aGenericFunctionType
. Instead, callers must explicitly callsubstGenericArgs()
.A
GenericFunctionType
is really not like the other interface types at all; it is a closed term that can only contain type parameters of its own generic signature, while other interface types can contain free occurrences of arbitrary type parameters. Since Swift doesn't allow higher-rank polymorphism,GenericFunctionType
is not the type of a first-class value, so most callers ofsubst()
don't expect to see aGenericFunctionType
. In the few cases that do, we should be explicit about what we're doing.