Skip to content

Conversation

Xazax-hun
Copy link
Contributor

rdar://159211965

@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Oct 10, 2025
@Xazax-hun Xazax-hun force-pushed the reverse-interop-non-public branch from 8e4b387 to 8f0dc63 Compare October 10, 2025 16:44
Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

LGTM, aside from one suggestion:

Can you add a test checking that the filter works for non-top-level items? Eg a struct with a mix of public and internal methods and fields.

@Xazax-hun Xazax-hun force-pushed the reverse-interop-non-public branch from 8f0dc63 to 96bf7db Compare October 10, 2025 17:32
Copy link
Contributor

@beccadax beccadax 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 a really nice enhancement, but I’d like it to work differently for C and ObjC interop.

llvm::raw_string_ostream moduleContents{moduleContentsBuf};
auto deps = printModuleContentsAsCxx(
moduleContents, *M, interopContext,
frontendOpts.ClangHeaderMinAccess.value_or(AccessLevel::Public),
Copy link
Contributor

@beccadax beccadax Oct 10, 2025

Choose a reason for hiding this comment

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

Possibly here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We currently do not seem to use the same heuristics for C++ interop (we never call getRequiredAccess). I did not want to change that behavior in this PR so leaving this as is for now. Let me know if you disagree.

os, *M->getASTContext().getStdlibModule(), interopContext,
/*requiresExposedAttribute=*/true, exposedModules);
printModuleContentsAsCxx(os, *M->getASTContext().getStdlibModule(),
interopContext, AccessLevel::Public,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this fixed as AccessLevel::Public? (Quite possible there’s a legitimate reason; I’m just wondering what it is.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This call is used to provide C++ a way to access certain types in Swift's standard library and we do not want to expose the non-public parts of it.

.Case("public", AccessLevel::Public)
.Case("package", AccessLevel::Package)
.Case("internal", AccessLevel::Internal)
.Default(std::nullopt);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be an explicit spelling for the default behavior? Something like auto or default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am a bit torn on this. Looking at the compiler invocation, seeing something like default would potentially mean that the behavior depends on the compiler version. I think that makes it a bit harder to understand what that invocation is doing and also the project more prone to break when/if the default change. Since I am split, I usually tend to lean towards providing less. Because it is always easier to add something in the future than taking it away. What do you think?

@Xazax-hun Xazax-hun force-pushed the reverse-interop-non-public branch from 96bf7db to 89869a4 Compare October 13, 2025 09:39
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

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++

3 participants