Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

transform return: Removed an optimization that broke some table literals

This optimization would normally remove an unnecessary variable, such as
the one in the following generated PIR:

set $P18, $P17[k_Foo]
new $P19, "LuaNil"
.tailcall $P18()

In the above snippet, $P19 is not used, so it can be removed without
harm. However, there are instances where this variable is used. Consider
the following code:

function Foo()
	return 42
end

return { Foo() }

In this case, the following PIR should be generated:

new $P21, "LuaNil"
($P21 :slurpy) = $P20()
.tailcall tconstruct($P18, $P19, $P21 :flat)

In this case, the register that initially contains a nil value is
actually used, so it cannot be optimized away.
  • Loading branch information...
commit 8ea8e825c4a932af83b87a08e1d47cd858d5634f 1 parent 4308744
@dafrito dafrito authored
Showing with 0 additions and 4 deletions.
  1. +0 −4 lua/POSTGrammar.tg
View
4 lua/POSTGrammar.tg
@@ -716,10 +716,6 @@ transform return (PAST;Op) :language('PIR') {
unless $I0 goto L3
if arglist goto L4
$P0.'pirop'('tailcall')
- # remove useless new LuaNil
- $P1 = cpost.'pop'()
- $P2 = cpost.'pop'()
- cpost.'push'($P1)
.return (ops)
L4:
$S1 = '(' . $S0
Please sign in to comment.
Something went wrong with that request. Please try again.