Skip to content

Commit 9e45ad1

Browse files
authored
Merge pull request #2260 from dotty-staging/backend-submodule
Fix #2184: Hyper Bootstrap! Integrate the backend as a git submodule
2 parents 975f7ef + 4767786 commit 9e45ad1

File tree

16 files changed

+178
-68
lines changed

16 files changed

+178
-68
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "scala-backend"]
2+
path = scala-backend
3+
url = https://github.com/lampepfl/scala.git
4+
branch = sharing-backend

bin/common

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function getLastStringOnLineWith {
1010
# Configuration
1111
SCALA_VERSION=$(getLastStringOnLineWith "val scalacVersion")
1212
SCALA_BINARY_VERSION=2.11
13-
SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler")
13+
SCALA_ASM_VERSION=$(getLastStringOnLineWith "% \"scala-asm\" %")
1414
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
1515
bootcp=true
1616
bootstrapped=false
@@ -146,8 +146,8 @@ if [ "$SCALA_REFLECT_JAR" == "" ]; then
146146
SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar")
147147
fi
148148

149-
if [ "$SCALA_COMPILER_JAR" == "" ]; then
150-
SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar")
149+
if [ "$SCALA_ASM_JAR" == "" ]; then
150+
SCALA_ASM_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang.modules/scala-asm/bundles" "scala-asm-$SCALA_ASM_VERSION.jar")
151151
fi
152152

153153
if [ "$SBT_INTERFACE_JAR" == "" ]; then

bin/dotc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ CompilerMain=dotty.tools.dotc.Main
2020
FromTasty=dotty.tools.dotc.FromTasty
2121
ReplMain=dotty.tools.dotc.repl.Main
2222

23-
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
23+
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_ASM_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
2424
then
2525
echo To use this script please set
2626
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
2727
echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)"
28-
echo SCALA_COMPILER_JAR to point to scala-compiler-$SCALA_VERSION.jar with bcode patches "(currently $SCALA_COMPILER_JAR)"
28+
echo SCALA_ASM_JAR to point to scala-asm-$SCALA_ASM_VERSION.jar "(currently $SCALA_ASM_JAR)"
2929
echo SBT_INTERFACE_JAR to point to interface-$SBT_VERSION.jar "(currently $SBT_INTERFACE_JAR)"
3030
fi
3131

