Skip to content

Commit a8a60dd

Browse files
authored
Merge pull request swiftlang#74917 from rjmccall/strip-isolated-any-reflection-metadata-6.0
[6.0] Suppress `@isolated(any)` in reflective metadata strings on old targets
2 parents 927f483 + dd59fa4 commit a8a60dd

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ class ASTMangler : public Mangler {
7575
/// If enabled, inverses will not be mangled into generic signatures.
7676
bool AllowInverses = true;
7777

78+
/// If enabled, @isolated(any) can be encoded in the mangled name.
79+
/// Suppressing type attributes this way is generally questionable ---
80+
/// for example, it does not interact properly with substitutions ---
81+
/// and should only be done in situations where it is just going to be
82+
/// interpreted as a type and the exact string value does not play
83+
/// a critical role.
84+
bool AllowIsolatedAny = true;
85+
7886
/// If enabled, declarations annotated with @_originallyDefinedIn are mangled
7987
/// as if they're part of their original module. Disabled for debug mangling,
8088
/// because lldb wants to find declarations in the modules they're currently

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,8 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
20562056
case SILFunctionTypeIsolation::Unknown:
20572057
break;
20582058
case SILFunctionTypeIsolation::Erased:
2059-
OpArgs.push_back('A');
2059+
if (AllowIsolatedAny)
2060+
OpArgs.push_back('A');
20602061
break;
20612062
}
20622063

@@ -3090,7 +3091,8 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
30903091
appendOperator("Yc");
30913092
break;
30923093
case FunctionTypeIsolation::Kind::Erased:
3093-
appendOperator("YA");
3094+
if (AllowIsolatedAny)
3095+
appendOperator("YA");
30943096
break;
30953097
}
30963098

lib/IRGen/IRGenMangler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,19 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
160160
ASTContext &ctx = Ty->getASTContext();
161161
llvm::SaveAndRestore<bool> savedConcurrencyStandardSubstitutions(
162162
AllowConcurrencyStandardSubstitutions);
163+
llvm::SaveAndRestore<bool> savedIsolatedAny(AllowIsolatedAny);
163164
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget(
164165
ctx.LangOpts.Target)) {
165166
if (*runtimeCompatVersion < llvm::VersionTuple(5, 5))
166167
AllowConcurrencyStandardSubstitutions = false;
168+
169+
// Suppress @isolated(any) if we're mangling for pre-6.0 runtimes.
170+
// This is unprincipled but, because of the restrictions in e.g.
171+
// mangledNameIsUnknownToDeployTarget, should only happen when
172+
// mangling for certain reflective uses where we have to hope that
173+
// the exact type identity is generally unimportant.
174+
if (*runtimeCompatVersion < llvm::VersionTuple(6, 0))
175+
AllowIsolatedAny = false;
167176
}
168177

169178
llvm::SaveAndRestore<bool> savedAllowStandardSubstitutions(

test/IRGen/reflection_metadata_isolated_any.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
// REQUIRES: OS=macosx
55
// UNSUPPORTED: CPU=arm64e
66

7-
public struct MyStruct {
8-
let fn: @isolated(any) () -> ()
9-
}
10-
117
// Make sure that we only emit a demangling-based type description
128
// for @isolated(any) types when deploying to runtimes that support it.
139
// If we don't, we fall back on using a type metadata accessor, which
@@ -18,6 +14,22 @@ public struct MyStruct {
1814
// ordinary function type.
1915
// rdar://129861211
2016

17+
// Closure capture metadata:
18+
19+
// CHECK-LABEL: @"\01l__swift5_reflection_descriptor" = private constant
20+
// CHECK-PRESENT-SAME: ptr @"symbolic SiIeAgd_"
21+
// CHECK-SUPPRESSED-SAME: ptr @"symbolic SiIegd_"
22+
// CHECK-LABEL: @metadata = private constant %swift.full_boxmetadata { {{.*}}, ptr @"\01l__swift5_reflection_descriptor" }, align
23+
func makeClosure(fn: @escaping @isolated(any) () -> Int) -> (() async -> Int) {
24+
return { await fn() + 1 }
25+
}
26+
27+
// Struct field metadata:
28+
29+
public struct MyStruct {
30+
let fn: @isolated(any) () -> ()
31+
}
32+
2133
// CHECK-LABEL: @"$s32reflection_metadata_isolated_any8MyStructVMF" = internal constant
2234
// CHECK-PRESENT-SAME: ptr @"symbolic yyYAc"
23-
// CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.1"
35+
// CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.{{[0-9]+}}"

0 commit comments

Comments
 (0)