Skip to content

Commit 83913d6

Browse files
authored
Merge pull request swiftlang#39513 from kavon/backdeploy-mangling-wip-5.5
2 parents 9face3d + affe337 commit 83913d6

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

lib/IRGen/GenReflection.cpp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,19 @@ class PrintMetadataSource
173173
};
174174

175175
Optional<llvm::VersionTuple>
176-
swift::irgen::getRuntimeVersionThatSupportsDemanglingType(CanType type) {
176+
getRuntimeVersionThatSupportsDemanglingType(CanType type) {
177+
// The Swift 5.5 runtime is the first version able to demangle types
178+
// related to concurrency.
179+
bool needsConcurrency = type.findIf([](CanType t) -> bool {
180+
if (auto fn = dyn_cast<AnyFunctionType>(t)) {
181+
return fn->isAsync() || fn->isSendable() || fn->hasGlobalActor();
182+
}
183+
return false;
184+
});
185+
if (needsConcurrency) {
186+
return llvm::VersionTuple(5, 5);
187+
}
188+
177189
// Associated types of opaque types weren't mangled in a usable form by the
178190
// Swift 5.1 runtime, so we needed to add a new mangling in 5.2.
179191
if (type->hasOpaqueArchetype()) {
@@ -192,16 +204,6 @@ swift::irgen::getRuntimeVersionThatSupportsDemanglingType(CanType type) {
192204
// involving them.
193205
}
194206

195-
bool needsConcurrency = type.findIf([](CanType t) -> bool {
196-
if (auto fn = dyn_cast<AnyFunctionType>(t)) {
197-
return fn->isAsync() || fn->isSendable() || fn->hasGlobalActor();
198-
}
199-
return false;
200-
});
201-
if (needsConcurrency) {
202-
return llvm::VersionTuple(5, 5);
203-
}
204-
205207
return None;
206208
}
207209

@@ -281,6 +283,20 @@ getTypeRefByFunction(IRGenModule &IGM,
281283
return {constant, 6};
282284
}
283285

286+
bool swift::irgen::mangledNameIsUnknownToDeployTarget(IRGenModule &IGM,
287+
CanType type) {
288+
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget(
289+
IGM.Context.LangOpts.Target)) {
290+
if (auto minimumSupportedRuntimeVersion =
291+
getRuntimeVersionThatSupportsDemanglingType(type)) {
292+
if (*runtimeCompatVersion < *minimumSupportedRuntimeVersion) {
293+
return true;
294+
}
295+
}
296+
}
297+
return false;
298+
}
299+
284300
static std::pair<llvm::Constant *, unsigned>
285301
getTypeRefImpl(IRGenModule &IGM,
286302
CanType type,
@@ -297,16 +313,10 @@ getTypeRefImpl(IRGenModule &IGM,
297313
// If the minimum deployment target's runtime demangler wouldn't understand
298314
// this mangled name, then fall back to generating a "mangled name" with a
299315
// symbolic reference with a callback function.
300-
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget
301-
(IGM.Context.LangOpts.Target)) {
302-
if (auto minimumSupportedRuntimeVersion =
303-
getRuntimeVersionThatSupportsDemanglingType(type)) {
304-
if (*runtimeCompatVersion < *minimumSupportedRuntimeVersion) {
305-
return getTypeRefByFunction(IGM, sig, type);
306-
}
307-
}
316+
if (mangledNameIsUnknownToDeployTarget(IGM, type)) {
317+
return getTypeRefByFunction(IGM, sig, type);
308318
}
309-
319+
310320
break;
311321

312322
case MangledTypeRefRole::Reflection:

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,10 @@ class IRGenMangler : public Mangle::ASTMangler {
641641
}
642642
};
643643

644-
/// Does this type require a special minimum Swift runtime version which
645-
/// supports demangling it?
646-
Optional<llvm::VersionTuple>
647-
getRuntimeVersionThatSupportsDemanglingType(CanType type);
644+
/// Determines if the minimum deployment target's runtime demangler will not
645+
/// understand the mangled name for the given type.
646+
/// \returns true iff the target's runtime does not understand the mangled name.
647+
bool mangledNameIsUnknownToDeployTarget(IRGenModule &IGM, CanType type);
648648

649649
} // end namespace irgen
650650
} // end namespace swift

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,11 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
24772477
// Never access by mangled name if we've been asked not to.
24782478
if (IGM.getOptions().DisableConcreteTypeMetadataMangledNameAccessors)
24792479
return false;
2480-
2480+
2481+
// Do not access by mangled name if the runtime won't understand it.
2482+
if (mangledNameIsUnknownToDeployTarget(IGM, type))
2483+
return false;
2484+
24812485
// A nongeneric nominal type with nontrivial metadata has an accessor
24822486
// already we can just call.
24832487
if (auto nom = dyn_cast<NominalType>(type)) {
@@ -2487,14 +2491,7 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
24872491
return false;
24882492
}
24892493
}
2490-
2491-
// The Swift 5.1 runtime fails to demangle associated types of opaque types.
2492-
if (auto minimumSwiftVersion =
2493-
getRuntimeVersionThatSupportsDemanglingType(type)) {
2494-
return IGM.getAvailabilityContext().isContainedIn(
2495-
IGM.Context.getSwift5PlusAvailability(*minimumSwiftVersion));
2496-
}
2497-
2494+
24982495
return true;
24992496

25002497
// The visitor below can be used to fine-tune a heuristic to decide whether

test/Interpreter/opaque_return_type_protocol_ext.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
// REQUIRES: executable_test
66

7-
// FIXME: Disabled because compilation is crashing in arm64e
8-
// REQUIRES: rdar60734429
9-
107
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
118
protocol P {
129
associatedtype AT

0 commit comments

Comments
 (0)