Hi V8 devs, I saw a few functions in src/builtin/builtin-*-gen.cc and src/code-stub-assembler.h uses quite a few std::function as a parameter, then pass lambda function to these functions to avoid code duplication as much as possible. std::function was used because raw function pointer can't accept lambda function.
However, because std::function is really powerful, it comes with a cost in terms of code size and overhead when calling std::function. I am working on introducing function_view to src/base, a lightweight callable reference that can accept normal and lambda function. function_view is adapted from [1] <https://vittorioromeo.info/index/blog/passing_functions_to_functions.html>. I have changed it so that it can be compiled with C++11, which is the minimum compiler support requirement to build Chromium. Note: The callable itself must be alive longer or equal to the life time of function_view object. Therefore, function_view is not a universal replacement for the general-purpose std::function. If you need to store lambda function as class property, std::function is still needed. Use case like [2] <https://cs.chromium.org/chromium/src/v8/src/compiler/code-assembler.h?type=cs&l=601> cannot be replaced with function_view. Chromium do have a very powerful library to store callback at https://cs.chromium.org/chromium/src/base/bind_internal.h (std::function is banned in Chromium). Plan: - Add base::function_view implementation to src/base/functional.h - Convert std::function to base::function_view in src/builtin/builtin-*-gen.cc and maybe other parts of src/* if appropriate. Usage of std::function in test/* will be ignored. - Add documentation. - Add unittest. src/compiler/s390/instruction-selector-s390.cc also uses a lot of std::function + lambda, but because I can't test on this platform myself, I don't feel safe to change it. It looks like dry run does not have bot for s390. WIP CL: https://chromium-review.googlesource.com/c/505653/ [1]: https://vittorioromeo.info/index/blog/passing_functions_to_functions.html [2]: https://cs.chromium.org/chromium/src/v8/src/compiler/code-assembler.h?type=cs&l=601 Sincerely, Rong Jie -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
