Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best-effort: fix compiler crash when using betasty with missing java classfiles #22599

Merged
merged 1 commit into from
Feb 13, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions compiler/test/dotc/neg-best-effort-pickling.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -1770,7 +1770,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
new CompilationTest(step1Targets).keepOutput,
new CompilationTest(step2Targets).keepOutput,
bestEffortDirs,
true
shouldDelete = true
)
}

Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions tests/best-effort/compiler-semanticdb-crash/err/ClassNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dotty.tools.backend.jvm;

public class ClassNode {

public ClassNode(int api) {
}

public ClassNode visitMethod(int access) {
return null;
}
}
4 changes: 4 additions & 0 deletions tests/best-effort/compiler-semanticdb-crash/err/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dotty.tools.backend.jvm

val errorGenerator: Int = "0"
def readClass(bytes: Array[Byte]): ClassNode = ???
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def c = dotty.tools.backend.jvm.readClass(Array())
Loading