mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Simplify SubstitutionMap::get()
This commit is contained in:
@@ -104,6 +104,15 @@ public:
|
|||||||
ArrayRef<Type> replacementTypes,
|
ArrayRef<Type> replacementTypes,
|
||||||
LookupConformanceFn lookupConformance);
|
LookupConformanceFn lookupConformance);
|
||||||
|
|
||||||
|
/// Build a substitution map from the substitutions represented by
|
||||||
|
/// the given in-flight substitution.
|
||||||
|
///
|
||||||
|
/// This function should generally only be used by the substitution
|
||||||
|
/// subsystem.
|
||||||
|
static SubstitutionMap get(GenericSignature genericSig,
|
||||||
|
ArrayRef<Type> replacementTypes,
|
||||||
|
InFlightSubstitution &IFS);
|
||||||
|
|
||||||
/// Build a substitution map from the substitutions represented by
|
/// Build a substitution map from the substitutions represented by
|
||||||
/// the given in-flight substitution.
|
/// the given in-flight substitution.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -998,9 +998,7 @@ case TypeKind::Id:
|
|||||||
return subs;
|
return subs;
|
||||||
|
|
||||||
auto sig = subs.getGenericSignature();
|
auto sig = subs.getGenericSignature();
|
||||||
return SubstitutionMap::get(sig,
|
return SubstitutionMap::get(sig, newSubs, LookUpConformanceInModule());
|
||||||
QueryReplacementTypeArray{sig, newSubs},
|
|
||||||
LookUpConformanceInModule());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CanType transformSILField(CanType fieldTy, TypePosition pos) {
|
CanType transformSILField(CanType fieldTy, TypePosition pos) {
|
||||||
|
|||||||
@@ -168,9 +168,28 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
|||||||
SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
||||||
ArrayRef<Type> types,
|
ArrayRef<Type> types,
|
||||||
LookupConformanceFn lookupConformance) {
|
LookupConformanceFn lookupConformance) {
|
||||||
return get(genericSig,
|
QueryReplacementTypeArray subs{genericSig, types};
|
||||||
QueryReplacementTypeArray{genericSig, types},
|
InFlightSubstitution IFS(subs, lookupConformance, std::nullopt);
|
||||||
lookupConformance);
|
return get(genericSig, types, IFS);
|
||||||
|
}
|
||||||
|
|
||||||
|
SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
||||||
|
ArrayRef<Type> types,
|
||||||
|
InFlightSubstitution &IFS) {
|
||||||
|
// Form the stored conformances.
|
||||||
|
SmallVector<ProtocolConformanceRef, 4> conformances;
|
||||||
|
for (const auto &req : genericSig.getRequirements()) {
|
||||||
|
if (req.getKind() != RequirementKind::Conformance) continue;
|
||||||
|
|
||||||
|
CanType depTy = req.getFirstType()->getCanonicalType();
|
||||||
|
auto replacement = depTy.subst(IFS);
|
||||||
|
auto *proto = req.getProtocolDecl();
|
||||||
|
auto conformance = IFS.lookupConformance(depTy, replacement, proto,
|
||||||
|
/*level=*/0);
|
||||||
|
conformances.push_back(conformance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SubstitutionMap(genericSig, types, conformances);
|
||||||
}
|
}
|
||||||
|
|
||||||
SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
||||||
@@ -185,29 +204,17 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
|||||||
|
|
||||||
for (auto *gp : genericSig.getGenericParams()) {
|
for (auto *gp : genericSig.getGenericParams()) {
|
||||||
// Record the replacement.
|
// Record the replacement.
|
||||||
Type replacement = Type(gp).subst(IFS);
|
Type replacement = IFS.substType(gp, /*level=*/0);
|
||||||
|
if (!replacement)
|
||||||
assert((!replacement || replacement->hasError() ||
|
replacement = ErrorType::get(gp->getASTContext());
|
||||||
|
assert((replacement->hasError() ||
|
||||||
gp->isParameterPack() == replacement->is<PackType>()) &&
|
gp->isParameterPack() == replacement->is<PackType>()) &&
|
||||||
"replacement for pack parameter must be a pack type");
|
"replacement for pack parameter must be a pack type");
|
||||||
|
|
||||||
replacementTypes.push_back(replacement);
|
replacementTypes.push_back(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Form the stored conformances.
|
return SubstitutionMap::get(genericSig, replacementTypes, IFS);
|
||||||
SmallVector<ProtocolConformanceRef, 4> conformances;
|
|
||||||
for (const auto &req : genericSig.getRequirements()) {
|
|
||||||
if (req.getKind() != RequirementKind::Conformance) continue;
|
|
||||||
|
|
||||||
CanType depTy = req.getFirstType()->getCanonicalType();
|
|
||||||
auto replacement = depTy.subst(IFS);
|
|
||||||
auto *proto = req.getProtocolDecl();
|
|
||||||
auto conformance = IFS.lookupConformance(depTy, replacement, proto,
|
|
||||||
/*level=*/0);
|
|
||||||
conformances.push_back(conformance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SubstitutionMap(genericSig, replacementTypes, conformances);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Type SubstitutionMap::lookupSubstitution(GenericTypeParamType *genericParam) const {
|
Type SubstitutionMap::lookupSubstitution(GenericTypeParamType *genericParam) const {
|
||||||
|
|||||||
@@ -808,8 +808,7 @@ SubstitutionMap TypeBase::getContextSubstitutionMap() {
|
|||||||
std::reverse(replacementTypes.begin(), replacementTypes.end());
|
std::reverse(replacementTypes.begin(), replacementTypes.end());
|
||||||
|
|
||||||
auto subMap = SubstitutionMap::get(
|
auto subMap = SubstitutionMap::get(
|
||||||
genericSig,
|
genericSig, replacementTypes,
|
||||||
QueryReplacementTypeArray{genericSig, replacementTypes},
|
|
||||||
LookUpConformanceInModule());
|
LookUpConformanceInModule());
|
||||||
|
|
||||||
nominalTy->ContextSubMap = subMap;
|
nominalTy->ContextSubMap = subMap;
|
||||||
|
|||||||
Reference in New Issue
Block a user