From 0561dd084b5f3c2678eb032a40b85cb25bb6d589 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 20 Feb 2014 09:29:58 +0100 Subject: SI-8315 Better debugging facility for ICode Suffix the phase name to avoid clobbering files. % qbin/scalac -Xprint-icode -Xprint:inline -Yinline -Ydead-code sandbox/test.scala 1>/dev/null 2>/dev/null % ls *.icode A$$anonfun$crash$1_icode.icode Listt_icode.icode A$$anonfun$crash$1_inliner.icode Listt_inliner.icode A_icode.icode Nill$_icode.icode A_inliner.icode Nill$_inliner.icode --- src/compiler/scala/tools/nsc/Global.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 81e96b76ac..432c8ef647 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -1795,10 +1795,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter) private def writeICode() { val printer = new icodes.TextPrinter(null, icodes.linearizer) icodes.classes.values.foreach((cls) => { - val suffix = if (cls.symbol.hasModuleFlag) "$.icode" else ".icode" + val suffix = s"${if (cls.symbol.hasModuleFlag) "$" else ""}_${phase}.icode" val file = getFile(cls.symbol, suffix) -// if (file.exists()) -// file = new File(file.getParentFile(), file.getName() + "1") try { val stream = new FileOutputStream(file) printer.setWriter(new PrintWriter(stream, true)) -- cgit v1.2.3 From 64ed64ed5c2f64ee83a7963273bedf490926050e Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 20 Feb 2014 11:23:50 +0100 Subject: SI-8315 Fix crash in dead code elimination It was a cache invalidation bug. We need to mark the Code as touched to invalidate the caches behind `predecessors` and `successors`. --- .../scala/tools/nsc/backend/opt/DeadCodeElimination.scala | 2 ++ test/files/pos/t8315.flags | 1 + test/files/pos/t8315.scala | 12 ++++++++++++ test/files/pos/t8315b.flags | 1 + test/files/pos/t8315b.scala | 11 +++++++++++ 5 files changed, 27 insertions(+) create mode 100644 test/files/pos/t8315.flags create mode 100644 test/files/pos/t8315.scala create mode 100644 test/files/pos/t8315b.flags create mode 100644 test/files/pos/t8315b.scala (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala index 0f317422ac..b39fee65bb 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala @@ -95,8 +95,10 @@ abstract class DeadCodeElimination extends SubComponent { localStores.clear() clobbers.clear() m.code.blocks.clear() + m.code.touched = true accessedLocals = m.params.reverse m.code.blocks ++= linearizer.linearize(m) + m.code.touched = true collectRDef(m) mark() sweep(m) diff --git a/test/files/pos/t8315.flags b/test/files/pos/t8315.flags new file mode 100644 index 0000000000..c926ad6493 --- /dev/null +++ b/test/files/pos/t8315.flags @@ -0,0 +1 @@ +-Yinline -Ydead-code diff --git a/test/files/pos/t8315.scala b/test/files/pos/t8315.scala new file mode 100644 index 0000000000..2f7742ed67 --- /dev/null +++ b/test/files/pos/t8315.scala @@ -0,0 +1,12 @@ +object Test { + def crash(as: Listt): Unit = { + map(as, (_: Any) => return) + } + + final def map(x: Listt, f: Any => Any): Any = { + if (x eq Nill) "" else f("") + } +} + +object Nill extends Listt +class Listt diff --git a/test/files/pos/t8315b.flags b/test/files/pos/t8315b.flags new file mode 100644 index 0000000000..c926ad6493 --- /dev/null +++ b/test/files/pos/t8315b.flags @@ -0,0 +1 @@ +-Yinline -Ydead-code diff --git a/test/files/pos/t8315b.scala b/test/files/pos/t8315b.scala new file mode 100644 index 0000000000..d7a2bf565f --- /dev/null +++ b/test/files/pos/t8315b.scala @@ -0,0 +1,11 @@ +object Test extends Object { + def crash: Unit = { + val key = "" + try map(new F(key)) + catch { case _: Throwable => } + }; + final def map(f: F): Any = f.apply(""); +}; +final class F(key: String) { + final def apply(a: Any): Any = throw new RuntimeException(key); +} -- cgit v1.2.3