Skip to content

Commit 5831fc9

Browse files
author
Davide Italiano
committed
[TypeReconstruction] Fix reconstructions for allocator.
Adrian reported this bug he discovered as part of his work on improving generics in swift/lldb. Allocators were treated as `function`, when the demangle tree suggests they're much more akin to constructors. On top of that, the code for handling them was commented out, so type reconstruction was always failing. I'm not entirely sure this is always correct, but it seems to be an improvement on what currently type reconstruction does. At least now we have tests so if something will break, we're going to notice. <rdar://problem/38720742>
1 parent 5b6285f commit 5831fc9

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

lib/IDE/TypeReconstruction.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ static void VisitLocalDeclVariableName(ASTContext *ast,
12171217
name->getText());
12181218
}
12191219

1220-
// VisitNodeFunction gets used for Function, Variable and Allocator:
1220+
// VisitNodeFunction gets used for Function and Variable.
12211221
static void VisitNodeFunction(
12221222
ASTContext *ast,
12231223
Demangle::NodePointer cur_node, VisitNodeResult &result) {
@@ -1347,25 +1347,6 @@ static void VisitNodeFunction(
13471347
}
13481348
} while (0);
13491349

1350-
// if (node_kind == Demangle::Node::Kind::Allocator)
1351-
// {
1352-
// // For allocators we don't have an identifier for
1353-
// the name, we will
1354-
// // need to extract it from the class or struct in
1355-
// "identifier_result"
1356-
// //Find
1357-
// if (identifier_result.HasSingleType())
1358-
// {
1359-
// // This contains the class or struct
1360-
// StringRef init_name("init");
1361-
//
1362-
// if (FindFirstNamedDeclWithKind(ast, init_name,
1363-
// DeclKind::Constructor, identifier_result))
1364-
// {
1365-
// }
1366-
// }
1367-
// }
1368-
13691350
if (identifier_result._types.size() == 1) {
13701351
result._module = identifier_result._module;
13711352
result._decls.push_back(identifier_result._decls[0]);
@@ -2229,6 +2210,7 @@ static void VisitNode(
22292210
VisitAllChildNodes(ast, node, result);
22302211
break;
22312212

2213+
case Demangle::Node::Kind::Allocator:
22322214
case Demangle::Node::Kind::Constructor:
22332215
VisitNodeConstructor(ast, node, result);
22342216
break;
@@ -2254,7 +2236,6 @@ static void VisitNode(
22542236
break;
22552237

22562238
case Demangle::Node::Kind::Function:
2257-
case Demangle::Node::Kind::Allocator:
22582239
case Demangle::Node::Kind::Variable:
22592240
case Demangle::Node::Kind::Subscript: // Out of order on purpose
22602241
VisitNodeFunction(ast, node, result);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
$S12DeclReconstr8patatinoSiyF ---> func patatino() -> Int
2-
$S12DeclReconstr1SVACycfC ---> Can't resolve decl of $S12DeclReconstr1SVACycfC
2+
$S12DeclReconstr1SVACycfC ---> init()

0 commit comments

Comments
 (0)