optimizer bug: don't remove empty subroutine if it's referenced. Fixes #67

This commit is contained in:
Irmen de Jong 2021-10-20 22:25:10 +02:00
parent df2d5c6585
commit 41e40cad03

View File

@ -81,10 +81,6 @@ internal class UnusedCodeRemover(private val program: Program,
val forceOutput = "force_output" in subroutine.definingBlock.options() val forceOutput = "force_output" in subroutine.definingBlock.options()
if (subroutine !== program.entrypoint && !forceOutput && !subroutine.inline && !subroutine.isAsmSubroutine) { if (subroutine !== program.entrypoint && !forceOutput && !subroutine.inline && !subroutine.isAsmSubroutine) {
if(callgraph.unused(subroutine)) { if(callgraph.unused(subroutine)) {
if(!subroutine.definingModule.isLibrary)
errors.warn("removing unused subroutine '${subroutine.name}'", subroutine.position)
return listOf(IAstModification.Remove(subroutine, subroutine.definingScope))
}
if(subroutine.containsNoCodeNorVars) { if(subroutine.containsNoCodeNorVars) {
if(!subroutine.definingModule.isLibrary) if(!subroutine.definingModule.isLibrary)
errors.warn("removing empty subroutine '${subroutine.name}'", subroutine.position) errors.warn("removing empty subroutine '${subroutine.name}'", subroutine.position)
@ -95,6 +91,10 @@ internal class UnusedCodeRemover(private val program: Program,
} }
return removals return removals
} }
if(!subroutine.definingModule.isLibrary)
errors.warn("removing unused subroutine '${subroutine.name}'", subroutine.position)
return listOf(IAstModification.Remove(subroutine, subroutine.definingScope))
}
} }
val removeDoubleAssignments = deduplicateAssignments(subroutine.statements) val removeDoubleAssignments = deduplicateAssignments(subroutine.statements)