Skip to content

Commit 3502e07

Browse files
authored
[Mangling] Add a new mangling for opaque return type to use when mangling an ObjC runtime name (#33035)
* [Mangling] Add a new mangling to represent opaque return type for ObjC runtime name * [Docs] Add the new 'Qu' mangling to 'Mangling.rst' document * [Test] Update test invocation arguments
1 parent 9d8e41a commit 3502e07

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

docs/ABI/Mangling.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ implementation details of a function type.
655655
opaque-type-decl-name ::= entity 'QO' // opaque result type of specified decl
656656
#endif
657657

658+
#if SWIFT_VERSION >= 5.4
659+
type ::= 'Qu' // opaque result type (of current decl)
660+
// used for ObjC class runtime name purposes.
661+
#endif
662+
658663
Opaque return types have a special short representation in the mangling of
659664
their defining entity. In structural position, opaque types are fully qualified
660665
by mangling the defining entity for the opaque declaration and the substitutions

lib/Demangling/OldDemangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,10 @@ class OldDemangler {
20132013
}
20142014
}
20152015
if (c == 'Q') {
2016+
if (Mangled.nextIf('u')) {
2017+
// Special mangling for opaque return type.
2018+
return Factory.createNode(Node::Kind::OpaqueReturnType);
2019+
}
20162020
return demangleArchetypeType();
20172021
}
20182022
if (c == 'q') {

lib/Demangling/OldRemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ void Remangler::mangleSugaredParen(Node *node) {
21102110
}
21112111

21122112
void Remangler::mangleOpaqueReturnType(Node *node) {
2113-
unreachable("unsupported");
2113+
Buffer << "Qu";
21142114
}
21152115
void Remangler::mangleOpaqueReturnTypeOf(Node *node, EntityContext &ctx) {
21162116
unreachable("unsupported");

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ _$S3BBBBf0602365061_ ---> _$S3BBBBf0602365061_
329329
_$S3BBBBi0602365061_ ---> _$S3BBBBi0602365061_
330330
_$S3BBBBv0602365061_ ---> _$S3BBBBv0602365061_
331331
_T0lxxxmmmTk ---> _T0lxxxmmmTk
332+
_TtCF4test11doNotCrash1FT_QuL_8MyClass1 ---> MyClass1 #1 in test.doNotCrash1() -> some
332333
$s4Test5ProtoP8IteratorV10collectionAEy_qd__Gqd___tcfc ---> Test.Proto.Iterator.init(collection: A1) -> Test.Proto.Iterator<A1>
333334
$s4test3fooV4blahyAA1SV1fQryFQOy_Qo_AHF ---> test.foo.blah(<<opaque return type of test.S.f() -> some>>.0) -> <<opaque return type of test.S.f() -> some>>.0
334335
$S3nix8MystructV1xACyxGx_tcfc7MyaliasL_ayx__GD ---> Myalias #1 in nix.Mystruct<A>.init(x: A) -> nix.Mystruct<A>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -o /dev/null %s
2+
3+
protocol MyProtocol {}
4+
5+
func doNotCrash1() -> some MyProtocol {
6+
class MyClass1: MyProtocol {}
7+
return MyClass1()
8+
}
9+
10+
var doNotCrash2: some MyProtocol {
11+
class MyClass2: MyProtocol {}
12+
return MyClass2()
13+
}

0 commit comments

Comments
 (0)