Merge pull request #74916 from rjmccall/strip-isolated-any-reflection-metadata

Suppress `@isolated(any)` in reflective metadata strings on old targets
This commit is contained in:
John McCall
2024-07-03 02:41:23 -04:00
committed by GitHub
4 changed files with 38 additions and 7 deletions

View File

@@ -75,6 +75,14 @@ protected:
/// If enabled, inverses will not be mangled into generic signatures. /// If enabled, inverses will not be mangled into generic signatures.
bool AllowInverses = true; bool AllowInverses = true;
/// If enabled, @isolated(any) can be encoded in the mangled name.
/// Suppressing type attributes this way is generally questionable ---
/// for example, it does not interact properly with substitutions ---
/// and should only be done in situations where it is just going to be
/// interpreted as a type and the exact string value does not play
/// a critical role.
bool AllowIsolatedAny = true;
/// If enabled, declarations annotated with @_originallyDefinedIn are mangled /// If enabled, declarations annotated with @_originallyDefinedIn are mangled
/// as if they're part of their original module. Disabled for debug mangling, /// as if they're part of their original module. Disabled for debug mangling,
/// because lldb wants to find declarations in the modules they're currently /// because lldb wants to find declarations in the modules they're currently

View File

@@ -2063,7 +2063,8 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
case SILFunctionTypeIsolation::Unknown: case SILFunctionTypeIsolation::Unknown:
break; break;
case SILFunctionTypeIsolation::Erased: case SILFunctionTypeIsolation::Erased:
OpArgs.push_back('A'); if (AllowIsolatedAny)
OpArgs.push_back('A');
break; break;
} }
@@ -3097,7 +3098,8 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
appendOperator("Yc"); appendOperator("Yc");
break; break;
case FunctionTypeIsolation::Kind::Erased: case FunctionTypeIsolation::Kind::Erased:
appendOperator("YA"); if (AllowIsolatedAny)
appendOperator("YA");
break; break;
} }

View File

@@ -161,10 +161,19 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
ASTContext &ctx = Ty->getASTContext(); ASTContext &ctx = Ty->getASTContext();
llvm::SaveAndRestore<bool> savedConcurrencyStandardSubstitutions( llvm::SaveAndRestore<bool> savedConcurrencyStandardSubstitutions(
AllowConcurrencyStandardSubstitutions); AllowConcurrencyStandardSubstitutions);
llvm::SaveAndRestore<bool> savedIsolatedAny(AllowIsolatedAny);
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget( if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget(
ctx.LangOpts.Target)) { ctx.LangOpts.Target)) {
if (*runtimeCompatVersion < llvm::VersionTuple(5, 5)) if (*runtimeCompatVersion < llvm::VersionTuple(5, 5))
AllowConcurrencyStandardSubstitutions = false; AllowConcurrencyStandardSubstitutions = false;
// Suppress @isolated(any) if we're mangling for pre-6.0 runtimes.
// This is unprincipled but, because of the restrictions in e.g.
// mangledNameIsUnknownToDeployTarget, should only happen when
// mangling for certain reflective uses where we have to hope that
// the exact type identity is generally unimportant.
if (*runtimeCompatVersion < llvm::VersionTuple(6, 0))
AllowIsolatedAny = false;
} }
llvm::SaveAndRestore<bool> savedAllowStandardSubstitutions( llvm::SaveAndRestore<bool> savedAllowStandardSubstitutions(

View File

@@ -4,10 +4,6 @@
// REQUIRES: OS=macosx // REQUIRES: OS=macosx
// UNSUPPORTED: CPU=arm64e // UNSUPPORTED: CPU=arm64e
public struct MyStruct {
let fn: @isolated(any) () -> ()
}
// Make sure that we only emit a demangling-based type description // Make sure that we only emit a demangling-based type description
// for @isolated(any) types when deploying to runtimes that support it. // for @isolated(any) types when deploying to runtimes that support it.
// If we don't, we fall back on using a type metadata accessor, which // If we don't, we fall back on using a type metadata accessor, which
@@ -18,6 +14,22 @@ public struct MyStruct {
// ordinary function type. // ordinary function type.
// rdar://129861211 // rdar://129861211
// Closure capture metadata:
// CHECK-LABEL: @"\01l__swift5_reflection_descriptor" = private constant
// CHECK-PRESENT-SAME: ptr @"symbolic SiIeAgd_"
// CHECK-SUPPRESSED-SAME: ptr @"symbolic SiIegd_"
// CHECK-LABEL: @metadata = private constant %swift.full_boxmetadata { {{.*}}, ptr @"\01l__swift5_reflection_descriptor" }, align
func makeClosure(fn: @escaping @isolated(any) () -> Int) -> (() async -> Int) {
return { await fn() + 1 }
}
// Struct field metadata:
public struct MyStruct {
let fn: @isolated(any) () -> ()
}
// CHECK-LABEL: @"$s32reflection_metadata_isolated_any8MyStructVMF" = internal constant // CHECK-LABEL: @"$s32reflection_metadata_isolated_any8MyStructVMF" = internal constant
// CHECK-PRESENT-SAME: ptr @"symbolic yyYAc" // CHECK-PRESENT-SAME: ptr @"symbolic yyYAc"
// CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.1" // CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.{{[0-9]+}}"