Skip to content

Commit bd8ab16

Browse files
committed
[Demangle-to-AST type] Make sure we can find the original nominal type in its own module
With noncopyable generics, we can end up using an extension mangling to refer to the original nominal type, even in its own module. Make sure we resolve that to the original nominal type declaration, rather than hunting for an extension that might not be there.
1 parent 8090fcf commit bd8ab16

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,17 +1268,33 @@ ASTBuilder::findDeclContext(NodePointer node) {
12681268
return nullptr;
12691269

12701270
CanGenericSignature genericSig;
1271-
if (node->getNumChildren() > 2)
1271+
bool genericSigMatchesNominal = false;
1272+
if (node->getNumChildren() > 2) {
12721273
genericSig = demangleGenericSignature(nominalDecl, node->getChild(2));
12731274

1275+
// If the generic signature are equivalent to that of the nominal type,
1276+
// we're either in another module or the nominal type is generic and
1277+
// involves inverse requirements on its generic parameters.
1278+
genericSigMatchesNominal = genericSig &&
1279+
genericSig == nominalDecl->getGenericSignatureOfContext().getCanonicalSignature();
1280+
1281+
// If the generic signature is equivalent to that of the nominal type,
1282+
// and we're in the same module, it's due to inverse requirements.
1283+
// Just return the nominal declaration.
1284+
if (genericSigMatchesNominal &&
1285+
nominalDecl->getParentModule() == moduleDecl) {
1286+
return nominalDecl;
1287+
}
1288+
}
1289+
12741290
for (auto *ext : nominalDecl->getExtensions()) {
12751291
if (ext->getParentModule() != moduleDecl)
12761292
continue;
12771293

12781294
if (!ext->isConstrainedExtension()) {
1279-
if (!genericSig ||
1280-
genericSig->isEqual(nominalDecl->getGenericSignature()))
1295+
if (!genericSig || genericSigMatchesNominal)
12811296
return ext;
1297+
12821298
continue;
12831299
}
12841300

test/IRGen/mangling_inverse_generics_evolution.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ func useAtomicRepresentation() {
8686
let x = UnsafePointer<Int>.AtomicRepresentation()
8787
print(x)
8888
}
89+
90+
struct Box<Wrapped: ~Copyable>: ~Copyable { }
91+
92+
struct List<Element: ~Copyable>: ~Copyable {
93+
// CHECK: $s4test4ListVAARiczrlE4NodeVwst
94+
struct Node: ~Copyable {
95+
var element: Element
96+
var next: Link
97+
}
98+
typealias Link = Box<Node>?
99+
100+
var head: Link
101+
}

0 commit comments

Comments
 (0)