-
Notifications
You must be signed in to change notification settings - Fork 10.5k
PrintAsClang: Introduce @cdecl
enums
#82039
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
Conversation
@swift-ci Please smoke test |
a92e68a
to
00890cb
Compare
@swift-ci Please smoke test |
Print @cdecl enums in the C section of the compatibility header. Use and extend the macros to support C compiler clients. The macro is adapted to the features supported by the client compiler. It uses an Objective-C style macro with raw type when available and fallbacks to a simple typedef for C compatibility.
There are two main scenarios when printing a compatibility header that references a @cdecl enum defined in Swift code. (1) When defined in the same module as it's used we can print the definition normally and then reference it. (2) When used in a different mode we need to print a forward declaration before we can reference it. This change adds printing the forward declaration and fix an issue where the compiler would instead print an @include of the Swift module. The import of the Swift module would work only in a local scenario where a compatibility header and module would be generated under the same name. However for a distributed frameworks we do not distribute the compatibility header so this strategy doesn't work. Relying on a forward declaration should be more reliable in all cases but clients may need to import the other compatibility header explicitly.
@swift-ci Please smoke test |
@swift-ci Please smoke test Linux |
@@ -457,6 +457,14 @@ class ModuleWriter { | |||
} | |||
} | |||
|
|||
if (isa<EnumDecl>(D) && !D->hasClangNode() && | |||
outputLangMode != OutputLanguageMode::Cxx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I follow from the code, could you explain why outputLangMode != OutputLanguageMode::Cxx
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field outputLangMode
sets the block of the compatibility header we're currently writing and how we represent different types for different languages.
This is part of the fix to not print an invalid import of a Swift module from the C header to access its enums, and instead forward declare the enum. This was an issue with the C and Objective-C interop, the C++ interop has its own way of handling this configuration which worked and this fix conflicted with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.
@swift-ci Please smoke test |
@swift-ci Please smoke test Windows |
Introduce
@cdecl
enums, enums declared in Swift and representable in C. These enums must have an integer raw type and can be referenced from@cdecl
functions and@objc
methods.@cdecl
enums are printed in the compatibility header using a macro that ensures compatibility with different C language modes. They can also be forward declared when referenced from the compatibility header of a client.@cdecl
and@objc
enums mostly have the same restrictions on their declarations. There are differences on how they are printed in the compatibility header, each are in the corresponding language section and only@objc
enums supports error domains.This is guarded behind the
CDecl
feature flag.