Skip to content

Commit 56052cf

Browse files
committed
Apparently the right way to look up imported declarations is to just ask the importer to look things up.
1 parent a2e03d5 commit 56052cf

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

lib/RemoteAST/RemoteAST.cpp

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/Module.h"
2323
#include "swift/AST/NameLookup.h"
2424
#include "swift/AST/Types.h"
25+
#include "swift/ClangImporter/ClangImporter.h"
2526

2627
using namespace swift;
2728
using namespace swift::remote;
@@ -366,8 +367,8 @@ class RemoteASTTypeBuilder {
366367
return loc.getType();
367368
}
368369

369-
NominalTypeDecl *getAcceptableNominalTypeCandidate(ValueDecl *decl,
370-
Demangle::Node::Kind kind) {
370+
static NominalTypeDecl *getAcceptableNominalTypeCandidate(ValueDecl *decl,
371+
Demangle::Node::Kind kind) {
371372
if (kind == Demangle::Node::Kind::Class) {
372373
return dyn_cast<ClassDecl>(decl);
373374
} else if (kind == Demangle::Node::Kind::Enum) {
@@ -557,44 +558,34 @@ RemoteASTTypeBuilder::findNominalTypeDecl(DeclContext *dc,
557558
NominalTypeDecl *
558559
RemoteASTTypeBuilder::findForeignNominalTypeDecl(Identifier name,
559560
Demangle::Node::Kind kind) {
560-
SimpleIdentTypeRepr repr(SourceLoc(), name);
561-
auto type = checkTypeRepr(&repr);
562-
if (!type) return nullptr;
563-
564-
if (auto nomTy = type->getAs<NominalType>()) {
565-
if (auto typeDecl = getAcceptableNominalTypeCandidate(nomTy->getDecl(), kind)) {
566-
if (typeDecl->hasClangNode())
567-
return typeDecl;
561+
// Check to see if we have an importer loaded.
562+
auto importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
563+
if (!importer) return nullptr;
564+
565+
// Find the unique declaration that has the right kind.
566+
struct Consumer : VisibleDeclConsumer {
567+
Demangle::Node::Kind ExpectedKind;
568+
NominalTypeDecl *Result = nullptr;
569+
bool HadError = false;
570+
571+
explicit Consumer(Demangle::Node::Kind kind) : ExpectedKind(kind) {}
572+
573+
void foundDecl(ValueDecl *decl, DeclVisibilityKind reason) override {
574+
if (HadError) return;
575+
auto typeDecl = getAcceptableNominalTypeCandidate(decl, ExpectedKind);
576+
if (!typeDecl) return;
577+
if (!Result) {
578+
Result = typeDecl;
579+
} else {
580+
HadError = true;
581+
Result = nullptr;
582+
}
568583
}
569-
}
570-
return nullptr;
571-
572-
UnqualifiedLookup lookup(name, getNotionalDC(), /*resolver*/ nullptr,
573-
/*known private*/ false, SourceLoc(),
574-
/*type lookup*/ true);
575-
576-
NominalTypeDecl *result = nullptr;
577-
for (auto lookupResult : lookup.Results) {
578-
// We can ignore the base declaration here.
579-
auto decl = lookupResult.getValueDecl();
580-
581-
// Ignore results that are not the right kind of nominal type declaration.
582-
NominalTypeDecl *candidate = getAcceptableNominalTypeCandidate(decl, kind);
583-
if (!candidate)
584-
continue;
585-
586-
// Ignore results that aren't foreign.
587-
if (!candidate->hasClangNode())
588-
continue;
589-
590-
// This is a viable result.
584+
} consumer(kind);
591585

592-
// If we already have a viable result, it's ambiguous, so give up.
593-
if (result) return nullptr;
594-
result = candidate;
595-
}
586+
importer->lookupValue(name, consumer);
596587

597-
return result;
588+
return consumer.Result;
598589
}
599590

600591
namespace {

test/RemoteAST/foreign_types.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %target-swift-remoteast-test -sdk %S/../IRGen/Inputs %s | FileCheck %s
22

33
// REQUIRES: objc_interop
4-
// XFAIL: *
54

65
import CoreCooling
76

0 commit comments

Comments
 (0)