Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

gonzalolarralde
Copy link
Contributor

The following declarations that were @escaping (default, actually) before SE-0103 and that I think they should remain @escaping.

And finally,

along with

Finally, the rescue parameter in DispatchQueue._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.

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

@mwwa mwwa Aug 19, 2016

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.

Copy link
Contributor

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.

@MadCoder
Copy link
Contributor

@MMWa do we have the similar patch for the compiler?
@gonzalolarralde please squash in a single commit

@gonzalolarralde
Copy link
Contributor Author

@MadCoder Done

@gonzalolarralde
Copy link
Contributor Author

gonzalolarralde commented Sep 23, 2016

Based on this swift#4905 and this SR-2444 I will remove @escaping from the optional block, as they're already escaping by default, and there's no way to mark them as no-escape.

The only remaining change will be: src/swift/Queue.swift:238.

@gonzalolarralde
Copy link
Contributor Author

gonzalolarralde commented Sep 28, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants