Skip to content

[cxx-interop] Mark some zero-sized value types as unavailable #77100

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
Oct 28, 2024

Conversation

Xazax-hun
Copy link
Contributor

Currently, we do not support exporting zero-sized value types from Swift to C++. It needs some work on our end as these types are not part of the lowered signature. In the meantime, this PR makes sure that common (but not all) zero sized types are properly marked as unavailable. This is important as the proper diagnostic will give users a hint how to work around this problem. Moreover, it is really easy to hit this when someone is experimenting with interop, so it is important to not have a cryptic failure mode.

rdar://138122545

@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Oct 18, 2024
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

Comment on lines 107 to 108
std::optional<std::function<bool(const NominalTypeDecl *)>> isZeroSized =
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.

Is it reasonable to invoke this without passing a zero-size check in some cases? Wondering if the default value of the parameter is needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, there is one user in the Swift AST that checks for the correct use of @_expose(Cxx). We do not have access to the type layout in that module, so we cannot do this check when doing semantic analysis for this attribute. I added the default argument for that user. We would still diagnose zero sized types as unavailable, but would do during the interop header generation via an unavailable attribe (not via a diagnostic while doing the semantic analysis for @expose).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly, but could we remove the default value on the declaration, and pass nullopt on that call site, since that seems to be an exception that we wouldn't want to be repeated elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point! Will do.

Currently, we do not support exporting zero-sized value types from Swift
to C++. It needs some work on our end as these types are not part of the
lowered signature. In the meantime, this PR makes sure that common (but
not all) zero sized types are properly marked as unavailable. This is
important as the proper diagnostic will give users a hint how to work
around this problem. Moreover, it is really easy to hit this when
someone is experimenting with interop, so it is important to not have a
cryptic failure mode.

rdar://138122545
@Xazax-hun Xazax-hun force-pushed the gaborh/empty-value-type-diagnostic branch from 7809039 to 22b46d3 Compare October 28, 2024 14:00
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun Xazax-hun merged commit 708782d into main Oct 28, 2024
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/empty-value-type-diagnostic branch October 28, 2024 18:08
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.

2 participants