-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Swiftify] don't add macro when required type is unavailable #86084
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
base: main
Are you sure you want to change the base?
Conversation
|
@swift-ci please smoke test |
1 similar comment
|
@swift-ci please smoke test |
1e2c9de to
c2f2306
Compare
A Swift module only imports a type definition once. This means that some clang modules may have function signatures imported with `UnsafePointer<qux>` even if `qux` is only forward declared in that module (which would normally be imported as `OpaquePointer`), because some Swift file in the module imported the clang module with the definition, so ClangImporter sees the definition. The macro expansion only imports the imports of the clang module it belongs to however, so namelookup for `qux` fails. This patch detects when this will result in an error and avoids attaching the macro in those cases. rdar://165864358
Implicit decls don't have an owning module, since multiple modules could instantiate them on demand. Since no implicit functions currently have any need for safe wrappers we can simply detect this and early exit. For templated functions, we need to fetch the owning module from the instantiation.
c2f2306 to
cd5d8e1
Compare
|
@swift-ci please smoke test |
This fixes an assert when signatures contain
`struct forward_declared_t **`, and makes sure that
`struct foo { struct forward_declared_t *bar; }` does *not* block
swiftification, since `@_SwiftifyImport` does not need to access the
struct field.
|
@swift-ci please smoke test |
Since decls with no module are imported to __ObjC this is not an issue, because __ObjC is always implicitly imported. Added test case that would previously assert.
|
@swift-ci please smoke test |
Xazax-hun
left a comment
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.
Overall looks good to me, one question inline.
| Action walkToTypePre(Type ty) override { | ||
| DLOG("Walking type:\n"); | ||
| LLVM_DEBUG(DUMP(ty)); | ||
| if (Type PointeeTy = ConcretePointeeType(ty)) { |
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.
Could we ever run into trouble with UnsafeBufferPointer and co?
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.
As in, could we ever encounter an UnsafeBufferPointer in the imported signature? Not that I know of
egorzhdan
left a comment
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.
Haven't looked into the specifics of the implementation, but the approach looks good, thanks!
|
@swift-ci please smoke test windows platform |
A Swift module only imports a type definition once. This means that some clang modules may have function signatures imported with
UnsafePointer<qux>even ifquxis only forward declared in that module (which would normally be imported asOpaquePointer), because some Swift file in the module imported the clang module with the definition, so ClangImporter sees the definition. The macro expansion only imports the imports of the clang module it belongs to however, so namelookup forquxfails. This patch detects when this will result in an error and avoids attaching the macro in those cases.rdar://165864358