-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SILGen: Emit a closure literal in a function conversion as the converted type. #58651
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
SILGen: Emit a closure literal in a function conversion as the converted type. #58651
Conversation
@swift-ci Please test |
@swift-ci Please benchmark |
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.
LGTM
lib/SILGen/SILGenExpr.cpp
Outdated
// | ||
// TODO: Move this up when we can emit closures directly with C calling | ||
// convention. | ||
if (isa<AbstractClosureExpr>(e->getSubExpr()) |
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 think we can at least do getSemanticsProvidingExpr()
here
@swift-ci Please benchmark |
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibs |
…ted type. Closure literals are sometimes type-checked as one type then immediately converted to another type in the AST. One particular case of this is when a closure body never throws, but the closure is used as an argument to a function that takes a parameter that `throws`. Emitting this naively, by emitting the closure as its original type, then converting to throws, can be expensive for async closures, since that takes a reabstraction thunk. Even for non-async functions, we still want to get the benefit of reabstraction optimization for the closure literal through the conversion too. So if the function conversion just add `throws`, emit the closure as throwing, and pass down the context abstraction pattern when emitting the closure as well.
4a741fb
to
482cc8a
Compare
@swift-ci Please test |
Closure literals are sometimes type-checked as one type then immediately converted to another
type in the AST. One particular case of this is when a closure body never throws, but the closure
is used as an argument to a function that takes a parameter that
throws
. Emitting this naively,by emitting the closure as its original type, then converting to throws, can be expensive for
async closures, since that takes a reabstraction thunk. Even for non-async functions, we still want
to get the benefit of reabstraction optimization for the closure literal through the conversion too.
So if the function conversion just add
throws
, emit the closure as throwing, and pass down thecontext abstraction pattern when emitting the closure as well.