Skip to content

Commit fc55324

Browse files
committed
Cross-compilation for Scala 3.0, with some changes for Inox
The small changes are brought to help migrate Inox to Scala 3
1 parent 95b5d1e commit fc55324

File tree

9 files changed

+64
-49
lines changed

9 files changed

+64
-49
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ target
66
.metals
77
.bloop
88
.vscode
9+
.idea
10+
.bsp
911
project/.bloop
1012
project/metals.sbt
11-
project/project
13+
project/project

.larabot.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
commands = [
2-
"sbt -batch ++2.12.13 it:test"
2+
"sbt -batch it:test"
33
]
44

55
trusted = [

build.sbt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@ git.useGitDescribe := true
44

55
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
66

7-
javaOptions in IntegrationTest ++= Seq("-Xss128M")
7+
IntegrationTest / javaOptions ++= Seq("-Xss128M")
88

9-
fork in IntegrationTest := true
9+
IntegrationTest / fork := true
1010

11-
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7"
12-
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % "test"
11+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % "test;it"
1312

1413

15-
logBuffered in IntegrationTest := false
14+
IntegrationTest / logBuffered := false
1615

17-
parallelExecution in Test := true
16+
Test / parallelExecution := true
1817

1918
lazy val commonSettings = Seq(
2019
organization := "com.regblanc",
2120
name := "scala-smtlib",
22-
scalaVersion := "2.12.13",
23-
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.8", "2.12.13", "2.13.0", "2.13.5")
21+
scalaVersion := "2.13.6",
22+
crossScalaVersions := Seq("3.0.2")
2423
)
2524

2625
lazy val root = (project in file(".")).
@@ -30,7 +29,7 @@ lazy val root = (project in file(".")).
3029

3130
publishMavenStyle := true
3231

33-
publishArtifact in Test := false
32+
Test / publishArtifact := false
3433

3534
pomIncludeRepository := { _ => false }
3635

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.3.0
1+
sbt.version=1.5.5

src/it/scala/smtlib/it/TestHelpers.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,18 @@ trait TestHelpers {
4444
def getCVC4Interpreter: Interpreter = CVC4Interpreter.buildDefault
4545

4646
def isZ3Available: Boolean = try {
47-
val output: String = "z3 -help".!!
47+
val _: String = "z3 -help".!!
4848
true
4949
} catch {
50-
case (_: Exception) => false
50+
case _: Exception => false
5151
}
5252

5353
def isCVC4Available: Boolean = try {
54-
val output: String = "cvc4".!!
54+
// Make sure to pass a dummy option to cvc4, otherwise it starts in interactive mode (and does not exit)
55+
val _: String = "cvc4 --version".!!
5556
true
5657
} catch {
57-
case (e: Exception) => {
58-
false
59-
}
58+
case _: Exception => false
6059
}
6160

6261
def executeZ3(file: File)(f: (String) => Unit): Unit = {

src/main/scala/smtlib/interpreters/CVC4Interpreter.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package smtlib
22
package interpreters
33

4-
import trees.Terms._
4+
import smtlib.lexer.Lexer
5+
import smtlib.parser.Parser
6+
import smtlib.printer.{Printer, RecursivePrinter}
57
import trees.Commands._
6-
import trees.CommandsResponses._
78

8-
class CVC4Interpreter(executable: String, args: Array[String], tailPrinter: Boolean = false)
9-
extends ProcessInterpreter(executable, args, tailPrinter) {
9+
import java.io.BufferedReader
10+
11+
class CVC4Interpreter(executable: String,
12+
args: Array[String],
13+
printer: Printer = RecursivePrinter,
14+
parserCtor: BufferedReader => Parser = out => new Parser(new Lexer(out)))
15+
extends ProcessInterpreter(executable, args, printer, parserCtor) {
1016

1117
printer.printCommand(SetOption(PrintSuccess(true)), in)
1218
in.write("\n")
13-
in.flush
19+
in.flush()
1420
parser.parseGenResponse
1521

1622
}

src/main/scala/smtlib/interpreters/ProcessInterpreter.scala

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ import printer._
1010

1111
import java.io._
1212

13-
abstract class ProcessInterpreter(protected val process: Process, tailPrinter: Boolean) extends Interpreter {
13+
abstract class ProcessInterpreter private(override val printer: Printer,
14+
override val parser: Parser,
15+
protected val process: Process,
16+
protected val in: BufferedWriter,
17+
protected val out: BufferedReader) extends Interpreter {
1418

15-
def this(executable: String, args: Array[String], tailPrinter: Boolean = false) = {
16-
this(java.lang.Runtime.getRuntime.exec((executable :: args.toList).mkString(" ")), tailPrinter)
17-
}
18-
19-
lazy val in = new BufferedWriter(new OutputStreamWriter(process.getOutputStream))
20-
lazy val out = new BufferedReader(new InputStreamReader(process.getInputStream))
19+
private def this(printer: Printer, otherArgs: (Parser, Process, BufferedWriter, BufferedReader)) =
20+
this(printer, otherArgs._1, otherArgs._2, otherArgs._3, otherArgs._4)
2121

22-
lazy val parser: Parser = new Parser(new Lexer(out))
23-
lazy val printer: Printer = if (tailPrinter) TailPrinter else RecursivePrinter
22+
def this(executable: String,
23+
args: Array[String],
24+
printer: Printer = RecursivePrinter,
25+
parserCtor: BufferedReader => Parser = out => new Parser(new Lexer(out))) =
26+
this(printer, ProcessInterpreter.ctorHelper(executable, args, parserCtor))
2427

2528
def parseResponseOf(cmd: SExpr): SExpr = cmd match {
2629
case CheckSat() => parser.parseCheckSatResponse
@@ -98,17 +101,16 @@ abstract class ProcessInterpreter(protected val process: Process, tailPrinter: B
98101
override def interrupt(): Unit = synchronized {
99102
kill()
100103
}
104+
}
101105

102-
/*
103-
* Manos, greatest hack:
104-
* Process.destroyForcibly is only available on java8,
105-
* Using the implicit conversion, if compiled with java7
106-
* we will fallback to Process.destroy. If compiled on java8,
107-
* it will ignore the implicit conversion as the method exists,
108-
* and call the native Process.destroyForcibly.
109-
*/
110-
private implicit class Java8Process(process: Process) {
111-
def destroyForcibly() = process.destroy
106+
object ProcessInterpreter {
107+
private def ctorHelper(executable: String,
108+
args: Array[String],
109+
parserCtor: BufferedReader => Parser): (Parser, Process, BufferedWriter, BufferedReader) = {
110+
val process = java.lang.Runtime.getRuntime.exec((executable :: args.toList).mkString(" "))
111+
val in = new BufferedWriter(new OutputStreamWriter(process.getOutputStream))
112+
val out = new BufferedReader(new InputStreamReader(process.getInputStream))
113+
val parser = parserCtor(out)
114+
(parser, process, in, out)
112115
}
113-
114-
}
116+
}

src/main/scala/smtlib/interpreters/Z3Interpreter.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ package smtlib
22
package interpreters
33

44
import trees.Commands._
5-
import printer.RecursivePrinter
5+
import printer.{Printer, RecursivePrinter}
6+
import smtlib.lexer.Lexer
7+
import smtlib.parser.Parser
68

7-
class Z3Interpreter(executable: String, args: Array[String], tailPrinter: Boolean = false)
8-
extends ProcessInterpreter(executable, args, tailPrinter) {
9+
import java.io.BufferedReader
10+
11+
class Z3Interpreter(executable: String,
12+
args: Array[String],
13+
printer: Printer = RecursivePrinter,
14+
parserCtor: BufferedReader => Parser = out => new Parser(new Lexer(out)))
15+
extends ProcessInterpreter(executable, args, printer, parserCtor) {
916

1017
printer.printCommand(SetOption(PrintSuccess(true)), in)
1118
in.write("\n")
12-
in.flush
19+
in.flush()
1320
parser.parseGenResponse
1421

1522
}

src/test/scala/smtlib/parser/CommandsParserTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class CommandsParserTests extends AnyFunSuite with TimeLimits {
402402

403403
{
404404
val declareSort = parseUniqueCmd("(declare-sort A 3)")
405-
assert(parseUniqueCmd("(declare-sort A 3)") === DeclareSort("A", 3))
405+
assert(parseUniqueCmd("(declare-sort A 3)") === DeclareSort("A", 3))
406406
val DeclareSort(a, n) = declareSort
407407
assert(declareSort.getPos === Position(1,1))
408408
assert(a.getPos === Position(1,15))

0 commit comments

Comments
 (0)