@@ -173,7 +173,19 @@ class PrintMetadataSource
173173};
174174
175175Optional<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+
281297static std::pair<llvm::Constant *, unsigned >
282298getTypeRefImpl (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:
0 commit comments