Closed zemse closed 1 month ago
We already do this automatically: https://github.com/ethereum/solidity/blob/develop/libevmasm/Inliner.h#L20 (evmasm) https://github.com/ethereum/solidity/blob/develop/libyul/optimiser/ExpressionInliner.h#L35-L46 (yul)
Adding an actual keyword is not at the top of the list of priorities honestly. Ultimately, in most language that have this, the inline
keyword is really just a suggestion to the compiler that it should if possible inline, instead of that it must inline.
Also, we have to be especially careful to strike a fine balance between optimizing for runtime performance (skip jump instructions) versus optimizing for code size, i.e. deploy time code, which the inliner steps already do.
Related: #12782.
Abstract
Currently, Solidity compiles functions into code sections and then JUMP instruction is used to go into the function and return to the parent code section.
If functions can be declared to be inlined, then that can enable runtime gas optimizations at the cost of bytecode size. Solidity could do this automatically, or allow users to explicitly mark a function that should be inlined. Small function logic makes sense to be inlined.
Examples of this functionality in other languages:
Rust Inlining Inlining - The Rust Performance Book Huff Macros Huff by Example | Huff Language
Specification
Introduce a inline keyword.
It would also be great if inlining is possible for yul code.
Backwards Compatibility
None