From 69a280ff1da7c1d8b6d6f094998f0ace1a328d1a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 2 Mar 2018 11:15:34 +0100 Subject: [PATCH 1/3] Fix output of decompiler when emitting to a file --- .../dotty/tools/dotc/decompiler/DecompilationPrinter.scala | 2 +- compiler/src/dotty/tools/dotc/decompiler/Main.scala | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala index c41a27281c5f..51533640a3bb 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala @@ -24,7 +24,7 @@ class DecompilationPrinter extends Phase { var os: OutputStream = null var ps: PrintStream = null try { - os = File(outputDir + ".decompiled").outputStream() + os = File(outputDir + ".decompiled").outputStream(append = true) ps = new PrintStream(os) printToOutput(ps) } finally { diff --git a/compiler/src/dotty/tools/dotc/decompiler/Main.scala b/compiler/src/dotty/tools/dotc/decompiler/Main.scala index e3b0376b0912..c91afc45fb34 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/Main.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/Main.scala @@ -1,5 +1,7 @@ package dotty.tools.dotc.decompiler +import java.nio.file.{Files, Paths} + import dotty.tools.dotc import dotty.tools.dotc.core.Contexts._ @@ -10,6 +12,9 @@ import dotty.tools.dotc.core.Contexts._ object Main extends dotc.Driver { override protected def newCompiler(implicit ctx: Context): dotc.Compiler = { assert(ctx.settings.fromTasty.value) + val outputDir = ctx.settings.outputDir.value + if (outputDir != ".") + Files.deleteIfExists(Paths.get(outputDir + ".decompiled")) new TASTYDecompiler } From e6130d9a6e86af961126c80a737ce903638c17f7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 2 Mar 2018 11:17:04 +0100 Subject: [PATCH 2/3] Fix compilation units not beeing loaded if already loaded symbol Not all classes where loaded depending on the order of the compilation --- .../dotc/fromtasty/ReadTastyTreesFromClasses.scala | 5 ++--- .../test/dotty/tools/dotc/FromTastyTests.scala | 5 ++--- tests/pos/simpleClass-2.decompiled | 14 ++++++++++++++ tests/pos/simpleClass-2.scala | 6 ++++++ tests/pos/simpleClass.decompiled | 9 ++++++++- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 tests/pos/simpleClass-2.decompiled create mode 100644 tests/pos/simpleClass-2.scala diff --git a/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala b/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala index 1fefd15d32ad..7b3b9635192e 100644 --- a/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala +++ b/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala @@ -66,11 +66,10 @@ class ReadTastyTreesFromClasses extends FrontEnd { clsd.infoOrCompleter match { case info: ClassfileLoader => info.load(clsd) // sets cls.treeOrProvider and cls.moduleClass.treeProvider as a side-effect - def moduleClass = clsd.owner.info.member(className.moduleClassName).symbol - compilationUnit(clsd.classSymbol).orElse(compilationUnit(moduleClass)) case _ => - alreadyLoaded() } + def moduleClass = clsd.owner.info.member(className.moduleClassName).symbol + compilationUnit(clsd.classSymbol).orElse(compilationUnit(moduleClass)) case _ => cannotUnpickle(s"no class file was found") } diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index 40d89815c17e..38d9c006f7ab 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -29,9 +29,7 @@ class FromTastyTests extends ParallelTesting { val (step1, step2, step3) = compileTastyInDir("tests/pos", defaultOptions, blacklist = Set( "macro-deprecate-dont-touch-backquotedidents.scala", - - // Compiles wrong class - "simpleClass.scala", + "t247.scala", // Wrong number of arguments "i3130b.scala", @@ -84,6 +82,7 @@ class FromTastyTests extends ParallelTesting { blacklist = Set( "t7223.scala", + "t5428.scala", // Missing position "Course-2002-13.scala", diff --git a/tests/pos/simpleClass-2.decompiled b/tests/pos/simpleClass-2.decompiled new file mode 100644 index 000000000000..4d860a964b01 --- /dev/null +++ b/tests/pos/simpleClass-2.decompiled @@ -0,0 +1,14 @@ +================================================================================ +out/posTestFromTasty/pos2/simpleClass-2/foo/B.class +-------------------------------------------------------------------------------- +package foo { + class B() extends Object() {} +} +-------------------------------------------------------------------------------- +================================================================================ +out/posTestFromTasty/pos2/simpleClass-2/foo/A.class +-------------------------------------------------------------------------------- +package foo { + class A() extends foo.B() {} +} +-------------------------------------------------------------------------------- \ No newline at end of file diff --git a/tests/pos/simpleClass-2.scala b/tests/pos/simpleClass-2.scala new file mode 100644 index 000000000000..e81982c4cecc --- /dev/null +++ b/tests/pos/simpleClass-2.scala @@ -0,0 +1,6 @@ +package foo + +class B + +class A extends B + diff --git a/tests/pos/simpleClass.decompiled b/tests/pos/simpleClass.decompiled index 44fba6e33f55..99663bd1f133 100644 --- a/tests/pos/simpleClass.decompiled +++ b/tests/pos/simpleClass.decompiled @@ -1,5 +1,12 @@ ================================================================================ -out/posTestFromTasty/pos/simpleClass/foo/A.class +out/posTestFromTasty/pos2/simpleClass/foo/B.class +-------------------------------------------------------------------------------- +package foo { + class B() extends foo.A() {} +} +-------------------------------------------------------------------------------- +================================================================================ +out/posTestFromTasty/pos2/simpleClass/foo/A.class -------------------------------------------------------------------------------- package foo { class A() extends Object() {} From 976ba4b29858eb42c1f76026a7abe169a59fab38 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 2 Mar 2018 11:55:36 +0100 Subject: [PATCH 3/3] Make decompliation test output stable on different filesystems --- compiler/test/dotty/tools/vulpix/ParallelTesting.scala | 2 +- tests/pos/simpleClass-2.decompiled | 8 ++++---- tests/pos/simpleClass.decompiled | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 47f23f957d31..7eba42f4b582 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -433,7 +433,7 @@ trait ParallelTesting extends RunnerOrchestration { self => def hasTastyFileToClassName(f: JFile): String = targetDir.toPath.relativize(f.toPath).toString.dropRight(".hasTasty".length).replace('/', '.') - val classes = flattenFiles(targetDir).filter(isHasTastyFile).map(hasTastyFileToClassName) + val classes = flattenFiles(targetDir).filter(isHasTastyFile).map(hasTastyFileToClassName).sorted val reporter = TestReporter.reporter(realStdout, logLevel = diff --git a/tests/pos/simpleClass-2.decompiled b/tests/pos/simpleClass-2.decompiled index 4d860a964b01..78291f123ca2 100644 --- a/tests/pos/simpleClass-2.decompiled +++ b/tests/pos/simpleClass-2.decompiled @@ -1,14 +1,14 @@ ================================================================================ -out/posTestFromTasty/pos2/simpleClass-2/foo/B.class +out/posTestFromTasty/pos/simpleClass-2/foo/A.class -------------------------------------------------------------------------------- package foo { - class B() extends Object() {} + class A() extends foo.B() {} } -------------------------------------------------------------------------------- ================================================================================ -out/posTestFromTasty/pos2/simpleClass-2/foo/A.class +out/posTestFromTasty/pos/simpleClass-2/foo/B.class -------------------------------------------------------------------------------- package foo { - class A() extends foo.B() {} + class B() extends Object() {} } -------------------------------------------------------------------------------- \ No newline at end of file diff --git a/tests/pos/simpleClass.decompiled b/tests/pos/simpleClass.decompiled index 99663bd1f133..f671605a89c7 100644 --- a/tests/pos/simpleClass.decompiled +++ b/tests/pos/simpleClass.decompiled @@ -1,14 +1,14 @@ ================================================================================ -out/posTestFromTasty/pos2/simpleClass/foo/B.class +out/posTestFromTasty/pos/simpleClass/foo/A.class -------------------------------------------------------------------------------- package foo { - class B() extends foo.A() {} + class A() extends Object() {} } -------------------------------------------------------------------------------- ================================================================================ -out/posTestFromTasty/pos2/simpleClass/foo/A.class +out/posTestFromTasty/pos/simpleClass/foo/B.class -------------------------------------------------------------------------------- package foo { - class A() extends Object() {} + class B() extends foo.A() {} } -------------------------------------------------------------------------------- \ No newline at end of file