[swift-dev] [RFC] UnsafeBytePointer API for In-Memory Layout

Andrew Trick atrick at apple.com
Thu May 12 20:56:20 CDT 2016


> On May 12, 2016, at 9:27 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
> Thoughts on the diff:

https://github.com/atrick/swift/tree/unsafeptr_convert <https://github.com/atrick/swift/tree/unsafeptr_convert>

> - What was the thought behind putting UnsafeBytePointer in PointerTypeKind? OpaquePointer isn’t there, and I’m concerned about places that test if something’s a pointer by checking that the pointee type is non-null (by far the common pattern).

In general I wanted UnsafeBytePointer to stand-in for UnsafePointer<Void> throughout the type system and handle most of the same implicit conversions. Specifically, I wanted getAnyPointerElementType to do the same thing as UnsafePointer<Void> and return an empty tuple pointee type so that the calling code could be reused. Also, I thought that supporting PointerToPointerExpr was necessary.

The only extra burden of doing this that I could find was that getPointerPointeePropertyDecl may return null. The only code that calls this is emitStoreToForeignErrorSlot.

I'm very open to alternate implementations, especially once the proposal is accepted.

> - The PrintAsObjC test can’t possibly pass as is—it’s checking that one pointer is const and the other isn’t. I’m guessing there’s actually more work to do here.

That's right. PrintAsObjC is one of several tests that are still failing. Before fixing them I want to:

- get reassurance that we really want to replace the the imported type of 'void*'. Then I'll introduce an UnsafeMutableBytePointer.

- determine precisely which implicit conversions we want to allow and update test cases accordingly.

These are the tests that were failing on my branch (last time I succesfully rebased):

POSIX.swift - requires String -> UnsafeBytePointer arg conversion
UnsafeBufferPointer.swift - UnsafePointer conversion rules?
UnsafePointer.swift - UnsafePointer conversion rules?
ClangModules/* - UnsafePointer conversion rules?
IRGen/objc_pointer - name mangling
SDK/c_pointers - [Double] to UnsafeBytePointer
SDK/objc_inner_pointer - [UInt8] to UnsafeBytePointer
Parse/pointer_conversion - 'UnsafePointer<Int>' to 'UnsafeBytePointer'
PrintAsObjC/classes.swift - void* export
SILGen/objc_currying - name mangling
SILGen/pointer_conversion - String to UnsafeBytePointer
SourceKit/DocSupport - formatting
sil-opt/emit-sib. - mangling
OpenCLSDKOverlay - [Float] to UnsafeBytePointer

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160512/1165e3f8/attachment.html>


More information about the swift-dev mailing list