Skip to content

[IDE] Fix type reconstructions for PrivateDeclName. #15126

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

Merged
merged 1 commit into from
Mar 12, 2018
Merged
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
87 changes: 53 additions & 34 deletions lib/IDE/TypeReconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,40 @@ static bool CompareFunctionTypes(const AnyFunctionType *f,
return (in_matches && out_matches);
}

static void VisitNodePrivateDeclName(
ASTContext *ast,
Demangle::NodePointer parent_node,
Demangle::NodePointer cur_node, VisitNodeResult &result) {
DeclKind decl_kind = GetKindAsDeclKind(parent_node->getKind());

if (cur_node->getNumChildren() != 2) {
if (result._error.empty())
result._error = stringWithFormat(
"unable to retrieve content for Node::Kind::PrivateDeclName");
return;
}

Demangle::NodePointer priv_decl_id_node(cur_node->getChild(0));
Demangle::NodePointer id_node(cur_node->getChild(1));

if (!priv_decl_id_node->hasText() || !id_node->hasText()) {
if (result._error.empty())
result._error = stringWithFormat(
"unable to retrieve content for Node::Kind::PrivateDeclName");
return;
}

if (!FindFirstNamedDeclWithKind(ast, ast->getIdentifier(id_node->getText()),
decl_kind, result,
priv_decl_id_node->getText().str())) {
if (result._error.empty())
result._error = stringWithFormat(
"unable to find Node::Kind::PrivateDeclName '%s' in '%s'",
id_node->getText().str().c_str(),
priv_decl_id_node->getText().str().c_str());
}
}

// VisitNodeFunction gets used for Function, Variable and Allocator:
static void VisitNodeFunction(
ASTContext *ast,
Expand Down Expand Up @@ -1191,6 +1225,25 @@ static void VisitNodeFunction(
VisitNode(ast, *pos, decl_scope_result);
break;

case Demangle::Node::Kind::PrivateDeclName: {
VisitNodePrivateDeclName(ast, cur_node, child, decl_scope_result);

// No results found, giving up.
if (decl_scope_result._decls.empty())
break;

std::copy(decl_scope_result._decls.begin(),
decl_scope_result._decls.end(),
back_inserter(identifier_result._decls));
std::copy(decl_scope_result._types.begin(),
decl_scope_result._types.end(),
back_inserter(identifier_result._types));
identifier_result._module = decl_scope_result._module;
if (decl_scope_result._decls.size() == 1)
found_univocous = true;
break;
}

case Demangle::Node::Kind::LabelList: {
for (const auto &label : **pos) {
if (label->getKind() == Demangle::Node::Kind::FirstElementMarker)
Expand Down Expand Up @@ -1670,40 +1723,6 @@ static void VisitNodeLocalDeclName(
}
}

static void VisitNodePrivateDeclName(
ASTContext *ast,
Demangle::NodePointer parent_node,
Demangle::NodePointer cur_node, VisitNodeResult &result) {
DeclKind decl_kind = GetKindAsDeclKind(parent_node->getKind());

if (cur_node->getNumChildren() != 2) {
if (result._error.empty())
result._error = stringWithFormat(
"unable to retrieve content for Node::Kind::PrivateDeclName");
return;
}

Demangle::NodePointer priv_decl_id_node(cur_node->getChild(0));
Demangle::NodePointer id_node(cur_node->getChild(1));

if (!priv_decl_id_node->hasText() || !id_node->hasText()) {
if (result._error.empty())
result._error = stringWithFormat(
"unable to retrieve content for Node::Kind::PrivateDeclName");
return;
}

if (!FindFirstNamedDeclWithKind(ast, ast->getIdentifier(id_node->getText()),
decl_kind, result,
priv_decl_id_node->getText().str())) {
if (result._error.empty())
result._error = stringWithFormat(
"unable to find Node::Kind::PrivateDeclName '%s' in '%s'",
id_node->getText().str().c_str(),
priv_decl_id_node->getText().str().c_str());
}
}

static void VisitNodeRelatedEntityDeclName(
ASTContext *ast,
Demangle::NodePointer parent_node,
Expand Down
12 changes: 10 additions & 2 deletions test/IDE/reconstruct_type_from_mangled_name.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ func hasLocalDecls() {

fileprivate struct VeryPrivateData {}

// FIXME
// CHECK: decl: FAILURE for 'privateFunction'
// CHECK: decl: fileprivate func privateFunction(_ d: VeryPrivateData) for 'privateFunction'
fileprivate func privateFunction(_ d: VeryPrivateData) {}

struct HasSubscript {
Expand Down Expand Up @@ -306,3 +305,12 @@ struct HasGenericSubscript<T> {
set {}
}
}

private
// CHECK: decl: private func patatino<T>(_ vers1: T, _ vers2: T) -> Bool where T : Comparable for
func patatino<T: Comparable>(_ vers1: T, _ vers2: T) -> Bool {
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xts10ComparableRzlF1TL_xmfp decl
// CHECK: decl: let vers1: T for 'vers1' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xts10ComparableRzlF5vers1L_xvp
// CHECK: decl: let vers2: T for 'vers2' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xts10ComparableRzlF5vers2L_xvp
return vers1 < vers2;
}