@@ -116,9 +116,9 @@ trap onExit INT
116116
classpathArgs () {
117117
if [[ "true" == "$bootstrapped" ]]; then
118118
check_jar "dotty-bootstrapped" "$DOTTY_JAR" "target" 'build_jar "test:runMain dotc.build" target' &> /dev/null
119-
toolchain="$DOTTY_JAR:$DOTTY_LIB_JAR:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$SBT_INTERFACE_JAR"
119+
toolchain="$DOTTY_JAR:$DOTTY_LIB_JAR:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
120120
else
121-
toolchain="$SCALA_LIBRARY_JAR:$DOTTY_LIB_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$SBT_INTERFACE_JAR"
121+
toolchain="$SCALA_LIBRARY_JAR:$DOTTY_LIB_JAR:$SCALA_REFLECT_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
122122
fi
123123
bcpJars="$INTERFACES_JAR:$MAIN_JAR:$DOTTY_LIB_JAR"
124124
cpJars="$INTERFACES_JAR:$MAIN_JAR:$DOTTY_LIB_JAR:$TEST_JAR"

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import dotty.tools.dotc.core.Names.TypeName
88

99
import scala.collection.mutable
1010
import scala.tools.asm.{ClassVisitor, CustomAttr, FieldVisitor, MethodVisitor}
11-
import scala.tools.nsc.Settings
1211
import scala.tools.nsc.backend.jvm._
1312
import dotty.tools.dotc
1413
import dotty.tools.dotc.backend.jvm.DottyPrimitives
@@ -35,7 +34,6 @@ import tpd._
3534
import StdNames._
3635

3736
import scala.reflect.io.{AbstractFile, Directory, PlainDirectory}
38-
import scala.tools.nsc.backend.jvm.opt.LocalOpt
3937

4038
class GenBCode extends Phase {
4139
def phaseName: String = "genBCode"
@@ -246,10 +244,10 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
246244
* - converting the plain ClassNode to byte array and placing it on queue-3
247245
*/
248246
class Worker2 {
249-
lazy val localOpt = new LocalOpt(new Settings())
247+
// lazy val localOpt = new LocalOpt(new Settings())
250248

251249
def localOptimizations(classNode: ClassNode): Unit = {
252-
/*BackendStats.timed(BackendStats.methodOptTimer)*/(localOpt.methodOptimizations(classNode))
250+
// BackendStats.timed(BackendStats.methodOptTimer)(localOpt.methodOptimizations(classNode))
253251
}
254252

255253
def run(): Unit = {

compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import core.Symbols.{Symbol, NoSymbol}
3737
* Inspired from the `scalac` compiler.
3838
*/
3939
class DottyPrimitives(ctx: Context) {
40-
import scala.tools.nsc.backend.ScalaPrimitives._
40+
import scala.tools.nsc.backend.ScalaPrimitivesOps._
4141

4242
private lazy val primitives: immutable.Map[Symbol, Int] = init
4343

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package scala.tools.nsc
2+
3+
/**
4+
* Compatibility layer needed for the backend.
5+
*
6+
* Our backend is based on the Scala 2.11 GenBCode backend and modified so that
7+
* it compiles both with dotty and scalac, since the backend uses
8+
* scala.tools.nsc.io.*, we need to also provide it.
9+
*
10+
* See http://dotty.epfl.ch/docs/contributing/backend.html for more information.
11+
*/
12+
package object io {
13+
type AbstractFile = scala.reflect.io.AbstractFile
14+
val AbstractFile = scala.reflect.io.AbstractFile
15+
16+
type Directory = scala.reflect.io.Directory
17+
val Directory = scala.reflect.io.Directory
18+
19+
type Path = scala.reflect.io.Path
20+
val Path = scala.reflect.io.Path
21+
22+
type File = scala.reflect.io.File
23+
val File = scala.reflect.io.File
24+
25+
type Jar = dotty.tools.io.Jar
26+
val Jar = dotty.tools.io.Jar
27+
}

compiler/test/dotc/tests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ class tests extends CompilerTest {
358358
@Test def tasty_dotc_util = compileDir(dotcDir, "util", testPickling)
359359
@Test def tasty_tools_io = compileDir(toolsDir, "io", testPickling)
360360

361-
@Test def tasty_bootstrap = {
361+
// Disabled, not worth porting since we're getting rid of the old JUnit tests soon.
362+
/*@Test*/ def tasty_bootstrap = {
362363
val logging = if (false) List("-Ylog-classpath", "-verbose") else Nil
363364
val opt = List("-priorityclasspath", defaultOutputDir) ++ logging
364365
// first compile dotty

compiler/test/dotty/tools/TypeStealer.scala

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

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import asm._
1111
import asm.tree._
1212
import scala.collection.JavaConverters._
1313

14-
import scala.tools.nsc.util.JavaClassPath
14+
import io.JavaClassPath
1515
import scala.collection.JavaConverters._
1616
import scala.tools.asm.{ClassWriter, ClassReader}
1717
import scala.tools.asm.tree._

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ package dotc
44

55
import org.junit.{ Test, BeforeClass, AfterClass }
66

7+
import java.nio.file._
8+
import java.util.stream.{ Stream => JStream }
9+
import scala.collection.JavaConverters._
710
import scala.util.matching.Regex
811
import scala.concurrent.duration._
912

1013
import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }
1114

15+
1216
class CompilationTests extends ParallelTesting {
1317
import TestConfiguration._
1418
import CompilationTests._
@@ -219,16 +223,44 @@ class CompilationTests extends ParallelTesting {
219223
// compile with bootstrapped library on cp:
220224
defaultOutputDir + "lib/src/:" +
221225
// as well as bootstrapped compiler:
222-
defaultOutputDir + "dotty1/dotty/:" +
226+
defaultOutputDir + "dotty1/dotty1/:" +
223227
Jars.dottyInterfaces
224228
)
225229

226230
def lib =
227231
compileDir("../library/src",
228232
allowDeepSubtypes.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir))
229233

230-
def dotty1 =
231-
compileDir("../compiler/src/dotty", opt)
234+
def sources(paths: JStream[Path], excludedFiles: List[String] = Nil): List[String] =
235+
paths.iterator().asScala
236+
.filter(path =>
237+
(path.toString.endsWith(".scala") || path.toString.endsWith(".java"))
238+
&& !excludedFiles.contains(path.getFileName.toString))
239+
.map(_.toString).toList
240+
241+
val compilerDir = Paths.get("../compiler/src")
242+
val compilerSources = sources(Files.walk(compilerDir))
243+
244+
val backendDir = Paths.get("../scala-backend/src/compiler/scala/tools/nsc/backend")
245+
val backendJvmDir = Paths.get("../scala-backend/src/compiler/scala/tools/nsc/backend/jvm")
246+
247+
// NOTE: Keep these exclusions synchronized with the ones in the sbt build (Build.scala)
248+
val backendExcluded =
249+
List("JavaPlatform.scala", "Platform.scala", "ScalaPrimitives.scala")
250+
val backendJvmExcluded =
251+
List("BCodeICodeCommon.scala", "GenASM.scala", "GenBCode.scala", "ScalacBackendInterface.scala")
252+
253+
val backendSources =
254+
sources(Files.list(backendDir), excludedFiles = backendExcluded)
255+
val backendJvmSources =
256+
sources(Files.list(backendJvmDir), excludedFiles = backendJvmExcluded)
257+
258+
def dotty1 = {
259+
compileList(
260+
"dotty1",
261+
compilerSources ++ backendSources ++ backendJvmSources,
262+
opt)
263+
}
232264

233265
def dotty2 =
234266
compileShallowFilesInDir("../compiler/src/dotty", opt)
@@ -247,7 +279,9 @@ class CompilationTests extends ParallelTesting {
247279
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc/rewrite", opt) +
248280
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc/transform", opt) +
249281
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc/typer", opt) +
250-
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc/util", opt)
282+
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc/util", opt) +
283+
compileList("shallow-backend", backendSources, opt) +
284+
compileList("shallow-backend-jvm", backendJvmSources, opt)
251285
} :: Nil
252286
}.map(_.checkCompile()).foreach(_.delete())
253287
}

docs/docs/contributing/backend.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
layout: doc-page
3+
title: Working with the backend
4+
---
5+
6+
The compiler backend is based on a fork of the Scala 2.11 `GenBCode` backend and
7+
lives at https://github.com/lampepfl/scala/tree/sharing-backend. The dotty
8+
source tree contains a git submodule in the directory
9+
[scala-backend](https://github.com/lampepfl/dotty/tree/master/scala-backend)
10+
that points to this fork. We do not compile every file in this submodule,
11+
instead we add the subset of files we need to the dotty-compiler project in the
12+
sbt build.
13+
14+
The most important thing to know when working with git submodules is that
15+
their content is not automatically updated when you do `git checkout` or `git
16+
pull`, instead everytime you switch branch, you need to do:
17+
18+
``` shell
19+
git submodule update --init
20+
```
21+
22+
## Environment setup
23+
24+
1. Set the following git configuration options to make working with submodules
25+
easier, see the [Git Book](https://git-scm.com/book/en/v2/Git-Tools-Submodules)
26+
for more information:
27+
``` shell
28+
git config --global diff.submodule log
29+
git config --global status.submodulesummary 1
30+
git config --global push.recurseSubmodules check
31+
```
32+
33+
2. Fork https://github.com/lampepfl/scala (in the following commands,
34+
`dotty-staging/scala` is used as a placeholder for your
35+
own fork).
36+
3. ```shell
37+
cd scala-backend
38+
git remote add scala-staging [email protected]:dotty-staging/scala.git
39+
cd ..
40+
```
41+
42+
## Workflow when changing to the backend
43+
44+
```shell
45+
cd scala-backend
46+
git checkout -b my-feature-branch
47+
# Make some changes ...
48+
49+
git push -u scala-backend
50+
# Open a PR against https://github.com/lampepfl/scala/tree/sharing-backend
51+
cd ..
52+
```
53+
54+
Once your PR has been merged into the backend, you'll need to make another PR
55+
against dotty itself to update the backend, the following commands should be run
56+
in the root dotty repository, not in the submodule:
57+
58+
``` shell
59+
# The --remote option will update the submodule to the latest commit in the
60+
# https://github.com/lampepfl/dotty/tree/master/scala-backend branch
61+
git submodule update --init --remote
62+
63+
git commit -am "Update backend to include ..."
64+
# Then push and make a PR against dotty as usual
65+
```

docs/docs/contributing/eclipse.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,19 @@ title: Building Dotty with Eclipse
55

66
Build setup
77
-----------
8-
You may need to redo these steps when the build changes.
98

109
1. Run `sbt eclipse`
11-
2. In dotty, go to `Properties > java build path > Libraries`.
12-
Remove the Scala Compiler container (currently 2.11.4) and add as an
13-
external jar the latest compiler version in the Ivy cache. This is
14-
currently:
1510

16-
```
17-
.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-2.11.5-20160322-171045-e19b30b3cd.jar
18-
```
19-
20-
But that might change in the future. Or, copy the latest scala compiler from
21-
the cache to a stable name and use that as external jar.
22-
23-
3. It is recommended to change the default output folder (in `Properties > java
11+
2. It is recommended to change the default output folder (in `Properties > java
2412
build path > Source`) to `dotty/classes` instead of `dotty/bin` because
2513
`dotty/bin` is reserved for shell scripts.
2614

2715
If you have `CLASSPATH` defined:
2816

29-
4. Update your classpath to contain any new required external libraries to run
17+
3. Update your classpath to contain any new required external libraries to run
3018
`./bin/dotc`, `./bin/dotr` outside of Eclipse.
3119

32-
5. Open the `Run Configurations` tab, and edit the `tests` configuration so
20+
4. Open the `Run Configurations` tab, and edit the `tests` configuration so
3321
that it contains a `CLASSPATH` variable which reflects the current
3422
`CLASSPATH`.
3523

docs/docs/contributing/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Compiling and Running
2424
Start by cloning the repository:
2525

2626
```bash
27-
$ git clone https://github.com/lampepfl/dotty.git
27+
$ git clone --recursive https://github.com/lampepfl/dotty.git
2828
$ cd dotty
2929
```
3030

docs/docs/contributing/workflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This document details common workflow patterns when working with Dotty.
99

1010
```bash
1111
# Start by cloning the repository:
12-
git clone https://github.com/lampepfl/dotty.git
12+
git clone --recursive https://github.com/lampepfl/dotty.git
1313
cd dotty
1414
# Clone dotty-compatible stdlib. Needed for running the test suite.
1515
git clone -b dotty-library https://github.com/DarkDimius/scala.git scala-scala

0 commit comments

Comments
 (0)