Commit ccaeb11f authored by Luca Bataillard's avatar Luca Bataillard
Browse files

fix general inlining

parent 4399af88
...@@ -269,9 +269,9 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }] ...@@ -269,9 +269,9 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val args = replaceArgs(oldArgs, s) val args = replaceArgs(oldArgs, s)
if (s.cEnv.contains(cntName)) { if (s.cEnv.contains(cntName)) {
val cnt = copyC(s.cEnv(cntName), s.aSubst, s.cSubst) val savedCnt = s.cEnv(cntName)
val newState = s.withASubst(cnt.args, args) val newState = s.withASubst(savedCnt.args, args)
inlineT(cnt.body)(newState) copyT(savedCnt.body, newState.aSubst, newState.cSubst)
} else { } else {
AppC(cntName, args) AppC(cntName, args)
} }
...@@ -284,14 +284,11 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }] ...@@ -284,14 +284,11 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
funName match { funName match {
case AtomN(n) if s.fEnv.contains(n) => { case AtomN(n) if s.fEnv.contains(n) => {
val oldFun = s.fEnv(n) val savedFun = s.fEnv(n)
val notUsedAsValue = s.census.get(oldFun.name).fold(false)(count => count.asValue == 0)
val nonRecursive = notUsedAsValue && !census(oldFun.body).contains(oldFun.name) if (sameLen(savedFun.args, args)) {
val newState = s.withASubst(savedFun.args, args).withCSubst(savedFun.retC, retC)
if (nonRecursive && sameLen(oldFun.args, args)) { copyT(savedFun.body, newState.aSubst, newState.cSubst)
val fun = copyF(oldFun, s.aSubst, s.cSubst)
val newState = s.withASubst(fun.args, args).withCSubst(fun.retC, retC)
inlineT(fun.body)(newState)
} else { } else {
AppF(funName, retC, args) AppF(funName, retC, args)
} }
......
(defrec fact
(fun (x) (if (@= x 0) 1 (@* x (fact (@- x 1))))))
(@byte-write (fact 5))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment