Skip to content

[6.2] Demangle: Implement missing Node::Kind::DependentProtocolConformanceOpaque #81046

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

Open
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ NODE(DependentPseudogenericSignature)
NODE(DependentProtocolConformanceRoot)
NODE(DependentProtocolConformanceInherited)
NODE(DependentProtocolConformanceAssociated)
NODE(DependentProtocolConformanceOpaque)
CONTEXT_NODE(Destructor)
CONTEXT_NODE(DidSet)
NODE(Directness)
Expand Down
1 change: 1 addition & 0 deletions include/swift/Demangling/Demangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class Demangler : public NodeFactory {
NodePointer demangleDependentProtocolConformanceInherited();
NodePointer popDependentAssociatedConformance();
NodePointer demangleDependentProtocolConformanceAssociated();
NodePointer demangleDependentProtocolConformanceOpaque();
NodePointer demangleThunkOrSpecialization();
NodePointer demangleGenericSpecialization(Node::Kind SpecKind,
NodePointer droppedArguments);
Expand Down
9 changes: 9 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ NodePointer Demangler::demangleOperator() {
case 'C': return demangleConcreteProtocolConformance();
case 'D': return demangleDependentProtocolConformanceRoot();
case 'I': return demangleDependentProtocolConformanceInherited();
case 'O': return demangleDependentProtocolConformanceOpaque();
case 'P':
return createWithChild(
Node::Kind::ProtocolConformanceRefInTypeModule, popProtocol());
Expand Down Expand Up @@ -1961,6 +1962,7 @@ NodePointer Demangler::popAnyProtocolConformance() {
case Node::Kind::DependentProtocolConformanceRoot:
case Node::Kind::DependentProtocolConformanceInherited:
case Node::Kind::DependentProtocolConformanceAssociated:
case Node::Kind::DependentProtocolConformanceOpaque:
return true;

default:
Expand Down Expand Up @@ -2060,6 +2062,13 @@ NodePointer Demangler::demangleDependentConformanceIndex() {
return createNode(Node::Kind::Index, unsigned(index) - 2);
}

NodePointer Demangler::demangleDependentProtocolConformanceOpaque() {
NodePointer type = popNode(Node::Kind::Type);
NodePointer conformance = popDependentProtocolConformance();
return createWithChildren(Node::Kind::DependentProtocolConformanceOpaque,
conformance, type);
}

NodePointer Demangler::demangleRetroactiveConformance() {
NodePointer index = demangleIndexAsNode();
NodePointer conformance = popAnyProtocolConformance();
Expand Down
7 changes: 7 additions & 0 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ class NodePrinter {
case Node::Kind::DependentProtocolConformanceAssociated:
case Node::Kind::DependentProtocolConformanceInherited:
case Node::Kind::DependentProtocolConformanceRoot:
case Node::Kind::DependentProtocolConformanceOpaque:
case Node::Kind::ProtocolConformanceRefInTypeModule:
case Node::Kind::ProtocolConformanceRefInProtocolModule:
case Node::Kind::ProtocolConformanceRefInOtherModule:
Expand Down Expand Up @@ -3285,6 +3286,12 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
Printer << " to ";
print(Node->getChild(1), depth + 1);
return nullptr;
case Node::Kind::DependentProtocolConformanceOpaque:
Printer << "opaque result conformance ";
print(Node->getChild(0), depth + 1);
Printer << " of ";
print(Node->getChild(1), depth + 1);
return nullptr;
case Node::Kind::ProtocolConformanceRefInTypeModule:
Printer << "protocol conformance ref (type's module) ";
printChildren(Node, depth);
Expand Down
7 changes: 7 additions & 0 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ Remangler::mangleDependentProtocolConformanceAssociated(Node *node,
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
}

ManglingError
Remangler::mangleDependentProtocolConformanceOpaque(Node *node,
unsigned depth) {
// Dependent conformances aren't in the old mangling
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
}

ManglingError Remangler::mangleProtocolConformance(Node *node, unsigned depth) {
// type, protocol name, context
DEMANGLER_ASSERT(node->getNumChildren() == 3, node);
Expand Down
12 changes: 12 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,16 @@ ManglingError Remangler::mangleDependentConformanceIndex(Node *node,
return ManglingError::Success;
}

ManglingError Remangler::mangleDependentProtocolConformanceOpaque(Node *node,
unsigned depth) {
DEMANGLER_ASSERT(node->getKind() == Node::Kind::DependentProtocolConformanceOpaque,
node);
mangleAnyProtocolConformance(node->getChild(0), depth + 1);
mangleType(node->getChild(1), depth + 1);
Buffer << "HO";
return ManglingError::Success;
}

ManglingError Remangler::mangleAnyProtocolConformance(Node *node,
unsigned depth) {
switch (node->getKind()) {
Expand All @@ -2790,6 +2800,8 @@ ManglingError Remangler::mangleAnyProtocolConformance(Node *node,
return mangleDependentProtocolConformanceInherited(node, depth + 1);
case Node::Kind::DependentProtocolConformanceAssociated:
return mangleDependentProtocolConformanceAssociated(node, depth + 1);
case Node::Kind::DependentProtocolConformanceOpaque:
return mangleDependentProtocolConformanceOpaque(node, depth + 1);
default:
// Should this really succeed?!
return ManglingError::Success;
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 @@ -497,3 +497,4 @@ _$s15raw_identifiers0020pathfoo_yuEHaaCiJskayyF ---> raw_identifiers.`path://foo
_$s15raw_identifiers10FontWeightO009_100_FpEpdyyFZ ---> static raw_identifiers.FontWeight.`100`() -> ()
$s7Library1BC1iSivxTwd ---> default override of Library.B.i.modify2 : Swift.Int
$s7Library1BC1iSivxTwdTwc ---> coro function pointer to default override of Library.B.i.modify2 : Swift.Int
$s3use1xAA3OfPVy3lib1GVyAA1fQryFQOyQo_GAjE1PAAxAeKHD1_AIHO_HCg_Gvp ---> use.x : use.OfP<lib.G<<<opaque return type of use.f() -> some>>.0>>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public struct G<T> {
public init(_: T) {}
}

public protocol P {
associatedtype A: P

func a() -> A
}
31 changes: 31 additions & 0 deletions test/SILGen/opaque_result_type_retroactive.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %target-swift-emit-silgen %s -I %t | %FileCheck %s

import opaque_result_type_retroactive_other

extension G: @retroactive P where T: P {
public func a() -> T {
fatalError()
}
}

public struct S: P {
public func a() -> S {
return self
}
}

public func f() -> some P {
return S()
}

public struct OfP<T: P> {
public init(_: T) {}
}

// CHECK-LABEL: sil_global @$s30opaque_result_type_retroactive1xAA3OfPVy0a1_b1_c1_D6_other1GVyAA1fQryFQOyQo_GAjE1PAAxAeKHD1_AIHO_HCg_Gvp
public var x = OfP(G(f()))

// CHECK-LABEL: sil_global @$s30opaque_result_type_retroactive1yAA3OfPVy0a1_b1_c1_D6_other1GVyAA1fQryFQOyQo_1AAE1PPQxGAnekAxAeKHD1_AJQzAeKHA1_AMHO_HCg_Gvp
public var y = OfP(G(f().a()))