mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -75,6 +75,14 @@ protected:
|
||||
/// If enabled, inverses will not be mangled into generic signatures.
|
||||
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
|
||||
/// 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
|
||||
|
||||
@@ -2063,7 +2063,8 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
|
||||
case SILFunctionTypeIsolation::Unknown:
|
||||
break;
|
||||
case SILFunctionTypeIsolation::Erased:
|
||||
OpArgs.push_back('A');
|
||||
if (AllowIsolatedAny)
|
||||
OpArgs.push_back('A');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3097,7 +3098,8 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
|
||||
appendOperator("Yc");
|
||||
break;
|
||||
case FunctionTypeIsolation::Kind::Erased:
|
||||
appendOperator("YA");
|
||||
if (AllowIsolatedAny)
|
||||
appendOperator("YA");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,10 +161,19 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
|
||||
ASTContext &ctx = Ty->getASTContext();
|
||||
llvm::SaveAndRestore<bool> savedConcurrencyStandardSubstitutions(
|
||||
AllowConcurrencyStandardSubstitutions);
|
||||
llvm::SaveAndRestore<bool> savedIsolatedAny(AllowIsolatedAny);
|
||||
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget(
|
||||
ctx.LangOpts.Target)) {
|
||||
if (*runtimeCompatVersion < llvm::VersionTuple(5, 5))
|
||||
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(
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
// REQUIRES: OS=macosx
|
||||
// UNSUPPORTED: CPU=arm64e
|
||||
|
||||
public struct MyStruct {
|
||||
let fn: @isolated(any) () -> ()
|
||||
}
|
||||
|
||||
// Make sure that we only emit a demangling-based type description
|
||||
// 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
|
||||
@@ -18,6 +14,22 @@ public struct MyStruct {
|
||||
// ordinary function type.
|
||||
// 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-PRESENT-SAME: ptr @"symbolic yyYAc"
|
||||
// CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.1"
|
||||
// CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.{{[0-9]+}}"
|
||||
|
||||
Reference in New Issue
Block a user