Skip to content

AST: Change signature of LookupConformanceFn #81202

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 3 commits into from
May 1, 2025

Conversation

slavapestov
Copy link
Contributor

The primitive form of subst() takes a pair of callbacks, to substitute generic parameters and conformances, respectively. We then implement substitution of arbitrary types in terms of these callbacks.

The LookupConformanceFn callback used to take both the original type and the substituted type of the conformance, so to perform a substitution on a dependent member type T.[P]A, we would first recursively substitute T, and then invoke LookupConformanceFn with T, the substituted type for T, and P. This returns a conformance, and we then project the type witness for A to get the final result.

While LookUpConformanceInModule needs the substitutedT for example, LookUpConformanceInSubstitutionMap does not; it calls SubstitutionMap::lookupConformance(), which only needs the original T and the P. To avoid this unnecessary bit of computation in the common case where we're calling subst() with a pair of callbacks that look into a substitution map, let's change the callback's signature to receive the InFlightSubstitution & instead of the substituted T. The substituted type can then be recovered by calling subst(IFS) on the original type T.

Also, remove an ancient hack in SubstitutionMap::lookupConformance() that is no longer necessary, now that we track subject types in abstract conformances. Previously, if any of the steps in a conformance path were abstract, we would fall back to global conformance lookup here, because we didn't have enough information to proceed. We do now.

Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
The abstract conformance hack is no longer necessary, so now all of the
cases can all be handled by ProtocolConformanceRef::getAssociatedConformance(),
without having to dispatch on the conformance kind.
@slavapestov slavapestov force-pushed the lookup-conformance-fn branch from 10a5d02 to e3c8f42 Compare April 30, 2025 17:42
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit f5087c4 into swiftlang:main May 1, 2025
5 checks passed
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.

1 participant