-
Notifications
You must be signed in to change notification settings - Fork 473
More changes for SE-0103 (@noescape by default). #157
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
Conversation
internal typealias _DispatchBlock = @convention(block) () -> Void | ||
internal typealias dispatch_block_t = @convention(block) () -> Void | ||
internal typealias _DispatchBlock = @escaping @convention(block) () -> Void | ||
internal typealias dispatch_block_t = @escaping @convention(block) () -> Void |
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.
that seems wrong, dispatch_sync() takes a dispatch_block_t and is definitely not escaping
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.
I get your point, but for what I understand that is a change that should concern the C part of libdispatch. Today dispatch_block_t
is being declared in object.h
like this:
typedef void (^dispatch_block_t)(void);
and internal typealias dispatch_block_t
doesn't seem to be more than a redeclaration of the existing C type. dispatch_block_t
is being used both in dispatch_sync
and dispatch_async
for that matter, that means that it can be both @escaping
and @noescape
, and from both options @escaping
is not the correct, but the safe option.
A different approach may be having a dispatch_noescape_block_t
with __attribute__((noescape))
, but that will create a difference with the darwin API.
For what I understand here, internal typealias dispatch_block_t
is just briging the C type oid (^dispatch_block_t)(void)
to the Swift scope, and it's being only used internally.
Am I getting this wrong? What would be the correct solution given the context?
Thanks.
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.
my point is that I find it troubling to annotate the type, as if the overlay has to do a
dispatch_sync(q) { ... }
some day for some weird reason, we will get a poorer performance for it. The importer should already have annotated the C functions (that are properly __attribute__((noescape))
where it makes sense) properly already anyway, so I think the one on dispatch_block_t is wrong.
@mwwa do I make sense?
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.
@gonzalolarralde Does the @noescape
(the C markup) from dispatch_sync
itself still override the declaration of the block type itself? If so I suspect we're no worse than we were before.
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.
Also note that @noescape
is now deprecated, and no longer has any functional effect.
@MMWa do we have the similar patch for the compiler? |
e780e93
to
4aeeea1
Compare
@MadCoder Done |
4aeeea1
to
3a0f8d5
Compare
Based on this swift#4905 and this SR-2444 I will remove The only remaining change will be: |
3a0f8d5
to
48baf82
Compare
48baf82
to
ec4205a
Compare
@maccoder Ok, done! I think the entire thing is probably no longer relevant, as the only change now is that line in that internal method. |
The following declarations that were
@escaping
(default, actually) beforeSE-0103
and that I think they should remain@escaping
.dispatch_data_create(…, destructor)
along withDispatchData.Deallocator.custom
dispatch_queue_set_specific(…, destructor)
(there's no associated typealias / parameter for this one, it's just being called withQueue._destructDispatchSpecificValue
as parameter)And finally,
dispatch_source_set_event_handler(…, handler)
dispatch_source_set_cancel_handler(…, handler)
dispatch_source_set_registration_handler(…, handler)
along with
DispatchSourceHandler
_DispatchBlock
Finally, the
rescue
parameter inDispatchQueue._syncHelper
was marked as@escaping
due to a manual migration, but there's nothing keeping a reference to it.Please let me know if this patch works for you, or if there's anything that needs to be changed. /cc @slavapestov @dgrove-oss
Thanks.