Skip to content

[PrintAsObjC] Import/fwd-declare types used in @_cdecl functions. #37436

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
Nov 15, 2021

Conversation

allevato
Copy link
Member

When a @_cdecl function is printed to a generated header, the types it uses in its signature are not forward declared or imported, so the header isn't usable unless you also add another Objective-C declaration to the module (like a class or protocol) that uses the types to force it.

@allevato allevato requested a review from beccadax May 14, 2021 23:23
@allevato
Copy link
Member Author

@swift-ci please smoke test

@allevato
Copy link
Member Author

@beccadax If you have time, can you review this please? Thanks!

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.

It's a little strange that this is only the second time we've needed this logic. Now that forwardDeclareType() exists, should we be calling it in more places?

Assuming the answer is "no", I'm happy with this PR.

When a `@_cdecl` function is printed to a generated header, the types
it uses in its signature are not forward declared or imported, so the
header isn't usable unless you also add another Objective-C declaration
to the module (like a class or protocol) that uses the types to force
it.
@allevato allevato force-pushed the lost-in-a-c-of-decls branch from dc0d6ba to f9ea748 Compare November 15, 2021 16:33
@allevato
Copy link
Member Author

It's a little strange that this is only the second time we've needed this logic. Now that forwardDeclareType() exists, should we be calling it in more places?

Assuming the answer is "no", I'm happy with this PR.

AFAICT, all the other cases where it was needed were covered by the code now in forwardDeclareType previously being embedded in forwardDeclareMemberTypes, since that gets called whenever a class, protocol, or extension is printed, so it drills down through its methods/properties and forward-declares any types used in their signatures.

The missing piece was doing this for a file-scoped FuncDecl; I don't think we have any other declarations at this time that can be printed in an Obj-C header and need this.

@allevato
Copy link
Member Author

@swift-ci please test

@allevato
Copy link
Member Author

@swift-ci Please test Windows platform

@allevato allevato merged commit dcffbc0 into swiftlang:main Nov 15, 2021
@allevato allevato deleted the lost-in-a-c-of-decls branch November 15, 2021 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants