Skip to content

Commit 0ae86c9

Browse files
committed
IRGen: Backward-deploy fix using open-coded accessors.
If we mangled an opaque associated type while targeting an older OS, we can use a \9 accessor reference string to instantiate the associated type.
1 parent 6817c53 commit 0ae86c9

File tree

9 files changed

+228
-61
lines changed

9 files changed

+228
-61
lines changed

lib/Basic/Platform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple){
351351
if (Major == 10) {
352352
if (Minor <= 14) {
353353
return llvm::VersionTuple(5, 0);
354+
} else if (Minor <= 15) {
355+
return llvm::VersionTuple(5, 1);
354356
} else {
355357
return None;
356358
}
@@ -361,13 +363,17 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple){
361363
Triple.getiOSVersion(Major, Minor, Micro);
362364
if (Major <= 12) {
363365
return llvm::VersionTuple(5, 0);
366+
} else if (Major <= 13) {
367+
return llvm::VersionTuple(5, 1);
364368
} else {
365369
return None;
366370
}
367371
} else if (Triple.isWatchOS()) {
368372
Triple.getWatchOSVersion(Major, Minor, Micro);
369373
if (Major <= 5) {
370374
return llvm::VersionTuple(5, 0);
375+
} else if (Major <= 6) {
376+
return llvm::VersionTuple(5, 1);
371377
} else {
372378
return None;
373379
}

lib/IRGen/GenKeyPath.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,10 @@ getInitializerForComputedComponent(IRGenModule &IGM,
649649
}
650650

651651
static llvm::Constant *
652-
emitMetadataTypeRefForKeyPath(IRGenModule &IGM, CanType type) {
652+
emitMetadataTypeRefForKeyPath(IRGenModule &IGM, CanType type,
653+
CanGenericSignature sig) {
653654
// Produce a mangled name for the type.
654-
auto constant = IGM.getTypeRef(type, MangledTypeRefRole::Metadata).first;
655+
auto constant = IGM.getTypeRef(type, sig, MangledTypeRefRole::Metadata).first;
655656

656657
// Mask the bottom bit to tell the key path runtime this is a mangled name
657658
// rather than a direct reference.
@@ -837,6 +838,10 @@ emitKeyPathComponent(IRGenModule &IGM,
837838
SmallVector<llvm::Constant *, 4> externalSubArgs;
838839
auto componentSig = externalDecl->getInnermostDeclContext()
839840
->getGenericSignatureOfContext();
841+
842+
auto componentCanSig = componentSig
843+
? componentSig->getCanonicalSignature()
844+
: CanGenericSignature();
840845
auto subs = component.getExternalSubstitutions();
841846
if (!subs.empty()) {
842847
enumerateGenericSignatureRequirements(
@@ -847,7 +852,7 @@ emitKeyPathComponent(IRGenModule &IGM,
847852
if (!reqt.Protocol) {
848853
// Type requirement.
849854
externalSubArgs.push_back(
850-
emitMetadataTypeRefForKeyPath(IGM, substType));
855+
emitMetadataTypeRefForKeyPath(IGM, substType, componentCanSig));
851856
} else {
852857
// Protocol requirement.
853858
auto conformance = subs.lookupConformance(
@@ -1182,9 +1187,11 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
11821187
getAddrOfGenericEnvironment(pattern->getGenericSignature()));
11831188
// Store type references for the root and leaf.
11841189
fields.addRelativeAddress(
1185-
emitMetadataTypeRefForKeyPath(*this, rootTy));
1190+
emitMetadataTypeRefForKeyPath(*this, rootTy,
1191+
pattern->getGenericSignature()));
11861192
fields.addRelativeAddress(
1187-
emitMetadataTypeRefForKeyPath(*this, valueTy));
1193+
emitMetadataTypeRefForKeyPath(*this, valueTy,
1194+
pattern->getGenericSignature()));
11881195

11891196
// Add a pointer to the ObjC KVC compatibility string, if there is one, or
11901197
// null otherwise.
@@ -1238,7 +1245,9 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
12381245
// For all but the last component, we pack in the type of the component.
12391246
if (i + 1 != pattern->getComponents().size()) {
12401247
fields.addRelativeAddress(
1241-
emitMetadataTypeRefForKeyPath(*this, component.getComponentType()));
1248+
emitMetadataTypeRefForKeyPath(*this,
1249+
component.getComponentType(),
1250+
pattern->getGenericSignature()));
12421251
}
12431252
baseTy = component.getComponentType();
12441253
}

lib/IRGen/GenMeta.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,11 +1683,14 @@ namespace {
16831683
}
16841684

16851685
void addUnderlyingTypeAndConformances() {
1686+
auto sig = O->getOpaqueInterfaceGenericSignature()
1687+
? O->getOpaqueInterfaceGenericSignature()->getCanonicalSignature()
1688+
: CanGenericSignature();
16861689
auto underlyingType = Type(O->getUnderlyingInterfaceType())
16871690
.subst(*O->getUnderlyingTypeSubstitutions())
1688-
->getCanonicalType(O->getOpaqueInterfaceGenericSignature());
1691+
->getCanonicalType(sig);
16891692

1690-
B.addRelativeAddress(IGM.getTypeRef(underlyingType,
1693+
B.addRelativeAddress(IGM.getTypeRef(underlyingType, sig,
16911694
MangledTypeRefRole::Metadata).first);
16921695

16931696
auto opaqueType = O->getDeclaredInterfaceType()

0 commit comments

Comments
 (0)