Skip to content

[cxx-interop] Skip already-imported sub decls. #35964

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
Feb 15, 2021
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
10 changes: 5 additions & 5 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3371,6 +3371,11 @@ namespace {
}
}

// If we've already imported this decl, skip it so we don't add the same
// member twice.
if (Impl.ImportedDecls.count({nd->getCanonicalDecl(), getVersion()}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it would be more idiomatic to use find() != end() instead of count, until someone adds a contains_key method to upstream DenseMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, thanks!

continue;

auto member = Impl.importDecl(nd, getActiveSwiftVersion());
if (!member) {
if (!isa<clang::TypeDecl>(nd) && !isa<clang::FunctionDecl>(nd)) {
Expand All @@ -3383,11 +3388,6 @@ namespace {
}

if (auto nestedType = dyn_cast<TypeDecl>(member)) {
// Only import definitions. Otherwise, we might add the same member
// twice.
if (auto tagDecl = dyn_cast<clang::TagDecl>(nd))
if (tagDecl->getDefinition() != tagDecl)
continue;
nestedTypes.push_back(nestedType);
continue;
}
Expand Down
12 changes: 12 additions & 0 deletions test/Interop/Cxx/class/Inputs/nested-records.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ struct HasForwardDeclaredNestedType {
struct ForwardDeclaredType { };
};

struct HasForwardDeclaredTemplateChild {
template <class T> struct ForwardDeclaredClassTemplate;

struct DeclaresForwardDeclaredClassTemplateFriend {
template <class T>
friend struct HasForwardDeclaredTemplateChild::ForwardDeclaredClassTemplate;
};

template <class T> struct ForwardDeclaredClassTemplate { };
};


// TODO: Nested class templates (SR-13853).

#endif // TEST_INTEROP_CXX_CLASS_INPUTS_NESTED_RECORDS_H
11 changes: 10 additions & 1 deletion test/Interop/Cxx/class/nested-records-module-interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@
// CHECK: }

// CHECK: struct HasForwardDeclaredNestedType {
// CHECK: struct ForwardDeclaredType {
// CHECK: init()
// CHECK: }
// CHECK: struct NormalSubType {
// CHECK: init()
// CHECK: }
// CHECK: struct ForwardDeclaredType {
// CHECK: init()
// CHECK: }

// CHECK: struct HasForwardDeclaredTemplateChild {
// CHECK: struct ForwardDeclaredClassTemplate<T> {
// CHECK: }
// CHECK: struct DeclaresForwardDeclaredClassTemplateFriend {
// CHECK: init()
// CHECK: }
// CHECK: init()
Expand Down