Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions effekt/jvm/src/test/scala/effekt/core/VMTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ class VMTests extends munit.FunSuite {

val duality_of_compilation: Seq[(File, Option[Summary])] = Seq(
examplesDir / "benchmarks" / "duality_of_compilation" / "erase_unused.effekt" -> Some(Summary(
staticDispatches = 21,
staticDispatches = 6,
dynamicDispatches = 0,
patternMatches = 0,
branches = 21,
pushedFrames = 6,
poppedFrames = 6,
allocations = 11,
branches = 6,
pushedFrames = 1,
poppedFrames = 1,
allocations = 0,
closures = 0,
variableReads = 0,
variableWrites = 0,
Expand Down Expand Up @@ -1089,14 +1089,14 @@ class VMTests extends munit.FunSuite {
resumes = 0
)),
examplesDir / "benchmarks" / "nofib" / "constraints.effekt" -> Some(Summary(
staticDispatches = 891409,
dynamicDispatches = 60355,
patternMatches = 1382034,
branches = 432810,
pushedFrames = 794941,
poppedFrames = 794941,
allocations = 852789,
closures = 10,
staticDispatches = 670319,
dynamicDispatches = 31053,
patternMatches = 1012640,
branches = 297136,
pushedFrames = 602935,
poppedFrames = 602935,
allocations = 642347,
closures = 6,
variableReads = 0,
variableWrites = 0,
resets = 0,
Expand Down Expand Up @@ -1149,16 +1149,16 @@ class VMTests extends munit.FunSuite {
resumes = 0
)),
examplesDir / "benchmarks" / "nofib" / "integer.effekt" -> Some(Summary(
staticDispatches = 4026,
dynamicDispatches = 792,
patternMatches = 2928,
branches = 1079,
pushedFrames = 3080,
poppedFrames = 3080,
allocations = 4532,
closures = 22,
variableReads = 924,
variableWrites = 792,
staticDispatches = 182,
dynamicDispatches = 0,
patternMatches = 135,
branches = 50,
pushedFrames = 104,
poppedFrames = 104,
allocations = 206,
closures = 0,
variableReads = 42,
variableWrites = 36,
resets = 0,
shifts = 0,
resumes = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ class Deadcode(reachable: Map[Id, Usage])

private def unused(id: Id): Boolean = !used(id)

/** A call that cannot be observed: the callee captures nothing, and neither does anything passed to it. */
private def isPureCall(stmt: Stmt): Boolean = stmt match {
case Stmt.App(callee, _, _, bargs) => callee.capt.isEmpty && bargs.forall(_.capt.isEmpty) && stmt.tpe != Type.TBottom
case _ => false
}

override def rewrite(stmt: Stmt): Trampoline[Stmt] = stmt match {
// Remove local unused definitions
case Stmt.Def(id, block, body) if unused(id) => rewrite(body)
case Stmt.Let(id, binding, body) if unused(id) => rewrite(body)

// Remove local unused 'val's as long as they are pure calls.
case Stmt.Val(id, binding, body) if unused(id) && isPureCall(binding) => rewrite(body)

case Stmt.Reset(body) =>
rewrite(body).map {
case BlockLit(tparams, cparams, vparams, List(prompt), body) if unused(prompt.id) => body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,18 @@ object StaticArguments {
case _ => false
}
}
lazy val read = body.free.freeIds // TODO: use Free.contains from #1453; reconsider free vs capt
val isValueStatic = vparams.zipWithIndex.collect {
case (param, index) => vargs.nonEmpty && vargs.map(args => args(index)).forall {
case (param, index) => (vargs.nonEmpty && vargs.map(args => args(index)).forall {
case ValueVar(other, _) => param.id == other
case _ => false
}
}) || !read.contains(param.id) // vparam not read by body is vacuously static
}
val isBlockStatic = bparams.zipWithIndex.collect {
case (param, index) => bargs.nonEmpty && bargs.map(args => args(index)).forall {
case (param, index) => (bargs.nonEmpty && bargs.map(args => args(index)).forall {
case BlockVar(other, _, _) => param.id == other
case _ => false
}
}) || !read.contains(param.id) // bparam not read by body is vacuously static
}
id -> IsStatic(isTypeStatic, isValueStatic, isBlockStatic)
}.toMap
Expand Down
Loading