Skip to content

[Async Refactoring] Better handle bool flag parameter bindings #39159

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

Merged
merged 4 commits into from
Sep 7, 2021

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Sep 3, 2021

If we have a known bool flag parameter, drop it from the success parameters being bound in a refactored await call, as the async variant drops it. And in the fallback case, add a binding for it in the success and error block.

rdar://81896460

@hamishknight
Copy link
Contributor Author

@swift-ci please test

Comment on lines 7216 to 7217
SmallVector<const ParamDecl *, 4> Scratch;
auto SuccessBindings = CallbackParams.getSuccessParamsToBind(Scratch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is the only use I'd prefer just returning the SmallVector from getSuccessParamsToBind.

And not sure if this part is worth it or not but...

  • Could name SuccessBindings just Bindings
  • Add an ArrayRef SuccessBindings of Bindings
  • Remove AllBindings and just add ErrParam to Bindings in the if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, returning a SmallVector directly would mean the callee would have to specify the inline buffer size, which feels odd – maybe we could return a llvm::TinyPtrVector or std::vector?

Regarding mutating a single Bindings vector directly, I tend to prefer reducing mutability where I can, but this is all pretty localised so I don't feel too strongly about it

Copy link
Contributor Author

@hamishknight hamishknight Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up generalising this logic to not need the mutation. I did switch over using llvm::TinyPtrVector, I don't really feel too strongly about the return type tho

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TinyPtrVector is optimised for 0/1 right? I guess that is probably almost always true for the success/error. I'm fine with specifying the inline buffer size in the return type, but I don't really mind. Personally I'd still use SmallVector<Thing, 0> over a vector, even if I was returning it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah TinyPtrVector is optimized for the single element (and empty) case, which as you say is fairly likely for the success/error params. Out of curiosity, what benefits would SmallVector<Thing, 0> have over a regular vector?

Refactor some closure parameter handling logic
into a new ClosureCallbackParams type, which lets
us clean up some of the parameters passed to
CallbackClassifier, and better distinguish between
an error param and a Result param.
If we have a known bool flag parameter, drop it
from the success parameters being bound in a
refactored await call, as the async variant drops
it.

rdar://81896460
Make sure to convert any references to parameters
that get dropped in the fallback case to
placeholders.
Generalize the logic to handle different BlockKinds,
and add binding logic that lets us assign `true` or
`false` to the given bool success param in the
fallback case.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit 97a1653 into swiftlang:main Sep 7, 2021
@hamishknight hamishknight deleted the conditions-apply branch September 7, 2021 12:35
@hamishknight hamishknight changed the title [Async Refactoring] Drop bool flag parameter binding [Async Refactoring] Better handle bool flag parameter bindings Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants