Skip to content

Commit c3f7e85

Browse files
committed
Demangle: Add node for reabstraction thunk capturing DynamicSelfType
Also, NodePrinter was printing the 'from' and 'to' type backwards, so fix that.
1 parent 592e2f7 commit c3f7e85

File tree

8 files changed

+75
-54
lines changed

8 files changed

+75
-54
lines changed

docs/ABI/Mangling.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ types where the metadata itself has unknown layout.)
191191
global ::= global specialization // function specialization
192192
global ::= global 'Tm' // merged function
193193
global ::= entity // some identifiable thing
194-
global ::= type type generic-signature? 'T' REABSTRACT-THUNK-TYPE // reabstraction thunk helper function
194+
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
195+
global ::= from-type to-type self-type generic-signature? 'Ty' // reabstraction thunk with dynamic 'Self' capture
196+
global ::= from-type to-type generic-signature? 'Tr' // obsolete mangling for reabstraction thunk
195197
global ::= entity generic-signature? type type* 'TK' // key path getter
196198
global ::= entity generic-signature? type type* 'Tk' // key path setter
197199
global ::= type generic-signature 'TH' // key path equality
@@ -204,11 +206,11 @@ types where the metadata itself has unknown layout.)
204206
global ::= type assoc-type-list protocol 'TN' // default associated conformance witness accessor
205207
global ::= type protocol 'Tb' // base conformance descriptor
206208

207-
REABSTRACT-THUNK-TYPE ::= 'R' // reabstraction thunk helper function
208-
REABSTRACT-THUNK-TYPE ::= 'r' // reabstraction thunk
209+
REABSTRACT-THUNK-TYPE ::= 'R' // reabstraction thunk
210+
REABSTRACT-THUNK-TYPE ::= 'r' // reabstraction thunk (obsolete)
209211

210-
The types in a reabstraction thunk helper function are always non-polymorphic
211-
``<impl-function-type>`` types.
212+
The `from-type` and `to-type` in a reabstraction thunk helper function
213+
are always non-polymorphic ``<impl-function-type>`` types.
212214

213215
::
214216

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ NODE(ProtocolWitnessTableAccessor)
176176
NODE(ProtocolWitnessTablePattern)
177177
NODE(ReabstractionThunk)
178178
NODE(ReabstractionThunkHelper)
179+
NODE(ReabstractionThunkHelperWithSelf)
179180
CONTEXT_NODE(ReadAccessor)
180181
NODE(RelatedEntityDeclName)
181182
NODE(RetroactiveConformance)

