-
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
Open
hnrklssn
wants to merge
5
commits into
main
Choose a base branch
from
opaque-non-opaque
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.
+412
−16
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
270f1d8
[Swiftify] don't add macro when required type is unavailable
hnrklssn 96d3deb
[Swiftify] fix missing owning module
hnrklssn cd5d8e1
handle bridging header decls in ForwardDeclaredConcreteTypeVisitor
hnrklssn db7c13c
traverse imported Swift type rather than clang type
hnrklssn ca3b77f
allow functions in modules to depend on decls with no owning module
hnrklssn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
test/Interop/C/swiftify-import/bridging-header-from-module.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // REQUIRES: swift_feature_SafeInteropWrappers | ||
|
|
||
| // RUN: %empty-directory(%t) | ||
| // RUN: split-file %s %t | ||
|
|
||
| // RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -o %t/test.swiftmodule -I %t -import-objc-header %t/bridging.h -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness -Xcc -Wno-div-by-zero -Xcc -Wno-pointer-to-int-cast %t/test.swift -verify | ||
| // RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -o %t/test.swiftmodule -I %t -import-objc-header %t/bridging.h -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness -Xcc -Wno-div-by-zero -Xcc -Wno-pointer-to-int-cast %t/test.swift -dump-macro-expansions 2>&1 | %FileCheck --dry-run > %t/macro-expansions.out | ||
| // RUN: %diff %t/macro-expansions.out %t/macro-expansions.expected | ||
| // RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -o %t/test.swiftmodule -I %t -import-objc-header %t/bridging.h -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness -Xcc -Wno-div-by-zero -Xcc -Wno-pointer-to-int-cast %t/test.swift -dump-source-file-imports 2>&1 | %FileCheck --dry-run > %t/imports.out | ||
| // RUN: %diff %t/imports.out %t/imports.expected | ||
|
|
||
| //--- imports.expected | ||
| imports for TMP_DIR/test.swift: | ||
| Swift | ||
| __ObjC | ||
| _StringProcessing | ||
| _SwiftConcurrencyShims | ||
| _Concurrency | ||
| A | ||
| imports for A.foo: | ||
| imports for @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift: | ||
| Swift | ||
| __ObjC | ||
| lifetimebound | ||
| ptrcheck | ||
| _StringProcessing | ||
| _SwiftConcurrencyShims | ||
| _Concurrency | ||
|
|
||
| //--- macro-expansions.expected | ||
| @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift | ||
| ------------------------------ | ||
| /// This is an auto-generated wrapper for safer interop | ||
| @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_disfavoredOverload public func foo(_ p: Span<Int32>, _ x: UnsafeMutablePointer<no_module_record_t>!) { | ||
| let len = Int32(exactly: p.count)! | ||
| return unsafe p.withUnsafeBufferPointer { _pPtr in | ||
| return unsafe foo(len, _pPtr.baseAddress!, x) | ||
| } | ||
| } | ||
| ------------------------------ | ||
|
|
||
| //--- test.swift | ||
| import A | ||
|
|
||
| func test(s: Span<a_t>, x: UnsafeMutablePointer<no_module_record_t>) { | ||
| unsafe foo(s, x) | ||
| } | ||
|
|
||
| //--- bridging.h | ||
| // claim this header as part of bridging header, making it not belong to a module | ||
| #include "no-module.h" | ||
|
|
||
| //--- no-module.h | ||
| #pragma once | ||
| typedef int no_module_t; | ||
| struct no_module_record_t { | ||
| int placeholder; | ||
| }; | ||
|
|
||
| //--- a.h | ||
| #include <ptrcheck.h> | ||
| #include <lifetimebound.h> | ||
| // this module header now depends on a decl with no module | ||
| #include "no-module.h" | ||
| typedef int a_t; | ||
| void foo(int len, const int * __counted_by(len) p __noescape, struct no_module_record_t *x); | ||
|
|
||
| //--- module.modulemap | ||
| module A { | ||
| header "a.h" | ||
| } |
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
Oops, something went wrong.
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.
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
UnsafeBufferPointerand 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
UnsafeBufferPointerin the imported signature? Not that I know of