-
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
Open
xymus
wants to merge
6
commits into
swiftlang:main
Choose a base branch
from
xymus:cdecl-enum
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+440
−50
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
artemcm
reviewed
Jun 26, 2025
@@ -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
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.