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,
|
||||
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
|
||||
/// the given in-flight substitution.
|
||||
///
|
||||
|
||||
@@ -998,9 +998,7 @@ case TypeKind::Id:
|
||||
return subs;
|
||||
|
||||
auto sig = subs.getGenericSignature();
|
||||
return SubstitutionMap::get(sig,
|
||||
QueryReplacementTypeArray{sig, newSubs},
|
||||
LookUpConformanceInModule());
|
||||
return SubstitutionMap::get(sig, newSubs, LookUpConformanceInModule());
|
||||
}
|
||||
|
||||
CanType transformSILField(CanType fieldTy, TypePosition pos) {
|
||||
|
||||
@@ -168,9 +168,28 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
||||
SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
||||
ArrayRef<Type> types,
|
||||
LookupConformanceFn lookupConformance) {
|
||||
return get(genericSig,
|
||||
QueryReplacementTypeArray{genericSig, types},
|
||||
lookupConformance);
|
||||
QueryReplacementTypeArray subs{genericSig, types};
|
||||
InFlightSubstitution IFS(subs, lookupConformance, std::nullopt);
|
||||
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,
|
||||
@@ -185,29 +204,17 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
|
||||
|
||||
for (auto *gp : genericSig.getGenericParams()) {
|
||||
// Record the replacement.
|
||||
Type replacement = Type(gp).subst(IFS);
|
||||
|
||||
assert((!replacement || replacement->hasError() ||
|
||||
Type replacement = IFS.substType(gp, /*level=*/0);
|
||||
if (!replacement)
|
||||
replacement = ErrorType::get(gp->getASTContext());
|
||||
assert((replacement->hasError() ||
|
||||
gp->isParameterPack() == replacement->is<PackType>()) &&
|
||||
"replacement for pack parameter must be a pack type");
|
||||
|
||||
replacementTypes.push_back(replacement);
|
||||
}
|
||||
|
||||
// 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, replacementTypes, conformances);
|
||||
return SubstitutionMap::get(genericSig, replacementTypes, IFS);
|
||||
}
|
||||
|
||||
Type SubstitutionMap::lookupSubstitution(GenericTypeParamType *genericParam) const {
|
||||
|
||||
@@ -808,8 +808,7 @@ SubstitutionMap TypeBase::getContextSubstitutionMap() {
|
||||
std::reverse(replacementTypes.begin(), replacementTypes.end());
|
||||
|
||||
auto subMap = SubstitutionMap::get(
|
||||
genericSig,
|
||||
QueryReplacementTypeArray{genericSig, replacementTypes},
|
||||
genericSig, replacementTypes,
|
||||
LookUpConformanceInModule());
|
||||
|
||||
nominalTy->ContextSubMap = subMap;
|
||||
|
||||
Reference in New Issue
Block a user