Skip to content

Revert "[cxx-interop] Allow import-as-member for types in namespaces" #82863

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
50 changes: 13 additions & 37 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ bool SwiftLookupTable::contextRequiresName(ContextKind kind) {

/// Try to translate the given Clang declaration into a context.
static std::optional<SwiftLookupTable::StoredContext>
translateDeclToContext(const clang::NamedDecl *decl) {
translateDeclToContext(clang::NamedDecl *decl) {
// Tag declaration.
if (auto tag = dyn_cast<clang::TagDecl>(decl)) {
if (tag->getIdentifier())
Expand Down Expand Up @@ -324,46 +324,22 @@ SwiftLookupTable::translateContext(EffectiveClangContext context) {

/// Lookup an unresolved context name and resolve it to a Clang
/// declaration context or typedef name.
const clang::NamedDecl *
SwiftLookupTable::resolveContext(StringRef unresolvedName) {
SmallVector<StringRef, 1> nameComponents;
unresolvedName.split(nameComponents, '.');

EffectiveClangContext parentContext;

clang::NamedDecl *SwiftLookupTable::resolveContext(StringRef unresolvedName) {
// Look for a context with the given Swift name.
for (auto nameComponent : nameComponents) {
auto entries =
parentContext
? lookup(SerializedSwiftName(nameComponent), parentContext)
: lookup(SerializedSwiftName(nameComponent),
std::make_pair(ContextKind::TranslationUnit, StringRef()));
bool entryFound = false;
for (auto entry : entries) {
if (auto decl = entry.dyn_cast<clang::NamedDecl *>()) {
if (isa<clang::TagDecl>(decl) ||
isa<clang::ObjCInterfaceDecl>(decl) ||
isa<clang::NamespaceDecl>(decl)) {
entryFound = true;
parentContext = EffectiveClangContext(cast<clang::DeclContext>(decl));
break;
}
if (auto typedefDecl = dyn_cast<clang::TypedefNameDecl>(decl)) {
entryFound = true;
parentContext = EffectiveClangContext(typedefDecl);
break;
}
}
for (auto entry :
lookup(SerializedSwiftName(unresolvedName),
std::make_pair(ContextKind::TranslationUnit, StringRef()))) {
if (auto decl = entry.dyn_cast<clang::NamedDecl *>()) {
if (isa<clang::TagDecl>(decl) ||
isa<clang::ObjCInterfaceDecl>(decl) ||
isa<clang::TypedefNameDecl>(decl))
return decl;
}

// If we could not resolve this component of the qualified name, bail.
if (!entryFound)
return nullptr;
}

return parentContext.getAsDeclContext()
? cast<clang::NamedDecl>(parentContext.getAsDeclContext())
: parentContext.getTypedefName();
// FIXME: Search imported modules to resolve the context.

return nullptr;
}

void SwiftLookupTable::addCategory(clang::ObjCCategoryDecl *category) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/SwiftLookupTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class SwiftLookupTable {
public:
/// Lookup an unresolved context name and resolve it to a Clang
/// named declaration.
const clang::NamedDecl *resolveContext(StringRef unresolvedName);
clang::NamedDecl *resolveContext(StringRef unresolvedName);

/// Lookup the set of entities with the given base name.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Functions:
- Name: ZXSpectrumSetMisnamedRegister
SwiftName: 'setter:ZXSpectrum.misnamedRegister(self:newValue:)'
- Name: ZXSpectrumHelperReset
SwiftName: 'ZXSpectrum::Helper.reset()'
SwiftName: 'ZXSpectrum.Helper.reset()'
32 changes: 0 additions & 32 deletions test/Interop/Cxx/namespace/Inputs/import-as-member.h

This file was deleted.

6 changes: 0 additions & 6 deletions test/Interop/Cxx/namespace/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ module Enums {
requires cplusplus
}

module ImportAsMember {
header "import-as-member.h"
export *
requires cplusplus
}

module MembersDirect {
header "members-direct.h"
requires cplusplus
Expand Down

This file was deleted.

24 changes: 0 additions & 24 deletions test/Interop/Cxx/namespace/import-as-member-typechecker.swift

This file was deleted.

31 changes: 0 additions & 31 deletions test/Interop/Cxx/namespace/import-as-member.swift

This file was deleted.