Closed Mercerenies closed 3 years ago
With everything that's happened since I first opened this issue, I'm calling this one "won't fix". It adds a ton of complexity and involves a lot of changes to fairly fundamental code. The optimizations in question are not that extreme, and ideally the optimizer could take care of them long-term. Closing.
This is more technical than anything, but it would be nice. Currently, if we have an
if
statement as the last line of a function as followsThen it compiles to a temporary variable
When, really, for things like
return
(stmt_wrapper::Return
) or simple assignment (stmt_wrapper::AssignToExpr
), we can simply do the assignment or return in both branches.So here's my somewhat sizeable proposal. Currently,
compile_stmt
delegates tocompile_expr
. What if we got rid of the latter? Then everything callscompile_stmt
and more complicated things like function call arguments can pass a specialStmtWrapper
that understands to generate and use a temporary variable, whereas for simple wrappers, if statements and things can split without the temporary.