-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[TypeChecker] Implement limited set of conversions between Swift and C pointers #37956
[TypeChecker] Implement limited set of conversions between Swift and C pointers #37956
Conversation
|
@swift-ci please build toolchain |
|
Linux Toolchain (Ubuntu 16.04) Install command |
7051c5a
to
2351391
Compare
|
@swift-ci please test |
|
Build failed |
2351391
to
a10d35c
Compare
|
@swift-ci please test |
|
Build failed |
|
@swift-ci please test Linux platform |
|
Build failed |
|
@swift-ci please test macOS platform |
|
Build failed |
a10d35c
to
b145dc1
Compare
|
@swift-ci please clean test |
1 similar comment
|
@swift-ci please clean test |
|
@swift-ci please build toolchain |
|
@swift-ci build toolchain |
|
@swift-ci please build toolchain |
|
Linux Toolchain (Ubuntu 16.04) Install command |
|
macOS Toolchain Install command |
d89463d
to
0ec00f5
Compare
0ec00f5
to
4690092
Compare
Following pointer conversions are supported in argument positions (when referencing C/ObjC functions):
- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> -> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
…rgument to C/ObjC imported decl
Allow following conversions in argument positions
(applies only to call to imported C/ObjC declarations):
- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> <-> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
…onal types Support Swift -> C pointer conversions even if argument required a value to optional promotion or is optional.
Make sure that conversions are properly supported when arguments either is wrapped in an optional type or requires a value-to-optional promotion because parameter is optional pointer.
…ts only on Darwin
…ication into a separate method
…nversions Just like other implicit conversions - always prefer solutions with the lowest possible number of them.
This is a skeleton of a fix that would be used to diagnose situations when Swift -> C pointer conversion was attempted on a Swift function.
…sion
Diagnose situations where Swift -> C pointer implicit conversion
is attempted on a Swift function instead of one imported from C header.
```swift
func test(_: UnsafePointer<UInt8>) {}
func pass_ptr(ptr: UnsafeRawPointer) {
test(ptr) // Only okay if `test` was an imported C function.
}
```
…s for optionals Wait for a value-to-optional promotion or optional-to-optional conversion to happen before attempting Swift -> C pointer conversion.
Detect and diagnose situations when Swift -> C pointer conversion is unsupported due to method not being imported from C header.
4690092
to
a9fdb7a
Compare
|
@swift-ci please clean test |
|
Build failed |
|
@swift-ci please test Linux platform |
|
@swift-ci please smoke test |
|
I'm going to land changes to CHANGELOG separately. |
Allow following pointer conversions in argument positions to C/ObjC imported calls:
Allow implicit conversion to
Unsafe[Mutable]Pointer<UInt8>orUnsafe[Mutable]Pointer<Int8>when the argument type is eitherUnsafe[Mutable]Pointer<T>orUnsafe[Mutable]RawPointer.Allow implicit conversion between signed and unsigned variants of trivial integer types:
e.g.
Unsafe[Mutable]Pointer<Int64>to/fromUnsafe[Mutable]Pointer<UInt64>Resolves: SR-10246