Skip to content

Commit 5a85c12

Browse files
authored
Merge pull request swiftlang#39497 from kavon/backdeploy-mangling-wip
2 parents e77b14a + 6739834 commit 5a85c12

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

@@ -278,6 +280,20 @@ getTypeRefByFunction(IRGenModule &IGM,
278280
return {constant, 6};
279281
}
280282

283+
bool swift::irgen::mangledNameIsUnknownToDeployTarget(IRGenModule &IGM,
284+
CanType type) {
285+
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget(
286+
IGM.Context.LangOpts.Target)) {
287+
if (auto minimumSupportedRuntimeVersion =
288+
getRuntimeVersionThatSupportsDemanglingType(type)) {
289+
if (*runtimeCompatVersion < *minimumSupportedRuntimeVersion) {
290+
return true;
291+
}
292+
}
293+
}
294+
return false;
295+
}
296+
281297
static std::pair<llvm::Constant *, unsigned>
282298
getTypeRefImpl(IRGenModule &IGM,
283299
CanType type,
@@ -294,16 +310,10 @@ getTypeRefImpl(IRGenModule &IGM,
294310
// If the minimum deployment target's runtime demangler wouldn't understand
295311
// this mangled name, then fall back to generating a "mangled name" with a
296312
// symbolic reference with a callback function.
297-
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget
298-
(IGM.Context.LangOpts.Target)) {
299-
if (auto minimumSupportedRuntimeVersion =
300-
getRuntimeVersionThatSupportsDemanglingType(type)) {
301-
if (*runtimeCompatVersion < *minimumSupportedRuntimeVersion) {
302-
return getTypeRefByFunction(IGM, sig, type);
303-
}
304-
}
313+
if (mangledNameIsUnknownToDeployTarget(IGM, type)) {
314+
return getTypeRefByFunction(IGM, sig, type);
305315
}
306-
316+
307317
break;
308318

309319
case MangledTypeRefRole::Reflection:

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,10 @@ class IRGenMangler : public Mangle::ASTMangler {
634634
}
635635
};
636636

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

642642
} // end namespace irgen
643643
} // 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)