Skip to content

Commit 977b444

Browse files
committed
AST: Add a new overload of getContextSubstitutionMap()
1 parent 2adad14 commit 977b444

25 files changed

+54
-66
lines changed

include/swift/AST/Types.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,26 +1289,22 @@ class alignas(1 << TypeAlignInBits) TypeBase
12891289
/// Otherwise, it returns the type itself.
12901290
Type getReferenceStorageReferent();
12911291

1292-
/// Determine the set of substitutions that should be applied to a
1293-
/// type spelled within the given DeclContext to treat it as a
1294-
/// member of this type.
1292+
/// Assumes this is a nominal type. Returns a substitution map that sends each
1293+
/// generic parameter of the declaration's generic signature to the corresponding
1294+
/// generic argument of this nominal type.
12951295
///
1296-
/// For example, given:
1297-
/// \code
1298-
/// struct X<T, U> { }
1299-
/// extension X {
1300-
/// typealias SomeArray = [T]
1301-
/// }
1302-
/// \endcode
1296+
/// Eg: Array<Int> ---> { Element := Int }
1297+
SubstitutionMap getContextSubstitutionMap();
1298+
1299+
/// More general form of the above that handles additional cases:
13031300
///
1304-
/// Asking for the member substitutions of \c X<Int,String> within
1305-
/// the context of the extension above will produce substitutions T
1306-
/// -> Int and U -> String suitable for mapping the type of
1307-
/// \c SomeArray.
1301+
/// 1) dc is the nominal type itself or an unconstrained extension
1302+
/// 2) dc is a superclass
1303+
/// 3) dc is a protocol
13081304
///
1309-
/// \param genericEnv If non-null and the type is nested inside of a
1310-
/// generic function, generic parameters of the outer context are
1311-
/// mapped to context archetypes of this generic environment.
1305+
/// In Case 2) and 3), the substitution map has the generic signature of the dc,
1306+
/// and not the nominal. In Case 1), this is the same as the no-argument overload
1307+
/// of getContextSubstitutionMap().
13121308
SubstitutionMap getContextSubstitutionMap(const DeclContext *dc,
13131309
GenericEnvironment *genericEnv=nullptr);
13141310

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ void BridgedPassContext::loadFunction(BridgedFunction function, bool loadCallees
415415

416416
BridgedSubstitutionMap BridgedPassContext::getContextSubstitutionMap(BridgedType type) const {
417417
swift::SILType ty = type.unbridged();
418-
auto *ntd = ty.getASTType()->getAnyNominal();
419-
return ty.getASTType()->getContextSubstitutionMap(ntd);
418+
return ty.getASTType()->getContextSubstitutionMap();
420419
}
421420

422421
BridgedType BridgedPassContext::getBuiltinIntegerType(SwiftInt bitWidth) const {

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,10 +1976,9 @@ void ASTMangler::appendRetroactiveConformances(Type type, GenericSignature sig)
19761976
if (type->hasUnboundGenericType())
19771977
return;
19781978

1979-
auto nominal = type->getAnyNominal();
1980-
if (!nominal) return;
1979+
if (!type->getAnyNominal()) return;
19811980

1982-
subMap = type->getContextSubstitutionMap(nominal);
1981+
subMap = type->getContextSubstitutionMap();
19831982
}
19841983

19851984
appendRetroactiveConformances(subMap, sig);

lib/AST/Type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,8 +3043,7 @@ getForeignRepresentable(Type type, ForeignLanguage language,
30433043
auto specialized = type->getASTContext()
30443044
.getSpecializedConformance(type,
30453045
cast<NormalProtocolConformance>(result.getConformance()),
3046-
boundGenericType->getContextSubstitutionMap(
3047-
boundGenericType->getDecl()));
3046+
boundGenericType->getContextSubstitutionMap());
30483047
result = ForeignRepresentationInfo::forBridged(specialized);
30493048
}
30503049
}

lib/AST/TypeSubstitution.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,10 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
805805
return substitutions;
806806
}
807807

808+
SubstitutionMap TypeBase::getContextSubstitutionMap() {
809+
return getContextSubstitutionMap(getAnyNominal(), nullptr);
810+
}
811+
808812
SubstitutionMap TypeBase::getContextSubstitutionMap(
809813
const DeclContext *dc,
810814
GenericEnvironment *genericEnv) {

lib/IRGen/Fulfillment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ bool FulfillmentMap::searchNominalTypeMetadata(IRGenModule &IGM,
361361

362362
bool hadFulfillment = false;
363363

364-
auto subs = type->getContextSubstitutionMap(nominal);
364+
auto subs = type->getContextSubstitutionMap();
365365

366366
GenericTypeRequirements requirements(IGM, nominal);
367367

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4929,7 +4929,7 @@ namespace {
49294929
}
49304930

49314931
SubstitutionMap genericSubstitutions() {
4932-
return type->getContextSubstitutionMap(type->getAnyNominal());
4932+
return type->getContextSubstitutionMap();
49334933
}
49344934

49354935
MetadataTrailingFlags getTrailingFlags() {

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,7 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
29912991
GenericTypeRequirements requirements(IGF.IGM, nominal);
29922992
auto &requirement = requirements.getRequirements()[reqtIndex];
29932993

2994-
auto subs = sourceKey.Type->getContextSubstitutionMap(nominal);
2994+
auto subs = type->getContextSubstitutionMap();
29952995
auto sub = requirement.getTypeParameter().subst(subs)->getCanonicalType();
29962996

29972997
// In either case, we need to change the type.

lib/IRGen/GenRecord.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class RecordTypeInfoImpl : public Base,
209209
if (auto likeType = rawLayout->getResolvedScalarLikeType(structDecl)) {
210210
if (rawLayout->shouldMoveAsLikeType()) {
211211
auto astT = T.getASTType();
212-
auto subs = astT->getContextSubstitutionMap(structDecl);
212+
auto subs = astT->getContextSubstitutionMap();
213213
auto loweredLikeType = IGF.IGM.getLoweredType(likeType->subst(subs));
214214
auto &likeTypeInfo = IGF.IGM.getTypeInfo(loweredLikeType);
215215

@@ -286,7 +286,7 @@ class RecordTypeInfoImpl : public Base,
286286
if (auto likeType = rawLayout->getResolvedScalarLikeType(structDecl)) {
287287
if (rawLayout->shouldMoveAsLikeType()) {
288288
auto astT = T.getASTType();
289-
auto subs = astT->getContextSubstitutionMap(structDecl);
289+
auto subs = astT->getContextSubstitutionMap();
290290
auto loweredLikeType = IGF.IGM.getLoweredType(likeType->subst(subs));
291291
auto &likeTypeInfo = IGF.IGM.getTypeInfo(loweredLikeType);
292292

lib/IRGen/GenType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ static bool tryEmitDeinitCall(IRGenFunction &IGF,
29422942
&& !deinitTy->hasError()
29432943
&& "deinit should have only one parameter");
29442944

2945-
auto substitutions = ty->getContextSubstitutionMap(nominal);
2945+
auto substitutions = ty->getContextSubstitutionMap();
29462946

29472947
CalleeInfo info(deinitTy,
29482948
deinitTy->substGenericArgs(IGF.getSILModule(),

0 commit comments

Comments
 (0)