Skip to content

Commit cb4e953

Browse files
committed
chore: extract repl to be its own artifact
1 parent ea1ab6e commit cb4e953

File tree

153 files changed

+298
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+298
-65
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ val `scala3-compiler` = Build.`scala3-compiler`
77
val `scala3-compiler-nonbootstrapped` = Build.`scala3-compiler-nonbootstrapped`
88
val `scala3-compiler-bootstrapped-new` = Build.`scala3-compiler-bootstrapped-new`
99
val `scala3-compiler-bootstrapped` = Build.`scala3-compiler-bootstrapped`
10+
val `scala3-repl-nonbootstrapped` = Build.`scala3-repl-nonbootstrapped`
11+
val `scala3-repl-bootstrapped` = Build.`scala3-repl-bootstrapped`
1012
val `scala-library-sjs` = Build.`scala-library-sjs`
1113
val `scala3-library-sjs` = Build.`scala3-library-sjs`
1214
val `scala-library-nonbootstrapped` = Build.`scala-library-nonbootstrapped`

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ object MainGenericCompiler {
176176
case CompileMode.Repl | CompileMode.Run =>
177177
addJavaProps()
178178
val properArgs = reconstructedArgs()
179-
repl.Main.main(properArgs.toArray)
179+
??? //repl.Main.main(properArgs.toArray)
180180
case CompileMode.Guess =>
181181
run(settings.withCompileMode(CompileMode.Compile))
182182
end run

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ object MainGenericRunner {
188188
val properArgs =
189189
List("-classpath", settings.classPath.mkString(classpathSeparator)).filter(Function.const(settings.classPath.nonEmpty))
190190
++ settings.residualArgs
191-
repl.Main.main(properArgs.toArray)
191+
//repl.Main.main(properArgs.toArray)
192192
None
193193

194194
case ExecuteMode.PossibleRun =>

compiler/src/dotty/tools/dotc/quoted/Interpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import dotty.tools.dotc.quoted.*
2525
import dotty.tools.dotc.typer.ImportInfo.withRootImports
2626
import dotty.tools.dotc.util.SrcPos
2727
import dotty.tools.dotc.reporting.Message
28-
import dotty.tools.repl.AbstractFileClassLoader
28+
import dotty.tools.io.AbstractFileClassLoader
2929
import dotty.tools.dotc.core.CyclicReference
3030

3131
/** Tree interpreter for metaprogramming constructs */

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import dotty.tools.dotc.quoted.Interpreter
2222

2323
import scala.util.control.NonFatal
2424
import dotty.tools.dotc.util.SrcPos
25-
import dotty.tools.repl.AbstractFileClassLoader
25+
import dotty.tools.io.AbstractFileClassLoader
2626

2727
import scala.reflect.ClassTag
2828

compiler/src/dotty/tools/dotc/util/ClasspathFromClassloader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.language.unsafeNulls
55
import java.net.URLClassLoader
66
import java.nio.file.Paths
77

8-
import dotty.tools.repl.AbstractFileClassLoader
8+
import dotty.tools.io.AbstractFileClassLoader
99

1010
object ClasspathFromClassloader {
1111

compiler/src/dotty/tools/repl/AbstractFileClassLoader.scala renamed to compiler/src/dotty/tools/io/AbstractFileClassLoader.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
*/
1212

1313
package dotty.tools
14-
package repl
14+
package io
1515

1616
import scala.language.unsafeNulls
1717

18-
import io.AbstractFile
18+
import dotty.tools.io.AbstractFile
1919

2020
import java.net.{URL, URLConnection, URLStreamHandler}
2121
import java.util.Collections

compiler/src/dotty/tools/repl/package.scala

Lines changed: 0 additions & 10 deletions
This file was deleted.

project/Build.scala

Lines changed: 158 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,6 @@ object Build {
724724
libraryDependencies ++= Seq(
725725
"org.scala-lang.modules" % "scala-asm" % "9.8.0-scala-1", // used by the backend
726726
Dependencies.compilerInterface,
727-
"org.jline" % "jline-reader" % "3.29.0", // used by the REPL
728-
"org.jline" % "jline-terminal" % "3.29.0",
729-
"org.jline" % "jline-terminal-jni" % "3.29.0", // needed for Windows
730727
("io.get-coursier" %% "coursier" % "2.0.16" % Test).cross(CrossVersion.for3Use2_13),
731728
),
732729

@@ -1773,6 +1770,164 @@ object Build {
17731770
},
17741771
)
17751772

1773+
lazy val `scala3-repl-nonbootstrapped` = project.in(file("repl"))
1774+
.dependsOn(`scala3-compiler-nonbootstrapped` % "compile->compile;test->test")
1775+
.settings(publishSettings)
1776+
.settings(
1777+
name := "scala3-repl",
1778+
moduleName := "scala3-repl",
1779+
version := dottyVersion,
1780+
versionScheme := Some("semver-spec"),
1781+
scalaVersion := referenceVersion,
1782+
crossPaths := true, // org.scala-lang:scala3-tasty-inspector has a crosspath
1783+
autoScalaLibrary := false, // do not add a dependency to stdlib, we depend transitively on the stdlib from `scala3-compiler-bootstrapped`
1784+
// Add the source directories for the sbt-bridge (boostrapped)
1785+
Compile / unmanagedSourceDirectories := Seq(baseDirectory.value / "src"),
1786+
Test / unmanagedSourceDirectories := Seq(baseDirectory.value / "test"),
1787+
// NOTE: The only difference here is that we drop `-Werror` and semanticDB for now
1788+
Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions"),
1789+
// Make sure that the produced artifacts have the minimum JVM version in the bytecode
1790+
Compile / javacOptions ++= Seq("--release", Versions.minimumJVMVersion),
1791+
Compile / scalacOptions ++= Seq("--java-output-version", Versions.minimumJVMVersion),
1792+
// Packaging configuration of `scala3-staging`
1793+
Compile / packageBin / publishArtifact := true,
1794+
Compile / packageDoc / publishArtifact := false,
1795+
Compile / packageSrc / publishArtifact := true,
1796+
// Only publish compilation artifacts, no test artifacts
1797+
Test / publishArtifact := false,
1798+
publish / skip := false,
1799+
libraryDependencies ++= Seq(
1800+
"com.github.sbt" % "junit-interface" % "0.13.3" % Test,
1801+
),
1802+
// Project specific target folder. sbt doesn't like having two projects using the same target folder
1803+
target := target.value / "scala3-repl-nonbootstrapped",
1804+
// Configure to use the non-bootstrapped compiler
1805+
scalaInstance := {
1806+
val lm = dependencyResolution.value
1807+
val log = streams.value.log
1808+
val retrieveDir = streams.value.cacheDirectory / "scala3-compiler" / scalaVersion.value
1809+
val comp = lm.retrieve("org.scala-lang" % "scala3-compiler_3" %
1810+
scalaVersion.value, scalaModuleInfo = None, retrieveDir, log)
1811+
.fold(w => throw w.resolveException, identity)
1812+
Defaults.makeScalaInstance(
1813+
scalaVersion.value,
1814+
Array.empty,
1815+
comp.toSeq,
1816+
Seq.empty,
1817+
state.value,
1818+
scalaInstanceTopLoader.value,
1819+
)},
1820+
scalaCompilerBridgeBinaryJar := {
1821+
Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value)
1822+
},
1823+
Test / javaOptions ++= {
1824+
val log = streams.value.log
1825+
val managedSrcDir = {
1826+
// Populate the directory
1827+
(Compile / managedSources).value
1828+
1829+
(Compile / sourceManaged).value
1830+
}
1831+
val externalDeps = (ThisProject / Runtime / externalDependencyClasspath).value
1832+
Seq(
1833+
s"-Ddotty.tests.dottyCompilerManagedSources=${managedSrcDir}",
1834+
s"-Ddotty.tests.classes.dottyInterfaces=${(`scala3-interfaces` / Compile / packageBin).value}",
1835+
s"-Ddotty.tests.classes.dottyCompiler=${(`scala3-compiler-nonbootstrapped` / Compile / packageBin).value}",
1836+
s"-Ddotty.tests.classes.tastyCore=${(`tasty-core-nonbootstrapped` / Compile / packageBin).value}",
1837+
s"-Ddotty.tests.classes.compilerInterface=${findArtifactPath(externalDeps, "compiler-interface")}",
1838+
s"-Ddotty.tests.classes.scalaLibrary=${(`scala-library-nonbootstrapped` / Compile / packageBin).value}",
1839+
s"-Ddotty.tools.dotc.semanticdb.test=${(ThisBuild / baseDirectory).value/"tests"/"semanticdb"}",
1840+
)
1841+
},
1842+
Test / forkOptions :=
1843+
(Test / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
1844+
)
1845+
1846+
lazy val `scala3-repl-bootstrapped` = project.in(file("repl"))
1847+
.dependsOn(`scala3-compiler-bootstrapped-new` % "compile->compile;test->test")
1848+
.settings(publishSettings)
1849+
.settings(
1850+
name := "scala3-repl",
1851+
moduleName := "scala3-repl",
1852+
version := dottyVersion,
1853+
versionScheme := Some("semver-spec"),
1854+
scalaVersion := referenceVersion,
1855+
crossPaths := true, // org.scala-lang:scala3-tasty-inspector has a crosspath
1856+
autoScalaLibrary := false, // do not add a dependency to stdlib, we depend transitively on the stdlib from `scala3-compiler-bootstrapped`
1857+
// Add the source directories for the sbt-bridge (boostrapped)
1858+
Compile / unmanagedSourceDirectories := Seq(baseDirectory.value / "src"),
1859+
Test / unmanagedSourceDirectories := Seq(baseDirectory.value / "test"),
1860+
// NOTE: The only difference here is that we drop `-Werror` and semanticDB for now
1861+
Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions"),
1862+
// Make sure that the produced artifacts have the minimum JVM version in the bytecode
1863+
Compile / javacOptions ++= Seq("--release", Versions.minimumJVMVersion),
1864+
Compile / scalacOptions ++= Seq("--java-output-version", Versions.minimumJVMVersion),
1865+
// Packaging configuration of `scala3-staging`
1866+
Compile / packageBin / publishArtifact := true,
1867+
Compile / packageDoc / publishArtifact := false,
1868+
Compile / packageSrc / publishArtifact := true,
1869+
// Only publish compilation artifacts, no test artifacts
1870+
Test / publishArtifact := false,
1871+
publish / skip := false,
1872+
libraryDependencies ++= Seq(
1873+
"com.github.sbt" % "junit-interface" % "0.13.3" % Test,
1874+
),
1875+
target := target.value / "scala3-repl-bootstrapped",
1876+
// Configure to use the non-bootstrapped compiler
1877+
scalaInstance := {
1878+
val externalCompilerDeps = (`scala3-compiler-nonbootstrapped` / Compile / externalDependencyClasspath).value.map(_.data).toSet
1879+
1880+
// IMPORTANT: We need to use actual jars to form the ScalaInstance and not
1881+
// just directories containing classfiles because sbt maintains a cache of
1882+
// compiler instances. This cache is invalidated based on timestamps
1883+
// however this is only implemented on jars, directories are never
1884+
// invalidated.
1885+
val tastyCore = (`tasty-core-nonbootstrapped` / Compile / packageBin).value
1886+
val scalaLibrary = (`scala-library-nonbootstrapped` / Compile / packageBin).value
1887+
val scala3Interfaces = (`scala3-interfaces` / Compile / packageBin).value
1888+
val scala3Compiler = (`scala3-compiler-nonbootstrapped` / Compile / packageBin).value
1889+
1890+
Defaults.makeScalaInstance(
1891+
dottyNonBootstrappedVersion,
1892+
libraryJars = Array(scalaLibrary),
1893+
allCompilerJars = Seq(tastyCore, scala3Interfaces, scala3Compiler) ++ externalCompilerDeps,
1894+
allDocJars = Seq.empty,
1895+
state.value,
1896+
scalaInstanceTopLoader.value
1897+
)
1898+
},
1899+
scalaCompilerBridgeBinaryJar := {
1900+
Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value)
1901+
},
1902+
Test / javaOptions ++= {
1903+
val log = streams.value.log
1904+
val managedSrcDir = {
1905+
// Populate the directory
1906+
(Compile / managedSources).value
1907+
1908+
(Compile / sourceManaged).value
1909+
}
1910+
val externalDeps = (ThisProject / Runtime / externalDependencyClasspath).value
1911+
Seq(
1912+
s"-Ddotty.tests.dottyCompilerManagedSources=${managedSrcDir}",
1913+
s"-Ddotty.tests.classes.dottyInterfaces=${(`scala3-interfaces` / Compile / packageBin).value}",
1914+
s"-Ddotty.tests.classes.dottyCompiler=${(ThisProject / Compile / packageBin).value}",
1915+
s"-Ddotty.tests.classes.tastyCore=${(`tasty-core-bootstrapped-new` / Compile / packageBin).value}",
1916+
s"-Ddotty.tests.classes.compilerInterface=${findArtifactPath(externalDeps, "compiler-interface")}",
1917+
s"-Ddotty.tests.classes.scalaLibrary=${(`scala-library-bootstrapped` / Compile / packageBin).value}",
1918+
s"-Ddotty.tests.classes.scalaJSScalalib=${(`scala-library-sjs` / Compile / packageBin).value}",
1919+
s"-Ddotty.tests.classes.scalaAsm=${findArtifactPath(externalDeps, "scala-asm")}",
1920+
s"-Ddotty.tests.classes.jlineTerminal=${findArtifactPath(externalDeps, "jline-terminal")}",
1921+
s"-Ddotty.tests.classes.jlineReader=${findArtifactPath(externalDeps, "jline-reader")}",
1922+
s"-Ddotty.tests.classes.dottyStaging=${(LocalProject("scala3-staging-new") / Compile / packageBin).value}",
1923+
s"-Ddotty.tests.classes.dottyTastyInspector=${(LocalProject("scala3-tasty-inspector-new") / Compile / packageBin).value}",
1924+
s"-Ddotty.tools.dotc.semanticdb.test=${(ThisBuild / baseDirectory).value/"tests"/"semanticdb"}",
1925+
)
1926+
},
1927+
Test / forkOptions :=
1928+
(Test / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
1929+
)
1930+
17761931
// ==============================================================================================
17771932
// =================================== SCALA STANDARD LIBRARY ===================================
17781933
// ==============================================================================================
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scala.tools.repl.ScriptEngine$Factory

0 commit comments

Comments
 (0)