Repository navigation
Conversation
|
To my untrained (for the compiler) eye, this looks fine, but maybe someone else needs to review it. |
|
This PR is stale because it has been open for 30 days with no activity. |
|
We get some extra bytecode: On main ends with With the PR: Can that be avoided? Can you create some statistics for |
Thanks for catching this. I moved the merge to
|
|
The implementation looks good to me, but I suspect there is not gain. Only a few opcodes are converted to the borrowed version. In addition: when we convert to |
In existing CFG optimization logic, for equivalent conditional code, ternary expressions do not get the
LOAD_FASToptimization applied, unlike standardif/elsestatements:The return in the
if/elsebranch is successfully optimized toLOAD_FAST_BORROW, whereas theelsebranch in the ternary expression can only generate a standardLOAD_FAST.Before being passed to
optimize_load_fast(the entry point for the reference checking phase), the control flow graphs of the two structures exhibit subtle differences:For
if/else, itselsebranch naturally belongs to a single basic block, containing both the reference being loaded and the return instruction that consumes that reference:Because the local reference is consumed directly within this basic block,
optimize_load_fastcan determine that the safety constraint is satisfied and convert it into a prioritizedLOAD_FAST_BORROW.However, for a trinary expression, due to the structural characteristics of the AST, the code generator produces the following CFG, which prevents
optimize_load_fastfrom performing the optimization:So this PR extends the inlining capabilities of
basicblock_inline_small_or_no_lineno_blocks:RETURN_VALUE), we can still safely copy it directly and inline it at the end of the underlying block.LOAD_FASTis not always converted toLOAD_FAST_BORROWin abasicblock#145629