Skip to content

C++ Interop: import namespace aliases #37443

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
May 23, 2021

Conversation

egorzhdan
Copy link
Contributor

Previously they weren't imported, now they are imported as typealiases to enums representing namespaces.

Fixes SR-12467.

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label May 15, 2021
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

cc @zoecarver @plotfi

@egorzhdan egorzhdan requested a review from zoecarver May 15, 2021 14:36
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test macOS

@plotfi
Copy link
Contributor

plotfi commented May 16, 2021

Looked over changes. LGTM but I am pretty green on this project. @zoecarver What do you think?

Comment on lines +43 to +59
namespace GlobalAliasToNS1 = ClassesNS1;

namespace ClassesNS4 {
namespace AliasToGlobalNS1 = ::ClassesNS1;
namespace AliasToGlobalNS2 = ::ClassesNS1::ClassesNS2;

namespace ClassesNS5 {
struct BasicStruct {};
} // namespace ClassesNS5

namespace AliasToInnerNS5 = ClassesNS5;
namespace AliasToNS2 = ClassesNS1::ClassesNS2;

namespace AliasChainToNS1 = GlobalAliasToNS1;
namespace AliasChainToNS2 = AliasChainToNS1::ClassesNS2;
} // namespace ClassesNS4

Copy link
Contributor

@varungandhi-apple varungandhi-apple May 16, 2021

Choose a reason for hiding this comment

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

Are more complex test cases covered by other tests? For example, consider code with namespaces that are shadowed

namespace X { }
namespace Y { namespace X { }; namespace Z = X; /* IIUC, refers to ::Y::X */ }

or code with using namespace ABC. Do these get translated correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There wasn't a test for such case, but I've added it now. Also added a test for an alias pointing to its parent namespace, and a couple of other similar cases.

Using-directives & using-declarations currently aren't imported at all (these C++ constructs, along with inline namespaces, are among those that I don't know how to express ergonomically in Swift).

Previously they weren't imported, now they are imported as typealiases to enums representing namespaces.

Fixes SR-12467.
@egorzhdan egorzhdan force-pushed the cxx-namespace-alias branch from 6d06597 to 51a8c47 Compare May 16, 2021 14:39
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@zoecarver
Copy link
Contributor

@swift-ci please test Windows.

@zoecarver
Copy link
Contributor

@swift-ci please test Windows platform.

@zoecarver
Copy link
Contributor

@swift-ci please test Windows.

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

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

This is great, thanks! Please land it once the Windows tests pass.

@@ -40,4 +40,35 @@ struct BasicStruct {
};
} // namespace ClassesNS3

namespace GlobalAliasToNS1 = ClassesNS1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest a test that references a namespace in another module, but I think we need to sort out SR-14214 first.

@zoecarver zoecarver merged commit 069e51d into swiftlang:main May 23, 2021
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
Development

Successfully merging this pull request may close these issues.

4 participants