Skip to content

[Mangling] Add a new mangling for opaque return type to use when mangling an ObjC runtime name #33035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ implementation details of a function type.
opaque-type-decl-name ::= entity 'QO' // opaque result type of specified decl
#endif

#if SWIFT_VERSION >= 5.4
type ::= 'Qu' // opaque result type (of current decl)
// used for ObjC class runtime name purposes.
#endif

Opaque return types have a special short representation in the mangling of
their defining entity. In structural position, opaque types are fully qualified
by mangling the defining entity for the opaque declaration and the substitutions
Expand Down
4 changes: 4 additions & 0 deletions lib/Demangling/OldDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,10 @@ class OldDemangler {
}
}
if (c == 'Q') {
if (Mangled.nextIf('u')) {
// Special mangling for opaque return type.
return Factory.createNode(Node::Kind::OpaqueReturnType);
}
return demangleArchetypeType();
}
if (c == 'q') {
Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ void Remangler::mangleSugaredParen(Node *node) {
}

void Remangler::mangleOpaqueReturnType(Node *node) {
unreachable("unsupported");
Buffer << "Qu";
}
void Remangler::mangleOpaqueReturnTypeOf(Node *node, EntityContext &ctx) {
unreachable("unsupported");
Expand Down
1 change: 1 addition & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ _$S3BBBBf0602365061_ ---> _$S3BBBBf0602365061_
_$S3BBBBi0602365061_ ---> _$S3BBBBi0602365061_
_$S3BBBBv0602365061_ ---> _$S3BBBBv0602365061_
_T0lxxxmmmTk ---> _T0lxxxmmmTk
_TtCF4test11doNotCrash1FT_QuL_8MyClass1 ---> MyClass1 #1 in test.doNotCrash1() -> some
$s4Test5ProtoP8IteratorV10collectionAEy_qd__Gqd___tcfc ---> Test.Proto.Iterator.init(collection: A1) -> Test.Proto.Iterator<A1>
$s4test3fooV4blahyAA1SV1fQryFQOy_Qo_AHF ---> test.foo.blah(<<opaque return type of test.S.f() -> some>>.0) -> <<opaque return type of test.S.f() -> some>>.0
$S3nix8MystructV1xACyxGx_tcfc7MyaliasL_ayx__GD ---> Myalias #1 in nix.Mystruct<A>.init(x: A) -> nix.Mystruct<A>
Expand Down
13 changes: 13 additions & 0 deletions validation-test/compiler_crashers_2_fixed/sr13203.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -o /dev/null %s

protocol MyProtocol {}

func doNotCrash1() -> some MyProtocol {
class MyClass1: MyProtocol {}
return MyClass1()
}

var doNotCrash2: some MyProtocol {
class MyClass2: MyProtocol {}
return MyClass2()
}