-
Notifications
You must be signed in to change notification settings - Fork 10.5k
std::function -> llvm::function_ref for some non-escaping params. #16251
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
@swift-ci please test |
@swift-ci Please ASAN test |
@swift-ci Please smoke test compiler performance |
lib/AST/Pattern.cpp
Outdated
public: | ||
|
||
WalkToVarDecls(const std::function<void(VarDecl*)> &fn) | ||
WalkToVarDecls(llvm::function_ref<void(VarDecl *)> fn) |
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.
Changing a field is dangerous because if someone passes a lambda expression it won't work. I know some of the SourceKit folks have hit this in the past and have decided that it's better to just use the std::function so that it won't regress in the future. (It should be safe for all the regular function arguments, though.)
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.
This particular field is only used inside another function that passes a function_ref
it receives as a parameter, so I think it's okay, but I can revert this if you think it's not worth the risk of being misused in future (although this code hasn't been touched for 3 years).
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.
Yeah, I assumed that was the case. I'm on the fence about it, but I know elsewhere in the codebase we use std::function
even though we don't really need to in the same way, just because it's safer. I feel like until we have a good way to catch the use of lambda expressions, we should stick with the safe idiom unless it's a noticeable performance hit.
@swift-ci please smoke test |
(For future reference, the ASAN test and full test above both passed, and the only change from then was deleting the modification to |
std::function
may need to allocate, which is totally unnecessary for non-escaping functions.llvm::function_ref
covers this perfectly.