Skip to content

Commit 3130c3c

Browse files
committed
AST: Remove an overload of GenericSignature::getSubstitutions()
1 parent 946b776 commit 3130c3c

File tree

8 files changed

+37
-58
lines changed

8 files changed

+37
-58
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,6 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
201201
Optional<ProtocolConformanceRef>
202202
lookupConformance(CanType depTy, ProtocolDecl *proto) const;
203203

204-
using GenericFunction = auto(CanType canType, Type conformingReplacementType,
205-
ProtocolType *conformedProtocol)
206-
->Optional<ProtocolConformanceRef>;
207-
using LookupConformanceFn = llvm::function_ref<GenericFunction>;
208-
209-
/// Build an array of substitutions from an interface type substitution map,
210-
/// using the given function to look up conformances.
211-
void getSubstitutions(TypeSubstitutionFn substitution,
212-
LookupConformanceFn lookupConformance,
213-
SmallVectorImpl<Substitution> &result) const;
214-
215204
/// Build an array of substitutions from an interface type substitution map,
216205
/// using the given function to look up conformances.
217206
void getSubstitutions(const SubstitutionMap &subMap,

lib/AST/GenericEnvironment.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,21 @@ Type GenericEnvironment::getSugaredType(Type type) const {
342342

343343
SubstitutionList
344344
GenericEnvironment::getForwardingSubstitutions() const {
345+
auto *genericSig = getGenericSignature();
346+
347+
SubstitutionMap subMap = genericSig->getSubstitutionMap(
348+
QueryInterfaceTypeSubstitutions(this),
349+
MakeAbstractConformanceForGenericType());
350+
345351
SmallVector<Substitution, 4> result;
346-
getGenericSignature()->getSubstitutions(QueryInterfaceTypeSubstitutions(this),
347-
MakeAbstractConformanceForGenericType(),
348-
result);
349-
return getGenericSignature()->getASTContext().AllocateCopy(result);
352+
genericSig->getSubstitutions(subMap, result);
353+
return genericSig->getASTContext().AllocateCopy(result);
350354
}
351355

352356
SubstitutionMap
353357
GenericEnvironment::
354358
getSubstitutionMap(TypeSubstitutionFn subs,
355-
GenericSignature::LookupConformanceFn lookupConformance) const {
359+
LookupConformanceFn lookupConformance) const {
356360
SubstitutionMap subMap(const_cast<GenericEnvironment *>(this));
357361

358362
getGenericSignature()->enumeratePairedRequirements(

lib/AST/GenericSignature.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ GenericSignature::getSubstitutionMap(SubstitutionList subs) const {
405405
SubstitutionMap
406406
GenericSignature::
407407
getSubstitutionMap(TypeSubstitutionFn subs,
408-
GenericSignature::LookupConformanceFn lookupConformance) const {
408+
LookupConformanceFn lookupConformance) const {
409409
SubstitutionMap subMap(const_cast<GenericSignature *>(this));
410410

411411
// Enumerate all of the requirements that require substitution.
@@ -437,33 +437,30 @@ getSubstitutionMap(TypeSubstitutionFn subs,
437437
}
438438

439439
void GenericSignature::
440-
getSubstitutions(TypeSubstitutionFn subs,
441-
GenericSignature::LookupConformanceFn lookupConformance,
440+
getSubstitutions(const SubstitutionMap &subMap,
442441
SmallVectorImpl<Substitution> &result) const {
443442

444443
// Enumerate all of the requirements that require substitution.
445444
enumeratePairedRequirements([&](Type depTy, ArrayRef<Requirement> reqs) {
446445
auto &ctx = getASTContext();
447446

448447
// Compute the replacement type.
449-
Type currentReplacement = depTy.subst(subs, lookupConformance);
448+
Type currentReplacement = depTy.subst(subMap);
450449
if (!currentReplacement)
451450
currentReplacement = ErrorType::get(depTy);
452451

453452
// Collect the conformances.
454453
SmallVector<ProtocolConformanceRef, 4> currentConformances;
455454
for (auto req: reqs) {
456455
assert(req.getKind() == RequirementKind::Conformance);
457-
auto protoType = req.getSecondType()->castTo<ProtocolType>();
458-
if (auto conformance = lookupConformance(depTy->getCanonicalType(),
459-
currentReplacement,
460-
protoType)) {
456+
auto protoDecl = req.getSecondType()->castTo<ProtocolType>()->getDecl();
457+
if (auto conformance = subMap.lookupConformance(depTy->getCanonicalType(),
458+
protoDecl)) {
461459
currentConformances.push_back(*conformance);
462460
} else {
463461
if (!currentReplacement->hasError())
464462
currentReplacement = ErrorType::get(currentReplacement);
465-
currentConformances.push_back(
466-
ProtocolConformanceRef(protoType->getDecl()));
463+
currentConformances.push_back(ProtocolConformanceRef(protoDecl));
467464
}
468465
}
469466

@@ -477,14 +474,6 @@ getSubstitutions(TypeSubstitutionFn subs,
477474
});
478475
}
479476

480-
void GenericSignature::
481-
getSubstitutions(const SubstitutionMap &subMap,
482-
SmallVectorImpl<Substitution> &result) const {
483-
getSubstitutions(QuerySubstitutionMap{subMap},
484-
LookUpConformanceInSubstitutionMap(subMap),
485-
result);
486-
}
487-
488477
bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
489478
if (!type->isTypeParameter()) return false;
490479

lib/SIL/TypeLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,17 +2518,17 @@ TypeConverter::getInterfaceBoxTypeForCapture(ValueDecl *captured,
25182518
SILField(loweredInterfaceType, isMutable));
25192519

25202520
// Instantiate the layout with identity substitutions.
2521-
SmallVector<Substitution, 4> genericArgs;
2522-
signature->getSubstitutions(
2523-
[&](SubstitutableType* type) -> Type {
2521+
auto subMap = signature->getSubstitutionMap(
2522+
[&](SubstitutableType *type) -> Type {
25242523
return signature->getCanonicalTypeInContext(type,
25252524
*M.getSwiftModule());
25262525
},
25272526
[](Type depTy, Type replacementTy, ProtocolType *conformedTy)
25282527
-> ProtocolConformanceRef {
25292528
return ProtocolConformanceRef(conformedTy->getDecl());
2530-
},
2531-
genericArgs);
2529+
});
2530+
SmallVector<Substitution, 4> genericArgs;
2531+
signature->getSubstitutions(subMap, genericArgs);
25322532

25332533
auto boxTy = SILBoxType::get(C, layout, genericArgs);
25342534
#ifndef NDEBUG

lib/SILGen/SILGenConstructor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,7 @@ void SILGenFunction::emitMemberInitializers(DeclContext *dc,
926926
// Generate a set of substitutions for the initialization function,
927927
// whose generic signature is that of the type context, and whose
928928
// replacement types are the archetypes of the initializer itself.
929-
SmallVector<Substitution, 4> subsVec;
930-
typeGenericSig->getSubstitutions(
929+
auto subMap = typeGenericSig->getSubstitutionMap(
931930
[&](SubstitutableType *type) {
932931
if (auto gp = type->getAs<GenericTypeParamType>()) {
933932
return genericEnv->mapTypeIntoContext(gp);
@@ -940,8 +939,9 @@ void SILGenFunction::emitMemberInitializers(DeclContext *dc,
940939
ProtocolType *conformedProtocol) {
941940
return ProtocolConformanceRef(
942941
conformedProtocol->getDecl());
943-
},
944-
subsVec);
942+
});
943+
SmallVector<Substitution, 4> subsVec;
944+
typeGenericSig->getSubstitutions(subMap, subsVec);
945945
subs = SGM.getASTContext().AllocateCopy(subsVec);
946946
}
947947

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,9 +1299,7 @@ FunctionSignaturePartialSpecializer::
12991299

13001300
void FunctionSignaturePartialSpecializer::computeClonerParamSubs(
13011301
SubstitutionList &ClonerParamSubs) {
1302-
SmallVector<Substitution, 4> List;
1303-
1304-
CalleeGenericSig->getSubstitutions(
1302+
auto SubMap = CalleeGenericSig->getSubstitutionMap(
13051303
[&](SubstitutableType *type) -> Type {
13061304
DEBUG(llvm::dbgs() << "\ngetSubstitution for ClonerParamSubs:\n"
13071305
<< Type(type) << "\n"
@@ -1312,8 +1310,10 @@ void FunctionSignaturePartialSpecializer::computeClonerParamSubs(
13121310
return SpecializedGenericEnv->mapTypeIntoContext(
13131311
SpecializedInterfaceTy);
13141312
},
1315-
LookUpConformanceInSignature(*SpecializedGenericSig), List);
1313+
LookUpConformanceInSignature(*SpecializedGenericSig));
13161314

1315+
SmallVector<Substitution, 4> List;
1316+
CalleeGenericSig->getSubstitutions(SubMap, List);
13171317
ClonerParamSubs = Ctx.AllocateCopy(List);
13181318
verifySubstitutionList(ClonerParamSubs, "ClonerParamSubs");
13191319
}

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ void Solution::computeSubstitutions(
9595
ConformanceCheckFlags::Used));
9696
};
9797

98-
sig->getSubstitutions(QueryTypeSubstitutionMap{subs},
99-
lookupConformanceFn, result);
98+
auto subMap = sig->getSubstitutionMap(
99+
QueryTypeSubstitutionMap{subs},
100+
lookupConformanceFn);
101+
102+
sig->getSubstitutions(subMap, result);
100103
}
101104

102105
void Solution::computeSubstitutions(

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,7 @@ Type TypeResolver::resolveSILBoxType(SILBoxTypeRepr *repr,
24792479
}
24802480

24812481
bool ok = true;
2482-
genericSig->getSubstitutions(
2482+
auto subMap = genericSig->getSubstitutionMap(
24832483
QueryTypeSubstitutionMap{genericArgMap},
24842484
[&](CanType depTy, Type replacement, ProtocolType *proto)
24852485
-> ProtocolConformanceRef {
@@ -2492,17 +2492,11 @@ Type TypeResolver::resolveSILBoxType(SILBoxTypeRepr *repr,
24922492
}
24932493

24942494
return *result;
2495-
},
2496-
genericArgs);
2495+
});
2496+
genericSig->getSubstitutions(subMap, genericArgs);
24972497

24982498
if (!ok)
24992499
return ErrorType::get(Context);
2500-
2501-
// Canonicalize the replacement types.
2502-
for (auto &arg : genericArgs) {
2503-
arg = Substitution(arg.getReplacement()->getCanonicalType(),
2504-
arg.getConformances());
2505-
}
25062500
}
25072501

25082502
auto layout = SILLayout::get(Context, genericSig, fields);

0 commit comments

Comments
 (0)