-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[PrintAsObjC] print __attribute__((noescape)) in Obj-C headers #4438
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
a9703ef to
a44fee7
Compare
|
@jrose-apple — based on CODE_OWNERS I think you're probably the best one to review this, too. 🙇 |
|
I'm not happy with adding the extra "is parameter position" flag, but maybe it's unavoidable. What about typealiases, though? |
|
It's probably also good to have a test for nested |
|
(And thank you for working on this!) |
|
What about typealiases? I can't test right now, but I imagine they're not allowed to be noescape. Only when used in a function param would it have any meaning, so you'd write |
|
Yeah, that's all I meant. Both Swift typealiases and imported Objective-C typedefs now allow Maybe instead of passing down the "are we in parameter position" flag, the logic that iterates over parameters can handle it? That does mean putting the logic in two places (once for function/block types, once for method parameters) but that's not the end of the world. |
|
(and would handle typealiases and other alternate spellings automatically) |
|
That's kinda how it's already done: the logic iterating over function parameters and method parameters are the only places where It's messy because in printing out param types, the code just calls |
|
(It would've been nicer if TypeVisitor could be given default values for its additional args, but I don't think that's supported.) |
|
Friendly bump 😄 |
|
I was remembering that it was okay to put if (auto fnTy = argTy->getAs<AnyFunctionType>())
if (fnTy->getExtInfo().isNoEscape())
print("SWIFT_NOESCAPE ");I feel like that's cleaner, but what do you think? |
|
Hmm, that's interesting, and would certainly be less code change. But would
|
|
Ah, yep, sorry. |
|
OK, thanks for the tip. I'll update the PR tonight. |
e66facc to
d14dd6b
Compare
|
Thanks a lot for the feedback. I'm much happier with this version. @swift-ci please smoke test |
|
missed changing one file to the new style. @swift-ci please smoke test |
|
Thanks! One more thing to test, unless I missed it: an imported typedef for a block. That should come out as Oh, and what do you think about using a two-element enum instead of a bool for "isFunctionParameter"? Then we don't need the comments. |
|
It looks like typealiases are just fully expanded right now: https://github.com/apple/swift/pull/4438/files#diff-ab50a31c33e58d3c979a7680a7dec033R92 Is that unexpected? |
|
Swift typealiases are fully expanded, but those defined in Objective-C shouldn't be. |
|
@jrose-apple Hmm, actually this is broken right now: Mostly, I think, due to an existing limitation https://bugs.swift.org/browse/SR-2520 which @slavapestov mentioned in a FIXME |
|
Also, it looks like |
|
I suppose the possible courses of action are:
Thoughts? |
|
If I'm understanding you correctly, I think you've found two different issues here:
For the first issue, I think a passing test with a FIXME is good enough, as long as we test imported typedefs with and without |
|
Yeah, that's accurate, at least as far as I could figure out reading the code last night. Here's where typedef decls are imported; it calls getUnderlyingType() and imports that type: To import the block pointer type it just imports the underlying function pointer: Then, here's where parameters of function pointer types are imported: At this point it seems like the noescape information is not available. Other places which use it are checking |
|
Okay, so I guess for now we should be treating all parameters in imported block typedefs as escaping. |
c229a0a to
638684e
Compare
|
OK, I've added a new test file to capture this, with FIXMEs and notes about what I think the real expected output should be, once the issues get fixed. #gloriousfuture 🌈 (I filed SR-2529 and SR-2520 to track them, and linked to these from the source code / tests.) I also found that I wasn't handling optional params properly, so I added a @swift-ci please smoke test |
|
@shahmishal Is this a known issue? The OS X smoke test seemed to start and immediately fail with |
|
@jtbandes yes this is known issue. It re-triggers with the new and correct sha. |
|
Not sure what I'm doing wrong here. For some reason, other test files with practically the same lit directives aren't generating this |
|
Found it; I was missing |
|
@swift-ci smoke test linux |
|
I think we're good. Thanks, Jacob! |
|
Thanks for all your help & patience! 😃 |
Print out
(A) -> BasSWIFT_NOESCAPE B ([*^] «nullability»)(A)if it's the type of a function param, unless marked with@escaping.Resolves SR-2406 filed by @jrose-apple.
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.