lib/Demangling/Demangler.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,15 +2057,20 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
20572057
return createWithChild(Node::Kind::ProtocolSelfConformanceWitness,
20582058
popNode(isEntity));
20592059
case 'R':
2060-
case 'r': {
2061-
NodePointer Thunk = createNode(c == 'R' ?
2062-
Node::Kind::ReabstractionThunkHelper :
2063-
Node::Kind::ReabstractionThunk);
2060+
case 'r':
2061+
case 'y': {
2062+
Node::Kind kind;
2063+
if (c == 'R') kind = Node::Kind::ReabstractionThunkHelper;
2064+
else if (c == 'y') kind = Node::Kind::ReabstractionThunkHelperWithSelf;
2065+
else kind = Node::Kind::ReabstractionThunk;
2066+
NodePointer Thunk = createNode(kind);
20642067
if (NodePointer GenSig = popNode(Node::Kind::DependentGenericSignature))
20652068
addChild(Thunk, GenSig);
2066-
NodePointer Ty2 = popNode(Node::Kind::Type);
2067-
Thunk = addChild(Thunk, popNode(Node::Kind::Type));
2068-
return addChild(Thunk, Ty2);
2069+
if (kind == Node::Kind::ReabstractionThunkHelperWithSelf)
2070+
addChild(Thunk, popNode(Node::Kind::Type));
2071+
addChild(Thunk, popNode(Node::Kind::Type));
2072+
addChild(Thunk, popNode(Node::Kind::Type));
2073+
return Thunk;
20692074
}
20702075
case 'g':
20712076
return demangleGenericSpecialization(Node::Kind::GenericSpecialization);

lib/Demangling/NodePrinter.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ class NodePrinter {
435435
case Node::Kind::ProtocolWitnessTablePattern:
436436
case Node::Kind::ReabstractionThunk:
437437
case Node::Kind::ReabstractionThunkHelper:
438+
case Node::Kind::ReabstractionThunkHelperWithSelf:
438439
case Node::Kind::ReadAccessor:
439440
case Node::Kind::RelatedEntityDeclName:
440441
case Node::Kind::RetroactiveConformance:
@@ -1536,22 +1537,40 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
15361537
case Node::Kind::ReabstractionThunkHelper: {
15371538
if (Options.ShortenThunk) {
15381539
Printer << "thunk for ";
1539-
print(Node->getChild(Node->getNumChildren() - 2));
1540+
print(Node->getChild(Node->getNumChildren() - 1));
15401541
return nullptr;
15411542
}
15421543
Printer << "reabstraction thunk ";
15431544
if (Node->getKind() == Node::Kind::ReabstractionThunkHelper)
15441545
Printer << "helper ";
1545-
auto generics = getFirstChildOfKind(Node, Node::Kind::DependentGenericSignature);
1546-
assert(Node->getNumChildren() == 2 + unsigned(generics != nullptr));
1547-
if (generics) {
1546+
unsigned idx = 0;
1547+
if (Node->getNumChildren() == 3) {
1548+
auto generics = Node->getChild(0);
1549+
idx = 1;
1550+
print(generics);
1551+
Printer << " ";
1552+
}
1553+
Printer << "from ";
1554+
print(Node->getChild(idx + 1));
1555+
Printer << " to ";
1556+
print(Node->getChild(idx));
1557+
return nullptr;
1558+
}
1559+
case Node::Kind::ReabstractionThunkHelperWithSelf: {
1560+
Printer << "reabstraction thunk ";
1561+
unsigned idx = 0;
1562+
if (Node->getNumChildren() == 4) {
1563+
auto generics = Node->getChild(0);
1564+
idx = 1;
15481565
print(generics);
15491566
Printer << " ";
15501567
}
15511568
Printer << "from ";
1552-
print(Node->getChild(Node->getNumChildren() - 2));
1569+
print(Node->getChild(idx + 2));
15531570
Printer << " to ";
1554-
print(Node->getChild(Node->getNumChildren() - 1));
1571+
print(Node->getChild(idx + 1));
1572+
Printer << " self ";
1573+
print(Node->getChild(idx));
15551574
return nullptr;
15561575
}
15571576
case Node::Kind::MergedFunction:

lib/Demangling/OldRemangler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,15 @@ void Remangler::mangleBaseWitnessTableAccessor(Node *node) {
715715
}
716716

717717
void Remangler::mangleReabstractionThunkHelper(Node *node) {
718-
Buffer << "TR";
719-
if (node->getNumChildren() == 3) Buffer << 'G';
720-
mangleChildNodes(node); // generic signature?, type, type
718+
Buffer << "<reabstraction-thunk-helper>";
719+
}
720+
721+
void Remangler::mangleReabstractionThunkHelperWithSelf(Node *node) {
722+
Buffer << "<reabstraction-thunk-helper-with-self>";
721723
}
722724

723725
void Remangler::mangleReabstractionThunk(Node *node) {
724-
Buffer << "Tr";
725-
if (node->getNumChildren() == 3) Buffer << 'G';
726-
mangleChildNodes(node); // generic signature?, type, type
726+
Buffer << "<reabstraction-thunk>";
727727
}
728728

729729
void Remangler::mangleProtocolSelfConformanceWitness(Node *node) {

lib/Demangling/Remangler.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,27 +1856,20 @@ void Remangler::mangleProtocolWitnessTableAccessor(Node *node) {
18561856
}
18571857

18581858
void Remangler::mangleReabstractionThunk(Node *node) {
1859-
if (node->getNumChildren() == 3) {
1860-
mangleChildNode(node, 1); // type 1
1861-
mangleChildNode(node, 2); // type 2
1862-
mangleChildNode(node, 0); // generic signature
1863-
} else {
1864-
mangleChildNodes(node);
1865-
}
1859+
mangleChildNodesReversed(node);
18661860
Buffer << "Tr";
18671861
}
18681862

18691863
void Remangler::mangleReabstractionThunkHelper(Node *node) {
1870-
if (node->getNumChildren() == 3) {
1871-
mangleChildNode(node, 1); // type 1
1872-
mangleChildNode(node, 2); // type 2
1873-
mangleChildNode(node, 0); // generic signature
1874-
} else {
1875-
mangleChildNodes(node);
1876-
}
1864+
mangleChildNodesReversed(node);
18771865
Buffer << "TR";
18781866
}
18791867

1868+
void Remangler::mangleReabstractionThunkHelperWithSelf(Node *node) {
1869+
mangleChildNodesReversed(node);
1870+
Buffer << "Ty";
1871+
}
1872+
18801873
void Remangler::mangleReadAccessor(Node *node) {
18811874
mangleAbstractStorage(node->getFirstChild(), "r");
18821875
}

test/Demangle/Inputs/manglings.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ _TtGSaGSqC5sugar7MyClass__ ---> [sugar.MyClass?]
173173
_TtaC9typealias5DWARF9DIEOffset ---> typealias.DWARF.DIEOffset
174174
_Tta1t5Alias ---> t.Alias
175175
_Ttas3Int ---> Swift.Int
176-
_TTRXFo_dSc_dSb_XFo_iSc_iSb_ ---> reabstraction thunk helper from @callee_owned (@unowned Swift.UnicodeScalar) -> (@unowned Swift.Bool) to @callee_owned (@in Swift.UnicodeScalar) -> (@out Swift.Bool)
177-
_TTRXFo_dSi_dGSqSi__XFo_iSi_iGSqSi__ ---> reabstraction thunk helper from @callee_owned (@unowned Swift.Int) -> (@unowned Swift.Int?) to @callee_owned (@in Swift.Int) -> (@out Swift.Int?)
178-
_TTRGrXFo_iV18switch_abstraction1A_ix_XFo_dS0__ix_ ---> reabstraction thunk helper <A> from @callee_owned (@in switch_abstraction.A) -> (@out A) to @callee_owned (@unowned switch_abstraction.A) -> (@out A)
176+
_TTRXFo_dSc_dSb_XFo_iSc_iSb_ ---> reabstraction thunk helper from @callee_owned (@in Swift.UnicodeScalar) -> (@out Swift.Bool) to @callee_owned (@unowned Swift.UnicodeScalar) -> (@unowned Swift.Bool)
177+
_TTRXFo_dSi_dGSqSi__XFo_iSi_iGSqSi__ ---> reabstraction thunk helper from @callee_owned (@in Swift.Int) -> (@out Swift.Int?) to @callee_owned (@unowned Swift.Int) -> (@unowned Swift.Int?)
178+
_TTRGrXFo_iV18switch_abstraction1A_ix_XFo_dS0__ix_ ---> reabstraction thunk helper <A> from @callee_owned (@unowned switch_abstraction.A) -> (@out A) to @callee_owned (@in switch_abstraction.A) -> (@out A)
179179
_TFCF5types1gFT1bSb_T_L0_10Collection3zimfT_T_ ---> zim() -> () in Collection #2 in types.g(b: Swift.Bool) -> ()
180180
_TFF17capture_promotion22test_capture_promotionFT_FT_SiU_FT_Si_promote0 ---> closure #1 () -> Swift.Int in capture_promotion.test_capture_promotion() -> () -> Swift.Int with unmangled suffix "_promote0"
181181
_TFIVs8_Processi10_argumentsGSaSS_U_FT_GSaSS_ ---> _arguments : [Swift.String] in variable initialization expression of Swift._Process with unmangled suffix "U_FT_GSaSS_"
@@ -200,8 +200,9 @@ _TTSgSiS_ ---> _TTSgSiS_
200200
_TTSgSi__xyz ---> _TTSgSi__xyz
201201
_TTSr5Si___TF4test7genericurFxx ---> generic not re-abstracted specialization <Swift.Int> of test.generic<A>(A) -> A
202202
_TTSrq5Si___TF4test7genericurFxx ---> generic not re-abstracted specialization <serialized, Swift.Int> of test.generic<A>(A) -> A
203-
_TPA__TTRXFo_oSSoSS_dSb_XFo_iSSiSS_dSb_ ---> {T:_TTRXFo_oSSoSS_dSb_XFo_iSSiSS_dSb_} partial apply forwarder for reabstraction thunk helper from @callee_owned (@owned Swift.String, @owned Swift.String) -> (@unowned Swift.Bool) to @callee_owned (@in Swift.String, @in Swift.String) -> (@unowned Swift.Bool)
204-
_TPAo__TTRGrXFo_dGSPx__dGSPx_zoPs5Error__XFo_iGSPx__iGSPx_zoPS___ ---> {T:_TTRGrXFo_dGSPx__dGSPx_zoPs5Error__XFo_iGSPx__iGSPx_zoPS___} partial apply ObjC forwarder for reabstraction thunk helper <A> from @callee_owned (@unowned Swift.UnsafePointer<A>) -> (@unowned Swift.UnsafePointer<A>, @error @owned Swift.Error) to @callee_owned (@in Swift.UnsafePointer<A>) -> (@out Swift.UnsafePointer<A>, @error @owned Swift.Error)
203+
_TPA__TTRXFo_oSSoSS_dSb_XFo_iSSiSS_dSb_ ---> {T:_TTRXFo_oSSoSS_dSb_XFo_iSSiSS_dSb_} partial apply forwarder for reabstraction thunk helper from @callee_owned (@in Swift.String, @in Swift.String) -> (@unowned Swift.Bool) to @callee_owned (@owned Swift.String, @owned Swift.String) -> (@unowned Swift.Bool)
204+
to @callee_owned (@in Swift.String, @in Swift.String) -> (@unowned Swift.Bool)
205+
_TPAo__TTRGrXFo_dGSPx__dGSPx_zoPs5Error__XFo_iGSPx__iGSPx_zoPS___ ---> {T:_TTRGrXFo_dGSPx__dGSPx_zoPs5Error__XFo_iGSPx__iGSPx_zoPS___} partial apply ObjC forwarder for reabstraction thunk helper <A> from @callee_owned (@in Swift.UnsafePointer<A>) -> (@out Swift.UnsafePointer<A>, @error @owned Swift.Error) to @callee_owned (@unowned Swift.UnsafePointer<A>) -> (@unowned Swift.UnsafePointer<A>, @error @owned Swift.Error)
205206
_T0S2SSbIxxxd_S2SSbIxiid_TRTA ---> {T:_T0S2SSbIxxxd_S2SSbIxiid_TR} partial apply forwarder for reabstraction thunk helper from @callee_owned (@owned Swift.String, @owned Swift.String) -> (@unowned Swift.Bool) to @callee_owned (@in Swift.String, @in Swift.String) -> (@unowned Swift.Bool)
206207
_T0SPyxGAAs5Error_pIxydzo_A2AsAB_pIxirzo_lTRTa ---> {T:_T0SPyxGAAs5Error_pIxydzo_A2AsAB_pIxirzo_lTR} partial apply ObjC forwarder for reabstraction thunk helper <A> from @callee_owned (@unowned Swift.UnsafePointer<A>) -> (@unowned Swift.UnsafePointer<A>, @error @owned Swift.Error) to @callee_owned (@in Swift.UnsafePointer<A>) -> (@out Swift.UnsafePointer<A>, @error @owned Swift.Error)
207208
_TiC4Meow5MyCls9subscriptFT1iSi_Sf ---> Meow.MyCls.subscript(i: Swift.Int) -> Swift.Float
@@ -223,8 +224,8 @@ _TTSf1cl35_TFF7specgen6callerFSiT_U_FTSiSi_T_Si___TF7specgen12take_closureFFTSiS
223224
_TTSfq1cl35_TFF7specgen6callerFSiT_U_FTSiSi_T_Si___TF7specgen12take_closureFFTSiSi_T_T_ ---> function signature specialization <serialized, Arg[0] = [Closure Propagated : closure #1 (Swift.Int, Swift.Int) -> () in specgen.caller(Swift.Int) -> (), Argument Types : [Swift.Int]> of specgen.take_closure((Swift.Int, Swift.Int) -> ()) -> ()
224225
_TTSf1cl35_TFF7specgen6callerFSiT_U_FTSiSi_T_Si___TTSg5Si___TF7specgen12take_closureFFTSiSi_T_T_ ---> function signature specialization <Arg[0] = [Closure Propagated : closure #1 (Swift.Int, Swift.Int) -> () in specgen.caller(Swift.Int) -> (), Argument Types : [Swift.Int]> of generic specialization <Swift.Int> of specgen.take_closure((Swift.Int, Swift.Int) -> ()) -> ()
225226
_TTSg5Si___TTSf1cl35_TFF7specgen6callerFSiT_U_FTSiSi_T_Si___TF7specgen12take_closureFFTSiSi_T_T_ ---> generic specialization <Swift.Int> of function signature specialization <Arg[0] = [Closure Propagated : closure #1 (Swift.Int, Swift.Int) -> () in specgen.caller(Swift.Int) -> (), Argument Types : [Swift.Int]> of specgen.take_closure((Swift.Int, Swift.Int) -> ()) -> ()
226-
_TTSf1cpfr24_TF8capturep6helperFSiT__n___TTRXFo_dSi_dT__XFo_iSi_dT__ ---> function signature specialization <Arg[0] = [Constant Propagated Function : capturep.helper(Swift.Int) -> ()]> of reabstraction thunk helper from @callee_owned (@unowned Swift.Int) -> (@unowned ()) to @callee_owned (@in Swift.Int) -> (@unowned ())
227-
_TTSf1cpfr24_TF8capturep6helperFSiT__n___TTRXFo_dSi_DT__XFo_iSi_DT__ ---> function signature specialization <Arg[0] = [Constant Propagated Function : capturep.helper(Swift.Int) -> ()]> of reabstraction thunk helper from @callee_owned (@unowned Swift.Int) -> (@unowned_inner_pointer ()) to @callee_owned (@in Swift.Int) -> (@unowned_inner_pointer ())
227+
_TTSf1cpfr24_TF8capturep6helperFSiT__n___TTRXFo_dSi_dT__XFo_iSi_dT__ ---> function signature specialization <Arg[0] = [Constant Propagated Function : capturep.helper(Swift.Int) -> ()]> of reabstraction thunk helper from @callee_owned (@in Swift.Int) -> (@unowned ()) to @callee_owned (@unowned Swift.Int) -> (@unowned ())
228+
_TTSf1cpfr24_TF8capturep6helperFSiT__n___TTRXFo_dSi_DT__XFo_iSi_DT__ ---> function signature specialization <Arg[0] = [Constant Propagated Function : capturep.helper(Swift.Int) -> ()]> of reabstraction thunk helper from @callee_owned (@in Swift.Int) -> (@unowned_inner_pointer ()) to @callee_owned (@unowned Swift.Int) -> (@unowned_inner_pointer ())
228229
_TTSf1cpi0_cpfl0_cpse0v4u123_cpg53globalinit_33_06E7F1D906492AE070936A9B58CBAE1C_token8_cpfr36_TFtest_capture_propagation2_closure___TF7specgen12take_closureFFTSiSi_T_T_ ---> function signature specialization <Arg[0] = [Constant Propagated Integer : 0], Arg[1] = [Constant Propagated Float : 0], Arg[2] = [Constant Propagated String : u8'u123'], Arg[3] = [Constant Propagated Global : globalinit_33_06E7F1D906492AE070936A9B58CBAE1C_token8], Arg[4] = [Constant Propagated Function : _TFtest_capture_propagation2_closure]> of specgen.take_closure((Swift.Int, Swift.Int) -> ()) -> ()
229230
_TTSf0gs___TFVs17_LegacyStringCore15_invariantCheckfT_T_ ---> function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of Swift._LegacyStringCore._invariantCheck() -> ()
230231
_TTSf2g___TTSf2s_d___TFVs17_LegacyStringCoreCfVs13_StringBufferS_ ---> function signature specialization <Arg[0] = Owned To Guaranteed> of function signature specialization <Arg[0] = Exploded, Arg[1] = Dead> of Swift._LegacyStringCore.init(Swift._StringBuffer) -> Swift._LegacyStringCore
@@ -241,7 +242,7 @@ _TTWurGV23interface_type_mangling18GenericTypeContextx_S_18GenericWitnessTestS_F
241242
_TFC3red11BaseClassEHcfzT1aSi_S0_ ---> red.BaseClassEH.init(a: Swift.Int) throws -> red.BaseClassEH
242243
_TFe27mangling_generic_extensionsRxS_8RunciblerVS_3Foog1aSi ---> (extension in mangling_generic_extensions):mangling_generic_extensions.Foo<A where A: mangling_generic_extensions.Runcible>.a.getter : Swift.Int
243244
_TFe27mangling_generic_extensionsRxS_8RunciblerVS_3Foog1bx ---> (extension in mangling_generic_extensions):mangling_generic_extensions.Foo<A where A: mangling_generic_extensions.Runcible>.b.getter : A
244-
_TTRXFo_iT__iT_zoPs5Error__XFo__dT_zoPS___ ---> reabstraction thunk helper from @callee_owned (@in ()) -> (@out (), @error @owned Swift.Error) to @callee_owned () -> (@unowned (), @error @owned Swift.Error)
245+
_TTRXFo_iT__iT_zoPs5Error__XFo__dT_zoPS___ ---> reabstraction thunk helper from @callee_owned () -> (@unowned (), @error @owned Swift.Error) to @callee_owned (@in ()) -> (@out (), @error @owned Swift.Error)
245246
_TFE1a ---> _TFE1a
246247
_TF21$__lldb_module_for_E0au3$E0Ps5Error_ ---> $__lldb_module_for_E0.$E0.unsafeMutableAddressor : Swift.Error
247248
_TMps10Comparable ---> protocol descriptor for Swift.Comparable

0 commit comments

Comments
 (0)