Skip to content

Commit 04ea4cc

Browse files
authored
Merge pull request #15126 from dcci/typereconstr-fixup-private
[IDE] Fix type reconstructions for PrivateDeclName.
2 parents 50a2703 + 74618cb commit 04ea4cc

File tree

2 files changed

+63
-36
lines changed

2 files changed

+63
-36
lines changed

lib/IDE/TypeReconstruction.cpp

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,40 @@ static bool CompareFunctionTypes(const AnyFunctionType *f,
11571157
return (in_matches && out_matches);
11581158
}
11591159

1160+
static void VisitNodePrivateDeclName(
1161+
ASTContext *ast,
1162+
Demangle::NodePointer parent_node,
1163+
Demangle::NodePointer cur_node, VisitNodeResult &result) {
1164+
DeclKind decl_kind = GetKindAsDeclKind(parent_node->getKind());
1165+
1166+
if (cur_node->getNumChildren() != 2) {
1167+
if (result._error.empty())
1168+
result._error = stringWithFormat(
1169+
"unable to retrieve content for Node::Kind::PrivateDeclName");
1170+
return;
1171+
}
1172+
1173+
Demangle::NodePointer priv_decl_id_node(cur_node->getChild(0));
1174+
Demangle::NodePointer id_node(cur_node->getChild(1));
1175+
1176+
if (!priv_decl_id_node->hasText() || !id_node->hasText()) {
1177+
if (result._error.empty())
1178+
result._error = stringWithFormat(
1179+
"unable to retrieve content for Node::Kind::PrivateDeclName");
1180+
return;
1181+
}
1182+
1183+
if (!FindFirstNamedDeclWithKind(ast, ast->getIdentifier(id_node->getText()),
1184+
decl_kind, result,
1185+
priv_decl_id_node->getText().str())) {
1186+
if (result._error.empty())
1187+
result._error = stringWithFormat(
1188+
"unable to find Node::Kind::PrivateDeclName '%s' in '%s'",
1189+
id_node->getText().str().c_str(),
1190+
priv_decl_id_node->getText().str().c_str());
1191+
}
1192+
}
1193+
11601194
// VisitNodeFunction gets used for Function, Variable and Allocator:
11611195
static void VisitNodeFunction(
11621196
ASTContext *ast,
@@ -1191,6 +1225,25 @@ static void VisitNodeFunction(
11911225
VisitNode(ast, *pos, decl_scope_result);
11921226
break;
11931227

1228+
case Demangle::Node::Kind::PrivateDeclName: {
1229+
VisitNodePrivateDeclName(ast, cur_node, child, decl_scope_result);
1230+
1231+
// No results found, giving up.
1232+
if (decl_scope_result._decls.empty())
1233+
break;
1234+
1235+
std::copy(decl_scope_result._decls.begin(),
1236+
decl_scope_result._decls.end(),
1237+
back_inserter(identifier_result._decls));
1238+
std::copy(decl_scope_result._types.begin(),
1239+
decl_scope_result._types.end(),
1240+
back_inserter(identifier_result._types));
1241+
identifier_result._module = decl_scope_result._module;
1242+
if (decl_scope_result._decls.size() == 1)
1243+
found_univocous = true;
1244+
break;
1245+
}
1246+
11941247
case Demangle::Node::Kind::LabelList: {
11951248
for (const auto &label : **pos) {
11961249
if (label->getKind() == Demangle::Node::Kind::FirstElementMarker)
@@ -1670,40 +1723,6 @@ static void VisitNodeLocalDeclName(
16701723
}
16711724
}
16721725

1673-
static void VisitNodePrivateDeclName(
1674-
ASTContext *ast,
1675-
Demangle::NodePointer parent_node,
1676-
Demangle::NodePointer cur_node, VisitNodeResult &result) {
1677-
DeclKind decl_kind = GetKindAsDeclKind(parent_node->getKind());
1678-
1679-
if (cur_node->getNumChildren() != 2) {
1680-
if (result._error.empty())
1681-
result._error = stringWithFormat(
1682-
"unable to retrieve content for Node::Kind::PrivateDeclName");
1683-
return;
1684-
}
1685-
1686-
Demangle::NodePointer priv_decl_id_node(cur_node->getChild(0));
1687-
Demangle::NodePointer id_node(cur_node->getChild(1));
1688-
1689-
if (!priv_decl_id_node->hasText() || !id_node->hasText()) {
1690-
if (result._error.empty())
1691-
result._error = stringWithFormat(
1692-
"unable to retrieve content for Node::Kind::PrivateDeclName");
1693-
return;
1694-
}
1695-
1696-
if (!FindFirstNamedDeclWithKind(ast, ast->getIdentifier(id_node->getText()),
1697-
decl_kind, result,
1698-
priv_decl_id_node->getText().str())) {
1699-
if (result._error.empty())
1700-
result._error = stringWithFormat(
1701-
"unable to find Node::Kind::PrivateDeclName '%s' in '%s'",
1702-
id_node->getText().str().c_str(),
1703-
priv_decl_id_node->getText().str().c_str());
1704-
}
1705-
}
1706-
17071726
static void VisitNodeRelatedEntityDeclName(
17081727
ASTContext *ast,
17091728
Demangle::NodePointer parent_node,

test/IDE/reconstruct_type_from_mangled_name.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ func hasLocalDecls() {
267267

268268
fileprivate struct VeryPrivateData {}
269269

270-
// FIXME
271-
// CHECK: decl: FAILURE for 'privateFunction'
270+
// CHECK: decl: fileprivate func privateFunction(_ d: VeryPrivateData) for 'privateFunction'
272271
fileprivate func privateFunction(_ d: VeryPrivateData) {}
273272

274273
struct HasSubscript {
@@ -306,3 +305,12 @@ struct HasGenericSubscript<T> {
306305
set {}
307306
}
308307
}
308+
309+
private
310+
// CHECK: decl: private func patatino<T>(_ vers1: T, _ vers2: T) -> Bool where T : Comparable for
311+
func patatino<T: Comparable>(_ vers1: T, _ vers2: T) -> Bool {
312+
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xts10ComparableRzlF1TL_xmfp decl
313+
// CHECK: decl: let vers1: T for 'vers1' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xts10ComparableRzlF5vers1L_xvp
314+
// CHECK: decl: let vers2: T for 'vers2' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xts10ComparableRzlF5vers2L_xvp
315+
return vers1 < vers2;
316+
}

0 commit comments

Comments
 (0)