From 62d62dfe362108911698faa071c3cf4849562b58 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 13 Feb 2025 17:25:40 +0100 Subject: [PATCH] Fix compiler crash when using betasty with missing java classfiles --- .../dotc/semanticdb/SemanticSymbolBuilder.scala | 12 +++++++++--- .../test/dotc/neg-best-effort-pickling.excludelist | 12 ++++++------ .../test/dotty/tools/vulpix/ParallelTesting.scala | 8 ++++---- .../compiler-semanticdb-crash/err/ClassNode.java | 11 +++++++++++ .../compiler-semanticdb-crash/err/Main.scala | 4 ++++ .../compiler-semanticdb-crash/main/Test.scala | 1 + 6 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 tests/best-effort/compiler-semanticdb-crash/err/ClassNode.java create mode 100644 tests/best-effort/compiler-semanticdb-crash/err/Main.scala create mode 100644 tests/best-effort/compiler-semanticdb-crash/main/Test.scala diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala b/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala index 077ee0e40b86..84993b531c69 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala @@ -90,9 +90,15 @@ class SemanticSymbolBuilder: b.append('+').append(idx + 1) case _ => end find - val sig = sym.signature - val targetName = sym.targetName - find(sym => sym.signature == sig && sym.targetName == targetName) + try + val sig = sym.signature + val targetName = sym.targetName + find(sym => sym.signature == sig && sym.targetName == targetName) + catch + // sym.signature might not exist + // this solves tests/best-effort/compiler-semanticdb-crash + case _: MissingType if ctx.usedBestEffortTasty => + def addDescriptor(sym: Symbol): Unit = if sym.is(ModuleClass) then diff --git a/compiler/test/dotc/neg-best-effort-pickling.excludelist b/compiler/test/dotc/neg-best-effort-pickling.excludelist index 99a83a467f08..13fd5669dd8a 100644 --- a/compiler/test/dotc/neg-best-effort-pickling.excludelist +++ b/compiler/test/dotc/neg-best-effort-pickling.excludelist @@ -13,11 +13,11 @@ curried-dependent-ift.scala i17121.scala illegal-match-types.scala i13780-1.scala -i20317a.scala -i11226.scala -i974.scala -i13864.scala + +i20317a.scala # recursion limit exceeded +i11226.scala # missing type +i974.scala # cyclic reference +i13864.scala # missing symbol in pickling # semantic db generation fails in the first compilation -i1642.scala -i15158.scala +i15158.scala # cyclic reference - stack overflow diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index f7ee9d1ecd5e..aba52f15c97d 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -1212,7 +1212,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * of betasty files. */ def checkNoBestEffortError()(implicit summaryReport: SummaryReporting): this.type = { - val test = new NoBestEffortErrorsTest(targets, times, threadLimit, shouldFail || shouldSuppressOutput).executeTestSuite() + val test = new NoBestEffortErrorsTest(targets, times, threadLimit, shouldFail).executeTestSuite() cleanup() @@ -1761,7 +1761,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val bestEffortDir = new JFile(step1OutDir, s"META-INF${JFile.separator}best-effort") val step2Compilation = JointCompilationSource( - testGroup.name, step2SourceFiles, flags.and(withBetastyFlag).and(semanticDbFlag), step2OutDir, fromTasty = WithBestEffortTasty(bestEffortDir) + testGroup.name, step2SourceFiles, flags.and(bestEffortFlag).and(withBetastyFlag).and(semanticDbFlag), step2OutDir, fromTasty = WithBestEffortTasty(bestEffortDir) ) (step1Compilation, step2Compilation, bestEffortDir) }.unzip3 @@ -1770,7 +1770,7 @@ trait ParallelTesting extends RunnerOrchestration { self => new CompilationTest(step1Targets).keepOutput, new CompilationTest(step2Targets).keepOutput, bestEffortDirs, - true + shouldDelete = true ) } @@ -1824,7 +1824,7 @@ trait ParallelTesting extends RunnerOrchestration { self => def noCrashWithCompilingDependencies()(implicit summaryReport: SummaryReporting): this.type = { step1.checkNoBestEffortError() // Compile all files to generate the class files with best effort tasty - step2.checkCompile() // Compile with best effort tasty + step2.checkNoBestEffortError() // Compile with best effort tasty this } diff --git a/tests/best-effort/compiler-semanticdb-crash/err/ClassNode.java b/tests/best-effort/compiler-semanticdb-crash/err/ClassNode.java new file mode 100644 index 000000000000..0a2aabc411d7 --- /dev/null +++ b/tests/best-effort/compiler-semanticdb-crash/err/ClassNode.java @@ -0,0 +1,11 @@ +package dotty.tools.backend.jvm; + +public class ClassNode { + + public ClassNode(int api) { + } + + public ClassNode visitMethod(int access) { + return null; + } +} diff --git a/tests/best-effort/compiler-semanticdb-crash/err/Main.scala b/tests/best-effort/compiler-semanticdb-crash/err/Main.scala new file mode 100644 index 000000000000..cfc81a297a8e --- /dev/null +++ b/tests/best-effort/compiler-semanticdb-crash/err/Main.scala @@ -0,0 +1,4 @@ +package dotty.tools.backend.jvm + +val errorGenerator: Int = "0" +def readClass(bytes: Array[Byte]): ClassNode = ??? diff --git a/tests/best-effort/compiler-semanticdb-crash/main/Test.scala b/tests/best-effort/compiler-semanticdb-crash/main/Test.scala new file mode 100644 index 000000000000..8e5aee732d3e --- /dev/null +++ b/tests/best-effort/compiler-semanticdb-crash/main/Test.scala @@ -0,0 +1 @@ +def c = dotty.tools.backend.jvm.readClass(Array())