[swift-dev] How should NSArray<void(^)(void)>* be imported?
Jacob Bandes-Storch
jtbandes at gmail.com
Fri Mar 4 00:12:43 CST 2016
I see, thanks for the clarification. How is it, then, that properties whose
type is void(^)(void) already work fine?
On Thu, Mar 3, 2016 at 12:16 PM Joe Groff <jgroff at apple.com> wrote:
> On Mar 3, 2016, at 10:26 AM, Jacob Bandes-Storch <jtbandes at gmail.com>
> wrote:
>
> Is another hack the way to go, or should it be correctly imported as
> [@convention(block) () -> ()] (which I think would be
> _isBridgedToObjectiveC already)?
>
>
> Bridging to @convention(block) is probably more practical, since we'd
> otherwise need to be able to thunk an arbitrary call signature at runtime.
> However, @convention(block) is still a structural type, so it would need
> special case handling similar to _BridgeableMetatype to be able to feed a
> _BridgedToObjectiveC conformance into the runtime.
>
> -Joe
>
>
> On Thu, Mar 3, 2016 at 9:08 AM, Joe Groff <jgroff at apple.com> wrote:
>
>>
>> On Mar 3, 2016, at 2:23 AM, Jacob Bandes-Storch via swift-dev <
>> swift-dev at swift.org> wrote:
>>
>> I'm interested in fixing a pet peeve of mine:
>> https://bugs.swift.org/browse/SR-772
>>
>> The failing assertion is in Array._forceBridgeFromObjectiveC, namely
>> Swift._isBridgedToObjectiveC(Element.self). Element is plain ol "() ->
>> ()", but probably should be @convention(block) since it was imported from
>> void(^)(void).
>>
>> I've started tracing through the importer, and I found that
>> `adjustTypeForConcreteImport` is enforcing
>> FunctionTypeRepresentation::Swift because the ImportKind is BridgedValue —
>> this is hardcoded in the call to importType for the type parameters to
>> NSArray (and NSDictionary and NSSet) in
>> SwiftTypeConverter::VisitObjCObjectPointerType.
>>
>> Are the Foundation collection classes only temporarily special-cased
>> here, until Obj-C generics are generally supported? Is someone working on
>> this in the near future?
>>
>> If this worked correctly, would we expect to see "var executionBlocks:
>> [@convention(block) () -> ()]" ? If so, would this be best achieved by
>> passing a different ImportKind, possibly introducing a new ImportKind, or
>> some other solution?
>>
>> I'm guessing that it doesn't make sense for () -> () to be
>> _ObjectiveCBridgeable, but either way I'm not sure where the
>> _isBridgedToObjectiveC implementation for blocks would come from.
>>
>> Bumblingly,
>> Jacob
>>
>>
>> There's a hack to handle NSArray<Class> * bridging to [AnyObject.Type],
>> which has similar problems. Look around for _BridgeableMetatype.
>>
>> -Joe
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160304/2ea8cca6/attachment.html>
More information about the swift-dev
mailing list