Skip to content
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

Swift should allow multiple SWIFT_CONFORMS_TO_PROTOCOL attributes on a C++ class #75831

Open
egorzhdan opened this issue Aug 12, 2024 · 2 comments · May be fixed by #76204
Open

Swift should allow multiple SWIFT_CONFORMS_TO_PROTOCOL attributes on a C++ class #75831

egorzhdan opened this issue Aug 12, 2024 · 2 comments · May be fixed by #76204
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself good first issue Good for newcomers

Comments

@egorzhdan
Copy link
Contributor

Description

swift/bridging header defines a SWIFT_CONFORMS_TO_PROTOCOL macro, which expands to __attribute__((swift_attr("conforms_to:MyModule.MyProtocol"))).

This attribute lets the Swift compiler know that the annotated C++ class should be automatically marked as conforming to a Swift protocol with the given name.

Currently the Swift compiler only respects one SWIFT_CONFORMS_TO_PROTOCOL attribute on a single C++ class at a time. This is a limitation, we should support multiple SWIFT_CONFORMS_TO_PROTOCOL attributes on a single class.

Reproduction

Expected behavior

If two or more SWIFT_CONFORMS_TO_PROTOCOL attributes are provided, Swift should conform the C++ type to all of the listed Swift protocols.

Environment

Recent Swift compiler from main

Additional information

This is the part of ClangImporter that handles explicit conformances:

void
addExplicitProtocolConformances(NominalTypeDecl *decl,
const clang::CXXRecordDecl *clangDecl) {

This method would likely need to change as part of the resolution of this issue.

@egorzhdan egorzhdan added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself good first issue Good for newcomers labels Aug 12, 2024
@jz709u
Copy link

jz709u commented Aug 21, 2024

I am working on this issue. I have a solution already, but still testing it

@jz709u
Copy link

jz709u commented Aug 24, 2024

I have been working on validating my solution.
It's been difficult as I can't do one-off toolchain builds based on this thread:
https://forums.swift.org/t/cant-build-toolchain/70247

I have resorted to validating my solution using the build-script tool and attempting to test it via unit tests. I can't find the corresponding unit tests which test this part of the code.

I would appreciate it if someone could point me in the right direction on the quickest way to test your solutions.
Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants