8000 Add expression compiler by adpi2 · Pull Request #22597 · scala/scala3 · GitHub
[go: up one dir, main page]

Skip to content

Add expression compiler #22597

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

Merged
merged 30 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26befcb
Add ExpressionCompiler in compiler module
adpi2 Feb 7, 2025
174a757
Add skeleton for debug tests
adpi2 Feb 11, 2025
afef97c
Introduce debugMode in RunnerOrchestration
adpi2 Feb 11, 2025
1378e1a
Add debugMain method
adpi2 Feb 12, 2025
62e0f40
Introduce Debugger
adpi2 Feb 12, 2025
32e538d
Add DebugStepAssert and parsing
adpi2 Feb 12, 2025
29f81e0
Implement Debugger
adpi2 Feb 13, 2025
ade2269
Configure JDI with sbt-jdi-tools
adpi2 Feb 17, 2025
43393ae
Introduce and implement ExpressionEvaluator
adpi2 Feb 17, 2025
50e03cc
Add Eval step in debug check file
adpi2 Feb 18, 2025
708607d
Add multi-line error check
adpi2 Feb 18, 2025
9354f4e
Hide progress bar when user is debugging the tests
adpi2 Feb 19, 2025
f14f73b
Add eval-static-fields test
adpi2 Feb 19, 2025
bfaec0f
Improve error reporting
adpi2 Feb 19, 2025
3e9f516
Fix re-using process for debugging
adpi2 Feb 20, 2025
9e36be6
Add eval-value-class test
adpi2 Feb 25, 2025
20c8280
Add more evaluation tests
adpi2 Feb 20, 2025
dffa9f4
Remove old Gen script for running debug tests
adpi2 Feb 27, 2025
176d8d1
Add documentation
adpi2 Feb 27, 2025
0855b09
Go to Add ExpressionCompiler
adpi2 Mar 7, 2025
ad715f7
Remove summaryReport.addCleanup
adpi2 Mar 7, 2025
c73fe36
Remove unused param in ExtractExpression.reflectEval
adpi2 Mar 7, 2025
5ca0b9a
Minor changes in ExtractExpression
adpi2 Mar 7, 2025
5c1a68e
remove useless transform of inline val
adpi2 Mar 7, 2025
9fcf8f1
Strenghten eval-java-protected-members test
adpi2 Mar 10, 2025
4672f2c
Add scaladoc on ExpressionCompiler
adpi2 Mar 10, 2025
6791207
Add eval-explicit-nulls test
adpi2 Mar 10, 2025
5a2c54a
Minor changes in InsertExpression
adpi2 Mar 10, 2025
bca9e31
Minor changes in ResolveReflectEval
adpi2 Mar 10, 2025
b75cd4d
Add scaladoc on expression compiler phases
adpi2 Mar 10, 2025
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
Prev Previous commit
Next Next commit
Add skeleton for debug tests
  • Loading branch information
adpi2 committed Mar 10, 2025
commit 174a757ca22f04fb31f8c2fd382e1edff16fa466
56 changes: 56 additions & 0 deletions compiler/test/dotty/tools/debug/DebugTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dotty.tools.debug

import dotty.Properties
import dotty.tools.dotc.reporting.TestReporter
import dotty.tools.io.JFile
import dotty.tools.vulpix.*
import org.junit.Test

import scala.concurrent.duration.*

class DebugTests:
import DebugTests.*
@Test def debug: Unit =
implicit val testGroup: TestGroup = TestGroup("debug")
compileFilesInDir("tests/debug", TestConfiguration.defaultOptions).checkDebug()

end DebugTests

object DebugTests extends ParallelTesting:
def maxDuration = 45.seconds
def numberOfSlaves = Runtime.getRuntime().availableProcessors()
def safeMode = Properties.testsSafeMode
def isInteractive = SummaryReport.isInteractive
def testFilter = Properties.testsFilter
def updateCheckFiles: Boolean = Properties.testsUpdateCheckfile
def failedTests = TestReporter.lastRunFailedTests

implicit val summaryReport: SummaryReporting = new SummaryReport

extension (test: CompilationTest)
private def checkDebug()(implicit summaryReport: SummaryReporting): test.type =
import test.*
checkPass(new DebugTest(targets, times, threadLimit, shouldFail || shouldSuppressOutput), "Debug")

private final class DebugTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
extends RunTest(testSources, times, threadLimit, suppressAllOutput):

override def onSuccess(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable) =
verifyDebug(testSource.outDir, testSource, countWarnings(reporters), reporters, logger)

private def verifyDebug(dir: JFile, testSource: TestSource, warnings: Int, reporters: Seq[TestReporter], logger: LoggedRunnable) =
if Properties.testsNoRun then addNoRunWarning()
else runMain(testSource.runClassPath, testSource.allToolArgs) match
case Success(output) => ()
case Failure(output) =>
if output == "" then
echo(s"Test '${testSource.title}' failed with no output")
else
echo(s"Test '${testSource.title}' failed with output:")
echo(output)
failTestSource(testSource)
case Timeout =>
echo("failed because test " + testSource.title + " timed out")
failTestSource(testSource, TimeoutFailure(testSource.title))

end DebugTest
24 changes: 12 additions & 12 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
rerun.exists(dir.getPath.contains)
})

private trait CompilationLogic { this: Test =>
protected trait CompilationLogic { this: Test =>
def suppressErrors = false

/**
Expand Down Expand Up @@ -359,7 +359,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
/** Each `Test` takes the `testSources` and performs the compilation and assertions
* according to the implementing class "neg", "run" or "pos".
*/
private class Test(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit val summaryReport: SummaryReporting) extends CompilationLogic { test =>
protected class Test(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit val summaryReport: SummaryReporting) extends CompilationLogic { test =>

import summaryReport._

Expand Down Expand Up @@ -903,15 +903,15 @@ trait ParallelTesting extends RunnerOrchestration { self =>
verifyOutput(testSource, reporters, logger)
}

private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
protected class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
extends Test(testSources, times, threadLimit, suppressAllOutput) {
private var didAddNoRunWarning = false
private def addNoRunWarning() = if (!didAddNoRunWarning) {
protected def addNoRunWarning() = if (!didAddNoRunWarning) {
didAddNoRunWarning = true
summaryReport.addStartingMessage {
"""|WARNING
|-------
|Run tests were only compiled, not run - this is due to the `dotty.tests.norun`
|Run and debug tests were only compiled, not run - this is due to the `dotty.tests.norun`
|property being set
|""".stripMargin
}
Expand Down Expand Up @@ -1162,12 +1162,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
* `aggregateTests` in the companion, which will ensure that aggregation is allowed.
*/
final class CompilationTest private (
private[ParallelTesting] val targets: List[TestSource],
private[ParallelTesting] val times: Int,
private[ParallelTesting] val shouldDelete: Boolean,
private[ParallelTesting] val threadLimit: Option[Int],
private[ParallelTesting] val shouldFail: Boolean,
private[ParallelTesting] val shouldSuppressOutput: Boolean
val targets: List[TestSource],
val times: Int,
val shouldDelete: Boolean,
val threadLimit: Option[Int],
val shouldFail: Boolean,
val shouldSuppressOutput: Boolean
) {
import org.junit.Assert.fail

Expand Down Expand Up @@ -1270,7 +1270,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
checkFail(test, "Rewrite")
}

private def checkPass(test: Test, desc: String): this.type =
def checkPass(test: Test, desc: String): this.type =
test.executeTestSuite()

cleanup()
Expand Down
2 changes: 1 addition & 1 deletion tests/debug/for.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object Test {
val b = 8 * 9 // [break] [step: f()]
f() // [step: val a]
20 + b
print(b)
println(b)
}

def f(): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion tests/debug/function.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Test {
a + b // [next] [next]
}
val c = plus(a, b) // [next: print]
print(c) // [cont]
println(c) // [cont]
}

}
2 changes: 1 addition & 1 deletion tests/debug/if.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ object Test {
else
a = 34 * 23 // [step: print]

print(a)
println(a)
}
}
2 changes: 1 addition & 1 deletion tests/debug/method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object Test {
val a = 1 + 2 // [break] [step: a * 9]
val b = a * 9 // [step: plus]
val c = plus(a, b) // [step: x * x]
print(c)
println(c)
}

def plus(x: Int, y: Int) = {
Expand Down
2 changes: 1 addition & 1 deletion tests/debug/nested-method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ object Test {
}

val c = plus(a, b) // [step: print] [cont]
print(c)
println(c)
}
}
2 changes: 1 addition & 1 deletion tests/debug/sequence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Test {
a = a * 8 // [step: 9 * 9]
a = 9 * 9 // [step: 34 * 23]
a = 34 * 23 // [step: print]
print(a) // [cont]
println(a) // [cont]
}
}
2 changes: 1 addition & 1 deletion tests/debug/tailrec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ object Test {
val b = a * 9 // [break] [step: fact]
val c = fact(a) // [step: x == 0] [step: fact(x - 1)] [step: x == 0] [cont]
fact(0) // [break] [step: x == 0] [step: 1] [step: fact(x - 1)] [step: print]
print(c) // [cont]
println(c) // [cont]
}
}
2 changes: 1 addition & 1 deletion tests/debug/while.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Test {
a += 1 // [step: while] [cont: print]
}

print(a) // [break] [cont]
println(a) // [break] [cont]
}
}
0