@@ -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
@@ -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+
284300static std::pair<llvm::Constant *, unsigned >
285301getTypeRefImpl (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:
0 commit comments