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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user