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 }]
val args = replaceArgs(oldArgs, s)
if (s.cEnv.contains(cntName)) {
val cnt = copyC(s.cEnv(cntName), s.aSubst, s.cSubst)
val newState = s.withASubst(cnt.args, args)
inlineT(cnt.body)(newState)
val savedCnt = s.cEnv(cntName)
val newState = s.withASubst(savedCnt.args, args)
copyT(savedCnt.body, newState.aSubst, newState.cSubst)
} else {
AppC(cntName, args)
}
......@@ -284,14 +284,11 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
funName match {
case AtomN(n) if s.fEnv.contains(n) => {
val oldFun = 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 (nonRecursive && sameLen(oldFun.args, args)) {
val fun = copyF(oldFun, s.aSubst, s.cSubst)
val newState = s.withASubst(fun.args, args).withCSubst(fun.retC, retC)
inlineT(fun.body)(newState)
val savedFun = s.fEnv(n)
if (sameLen(savedFun.args, args)) {
val newState = s.withASubst(savedFun.args, args).withCSubst(savedFun.retC, retC)
copyT(savedFun.body, newState.aSubst, newState.cSubst)
} else {
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