Skip to content

[cxx-interop] Fix a rare compilation error in reverse interop header #80598

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
Apr 7, 2025

Conversation

Xazax-hun
Copy link
Contributor

To trigger this error one needs to import a nested type from C++, use it in a generic context in Swift, and export it back to C++. We were inconsisent in what namespace did we declare the functions to get the type metadata for types. It was in the swift namespace for foreign types and in the module namespace for Swift types. This PR standardizes on how the metadata function is declared and called to fix the issue.

Fixes #80538.

rdar://148597079


bool importer::isClangNamespace(const DeclContext *dc) {
if (const auto *ed = dc->getSelfEnumDecl())
return llvm::isa_and_nonnull<clang::NamespaceDecl>(ed->getClangDecl());
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: redundant llvm::

// RUN: cat %t/UseCxxTy.h >> %t/full-header.h
// RUN: %target-interop-build-clangxx -std=c++20 -c -xc++-header %t/full-header.h -o %t/o.o

// UN: %FileCheck %s < %t/UseCxxTy.h
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this UN: supposed to be RUN:?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, this is a line I wanted to remove. Thanks for catching this!

To trigger this error one needs to import a nested type from C++, use it
in a generic context in Swift, and export it back to C++. We were
inconsisent in what namespace did we declare the functions to get the
type metadata for types. It was in the swift namespace for foreign types
and in the module namespace for Swift types. This PR standardizes on how
the metadata function is declared and called to fix the issue.

Fixes #80538.

rdar://148597079
@Xazax-hun Xazax-hun force-pushed the gaborh/nested-foreign-type-metadata branch from 36aaa67 to b3b2031 Compare April 7, 2025 16:50
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun Xazax-hun enabled auto-merge April 7, 2025 18:00
@Xazax-hun Xazax-hun merged commit fe98abb into main Apr 7, 2025
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/nested-foreign-type-metadata branch April 7, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
3 participants