Skip to content

Commit 4555616

Browse files
authored
Merge pull request #81045 from slavapestov/fix-rdar149801864
Demangle: Implement missing Node::Kind::DependentProtocolConformanceOpaque
2 parents 4b7edce + 5e23a4c commit 4555616

File tree

9 files changed

+78
-0
lines changed

9 files changed

+78
-0
lines changed

include/swift/Demangling/DemangleNodes.def

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ NODE(DependentPseudogenericSignature)
7575
NODE(DependentProtocolConformanceRoot)
7676
NODE(DependentProtocolConformanceInherited)
7777
NODE(DependentProtocolConformanceAssociated)
78+
NODE(DependentProtocolConformanceOpaque)
7879
CONTEXT_NODE(Destructor)
7980
CONTEXT_NODE(DidSet)
8081
NODE(Directness)

include/swift/Demangling/Demangler.h

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ class Demangler : public NodeFactory {
596596
NodePointer demangleDependentProtocolConformanceInherited();
597597
NodePointer popDependentAssociatedConformance();
598598
NodePointer demangleDependentProtocolConformanceAssociated();
599+
NodePointer demangleDependentProtocolConformanceOpaque();
599600
NodePointer demangleThunkOrSpecialization();
600601
NodePointer demangleGenericSpecialization(Node::Kind SpecKind,
601602
NodePointer droppedArguments);

lib/Demangling/Demangler.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ NodePointer Demangler::demangleOperator() {
10421042
case 'C': return demangleConcreteProtocolConformance();
10431043
case 'D': return demangleDependentProtocolConformanceRoot();
10441044
case 'I': return demangleDependentProtocolConformanceInherited();
1045+
case 'O': return demangleDependentProtocolConformanceOpaque();
10451046
case 'P':
10461047
return createWithChild(
10471048
Node::Kind::ProtocolConformanceRefInTypeModule, popProtocol());
@@ -1961,6 +1962,7 @@ NodePointer Demangler::popAnyProtocolConformance() {
19611962
case Node::Kind::DependentProtocolConformanceRoot:
19621963
case Node::Kind::DependentProtocolConformanceInherited:
19631964
case Node::Kind::DependentProtocolConformanceAssociated:
1965+
case Node::Kind::DependentProtocolConformanceOpaque:
19641966
return true;
19651967

19661968
default:
@@ -2060,6 +2062,13 @@ NodePointer Demangler::demangleDependentConformanceIndex() {
20602062
return createNode(Node::Kind::Index, unsigned(index) - 2);
20612063
}
20622064

2065+
NodePointer Demangler::demangleDependentProtocolConformanceOpaque() {
2066+
NodePointer type = popNode(Node::Kind::Type);
2067+
NodePointer conformance = popDependentProtocolConformance();
2068+
return createWithChildren(Node::Kind::DependentProtocolConformanceOpaque,
2069+
conformance, type);
2070+
}
2071+
20632072
NodePointer Demangler::demangleRetroactiveConformance() {
20642073
NodePointer index = demangleIndexAsNode();
20652074
NodePointer conformance = popAnyProtocolConformance();

lib/Demangling/NodePrinter.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ class NodePrinter {
615615
case Node::Kind::DependentProtocolConformanceAssociated:
616616
case Node::Kind::DependentProtocolConformanceInherited:
617617
case Node::Kind::DependentProtocolConformanceRoot:
618+
case Node::Kind::DependentProtocolConformanceOpaque:
618619
case Node::Kind::ProtocolConformanceRefInTypeModule:
619620
case Node::Kind::ProtocolConformanceRefInProtocolModule:
620621
case Node::Kind::ProtocolConformanceRefInOtherModule:
@@ -3285,6 +3286,12 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
32853286
Printer << " to ";
32863287
print(Node->getChild(1), depth + 1);
32873288
return nullptr;
3289+
case Node::Kind::DependentProtocolConformanceOpaque:
3290+
Printer << "opaque result conformance ";
3291+
print(Node->getChild(0), depth + 1);
3292+
Printer << " of ";
3293+
print(Node->getChild(1), depth + 1);
3294+
return nullptr;
32883295
case Node::Kind::ProtocolConformanceRefInTypeModule:
32893296
Printer << "protocol conformance ref (type's module) ";
32903297
printChildren(Node, depth);

lib/Demangling/OldRemangler.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,13 @@ Remangler::mangleDependentProtocolConformanceAssociated(Node *node,
555555
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
556556
}
557557

558+
ManglingError
559+
Remangler::mangleDependentProtocolConformanceOpaque(Node *node,
560+
unsigned depth) {
561+
// Dependent conformances aren't in the old mangling
562+
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
563+
}
564+
558565
ManglingError Remangler::mangleProtocolConformance(Node *node, unsigned depth) {
559566
// type, protocol name, context
560567
DEMANGLER_ASSERT(node->getNumChildren() == 3, node);

lib/Demangling/Remangler.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,16 @@ ManglingError Remangler::mangleDependentConformanceIndex(Node *node,
27772777
return ManglingError::Success;
27782778
}
27792779

2780+
ManglingError Remangler::mangleDependentProtocolConformanceOpaque(Node *node,
2781+
unsigned depth) {
2782+
DEMANGLER_ASSERT(node->getKind() == Node::Kind::DependentProtocolConformanceOpaque,
2783+
node);
2784+
mangleAnyProtocolConformance(node->getChild(0), depth + 1);
2785+
mangleType(node->getChild(1), depth + 1);
2786+
Buffer << "HO";
2787+
return ManglingError::Success;
2788+
}
2789+
27802790
ManglingError Remangler::mangleAnyProtocolConformance(Node *node,
27812791
unsigned depth) {
27822792
switch (node->getKind()) {
@@ -2790,6 +2800,8 @@ ManglingError Remangler::mangleAnyProtocolConformance(Node *node,
27902800
return mangleDependentProtocolConformanceInherited(node, depth + 1);
27912801
case Node::Kind::DependentProtocolConformanceAssociated:
27922802
return mangleDependentProtocolConformanceAssociated(node, depth + 1);
2803+
case Node::Kind::DependentProtocolConformanceOpaque:
2804+
return mangleDependentProtocolConformanceOpaque(node, depth + 1);
27932805
default:
27942806
// Should this really succeed?!
27952807
return ManglingError::Success;

test/Demangle/Inputs/manglings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,4 @@ _$s15raw_identifiers0020pathfoo_yuEHaaCiJskayyF ---> raw_identifiers.`path://foo
497497
_$s15raw_identifiers10FontWeightO009_100_FpEpdyyFZ ---> static raw_identifiers.FontWeight.`100`() -> ()
498498
$s7Library1BC1iSivxTwd ---> default override of Library.B.i.modify2 : Swift.Int
499499
$s7Library1BC1iSivxTwdTwc ---> coro function pointer to default override of Library.B.i.modify2 : Swift.Int
500+
$s3use1xAA3OfPVy3lib1GVyAA1fQryFQOyQo_GAjE1PAAxAeKHD1_AIHO_HCg_Gvp ---> use.x : use.OfP<lib.G<<<opaque return type of use.f() -> some>>.0>>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public struct G<T> {
2+
public init(_: T) {}
3+
}
4+
5+
public protocol P {
6+
associatedtype A: P
7+
8+
func a() -> A
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/opaque_result_type_retroactive_other.swift -emit-module -emit-module-path %t/opaque_result_type_retroactive_other.swiftmodule
3+
// RUN: %target-swift-emit-silgen %s -I %t | %FileCheck %s
4+
5+
import opaque_result_type_retroactive_other
6+
7+
extension G: @retroactive P where T: P {
8+
public func a() -> T {
9+
fatalError()
10+
}
11+
}
12+
13+
public struct S: P {
14+
public func a() -> S {
15+
return self
16+
}
17+
}
18+
19+
public func f() -> some P {
20+
return S()
21+
}
22+
23+
public struct OfP<T: P> {
24+
public init(_: T) {}
25+
}
26+
27+
// CHECK-LABEL: sil_global @$s30opaque_result_type_retroactive1xAA3OfPVy0a1_b1_c1_D6_other1GVyAA1fQryFQOyQo_GAjE1PAAxAeKHD1_AIHO_HCg_Gvp
28+
public var x = OfP(G(f()))
29+
30+
// CHECK-LABEL: sil_global @$s30opaque_result_type_retroactive1yAA3OfPVy0a1_b1_c1_D6_other1GVyAA1fQryFQOyQo_1AAE1PPQxGAnekAxAeKHD1_AJQzAeKHA1_AMHO_HCg_Gvp
31+
public var y = OfP(G(f().a()))

0 commit comments

Comments
 (0)