Skip to content

Commit bc0b884

Browse files
committed
Fix demangling of lifetime dependence when other function annotations like throws etc are present
It was demangled in the wrong order previously.
1 parent 60558f4 commit bc0b884

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ Types
727727
C-TYPE is mangled according to the Itanium ABI, and prefixed with the length.
728728
Non-ASCII identifiers are preserved as-is; we do not use Punycode.
729729

730-
function-signature ::= params-type params-type async? sendable? throws? differentiable? function-isolation? // results and parameters
730+
function-signature ::= params-type params-type async? sendable? throws? differentiable? function-isolation? self-lifetime-dependence? // results and parameters
731731

732732
params-type ::= type 'z'? 'h'? // tuple in case of multiple parameters or a single parameter with a single tuple type
733733
// with optional inout convention, shared convention. parameters don't have labels,

lib/Demangling/Demangler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ NodePointer Demangler::popFunctionType(Node::Kind kind, bool hasClangType) {
15601560
ClangType = demangleClangType();
15611561
}
15621562
addChild(FuncType, ClangType);
1563+
addChild(FuncType, popNode(Node::Kind::SelfLifetimeDependence));
15631564
addChild(FuncType, popNode(Node::Kind::GlobalActorFunctionType));
15641565
addChild(FuncType, popNode(Node::Kind::IsolatedAnyFunctionType));
15651566
addChild(FuncType, popNode(Node::Kind::TransferringResultFunctionType));
@@ -1570,7 +1571,6 @@ NodePointer Demangler::popFunctionType(Node::Kind kind, bool hasClangType) {
15701571
}));
15711572
addChild(FuncType, popNode(Node::Kind::ConcurrentFunctionType));
15721573
addChild(FuncType, popNode(Node::Kind::AsyncAnnotation));
1573-
addChild(FuncType, popNode(Node::Kind::SelfLifetimeDependence));
15741574

15751575
FuncType = addChild(FuncType, popFunctionParams(Node::Kind::ArgumentTuple));
15761576
FuncType = addChild(FuncType, popFunctionParams(Node::Kind::ReturnType));
@@ -1603,6 +1603,9 @@ NodePointer Demangler::popFunctionParamLabels(NodePointer Type) {
16031603
return nullptr;
16041604

16051605
unsigned FirstChildIdx = 0;
1606+
if (FuncType->getChild(FirstChildIdx)->getKind() ==
1607+
Node::Kind::SelfLifetimeDependence)
1608+
++FirstChildIdx;
16061609
if (FuncType->getChild(FirstChildIdx)->getKind()
16071610
== Node::Kind::GlobalActorFunctionType)
16081611
++FirstChildIdx;
@@ -1629,9 +1632,6 @@ NodePointer Demangler::popFunctionParamLabels(NodePointer Type) {
16291632
if (FuncType->getChild(FirstChildIdx)->getKind() ==
16301633
Node::Kind::ParamLifetimeDependence)
16311634
++FirstChildIdx;
1632-
if (FuncType->getChild(FirstChildIdx)->getKind() ==
1633-
Node::Kind::SelfLifetimeDependence)
1634-
++FirstChildIdx;
16351635
auto ParameterType = FuncType->getChild(FirstChildIdx);
16361636

16371637
assert(ParameterType->getKind() == Node::Kind::ArgumentTuple);

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ struct Wrapper : ~Escapable {
8282
self._view = view
8383
}
8484
// TODO: Investigate why it was mangled as Yli and not YLi before
85-
// CHECK: sil hidden @$s28implicit_lifetime_dependence7WrapperV8getView1AA10BufferViewVyYLiF : $@convention(method) (@guaranteed Wrapper) -> _inherit(0) @owned BufferView {
86-
borrowing func getView1() -> BufferView {
85+
// CHECK: sil hidden @$s28implicit_lifetime_dependence7WrapperV8getView1AA10BufferViewVyKYLiF : $@convention(method) (@guaranteed Wrapper) -> _inherit(0) (@owned BufferView, @error any Error) {
86+
borrowing func getView1() throws -> BufferView {
8787
return _view
8888
}
8989

90-
// CHECK:sil hidden @$s28implicit_lifetime_dependence7WrapperV8getView2AA10BufferViewVyYLiF : $@convention(method) (@owned Wrapper) -> _inherit(0) @owned BufferView {
91-
consuming func getView2() -> BufferView {
90+
// CHECK: sil hidden @$s28implicit_lifetime_dependence7WrapperV8getView2AA10BufferViewVyYaKYLiF : $@convention(method) @async (@owned Wrapper) -> _inherit(0) (@owned BufferView, @error any Error) {
91+
consuming func getView2() async throws -> BufferView {
9292
return _view
9393
}
9494
}

0 commit comments

Comments
 (0)