Skip to content

Commit 13e5024

Browse files
committed
Merge remote-tracking branch 'origin/main' into scaladoc/new-ui
2 parents 8228388 + 65a86ae commit 13e5024

File tree

596 files changed

+11240
-3794
lines changed

Some content is hidden

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

596 files changed

+11240
-3794
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches-ignore:
66
- 'language-reference-stable'
7+
tags:
8+
- '**'
79
pull_request:
810
branches-ignore:
911
- 'language-reference-stable'
@@ -69,8 +71,13 @@ jobs:
6971
run: cp -vf .github/workflows/repositories /root/.sbt/ ; true
7072

7173
- name: Test
74+
# DON'T add dist/pack!
75+
# Adding dist/pack bootstraps the compiler
76+
# which undermines the point of these tests:
77+
# to quickly run the tests without the cost of bootstrapping
78+
# and also to run tests when the compiler doesn't bootstrap
7279
run: |
73-
./project/scripts/sbt ";dist/pack; compile ;test"
80+
./project/scripts/sbt ";compile ;test"
7481
./project/scripts/cmdTests
7582
7683
test:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package dotty.tools.benchmarks
2+
3+
import org.openjdk.jmh.annotations.*
4+
import java.util.concurrent.TimeUnit.SECONDS
5+
import dotty.tools.dotc.{Driver, Run, Compiler}
6+
import dotty.tools.dotc.core.Mode
7+
import dotty.tools.dotc.core.Types.{TermRef, Type}
8+
import dotty.tools.dotc.core.Contexts.{ContextBase, Context, ctx, withMode}
9+
10+
@Fork(value = 5)
11+
@Warmup(iterations = 5, time = 1, timeUnit = SECONDS)
12+
@Measurement(iterations = 5, time = 1, timeUnit = SECONDS)
13+
@State(Scope.Thread)
14+
class TypeOpsBenchmark:
15+
var tp: Type = null
16+
var context: Context = null
17+
18+
@Param(Array("int", "singletonsSum", "intsSum", "deepSingletonsSum", "deepIntsSum", "singletonsIntersection", "singletonsUnion"))
19+
var valName: String = "int"
20+
21+
@Setup(Level.Iteration)
22+
def setup(): Unit =
23+
val driver = new Driver:
24+
override def finish(compiler: Compiler, run: Run)(using Context): Unit =
25+
withMode(Mode.Printing) {
26+
val pkg = run.units(0).tpdTree.symbol
27+
tp = pkg.requiredClass("Test").requiredValueRef(valName).underlying
28+
context = ctx
29+
}
30+
super.finish(compiler, run)
31+
driver.process(Array(
32+
"-classpath", System.getProperty("BENCH_CLASS_PATH"),
33+
"-Ystop-after:typer",
34+
"tests/someTypes.scala"
35+
))
36+
37+
@Benchmark
38+
def isStable(): Unit = tp.isStable(using context)
39+
40+
@Benchmark
41+
def normalized(): Unit = tp.normalized(using context)
42+
43+
@Benchmark
44+
def simplified(): Unit = tp.simplified(using context)
45+
46+
@Benchmark
47+
def dealias(): Unit = tp.dealias(using context)
48+
49+
@Benchmark
50+
def widen(): Unit = tp.widen(using context)
51+
52+
@Benchmark
53+
def atoms(): Unit = tp.atoms(using context)
54+
55+
@Benchmark
56+
def isProvisional(): Unit = tp.isProvisional(using context)

bench-micro/tests/someTypes.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import compiletime.ops.int.+
2+
3+
class Test:
4+
val int: Int = 5
5+
6+
val int2: Int = 6
7+
8+
val singletonsSum: int.type + int2.type = ???
9+
10+
val intsSum: Int + Int = ???
11+
12+
val deepSingletonsSum:
13+
((int.type + int2.type) + (int.type + int2.type)) + ((int.type + int2.type) + (int.type + int2.type)) +
14+
((int.type + int2.type) + (int.type + int2.type)) + ((int.type + int2.type) + (int.type + int2.type)) = ???
15+
16+
val deepIntsSum:
17+
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) +
18+
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) = ???
19+
20+
val singletonsIntersection: int.type & int2.type = ???
21+
22+
val singletonsUnion: int.type | int2.type = ???

bench/src/main/scala/Benchmarks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.openjdk.jmh.results.format._
1515
import java.util.concurrent.TimeUnit
1616

1717
import java.io.{File, FileOutputStream, BufferedWriter, FileWriter}
18-
import scala.collection.JavaConverters._
18+
import scala.jdk.CollectionConverters._
1919
import scala.io.Source
2020
import scala.util.Using
2121

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ val `scala3-tasty-inspector` = Build.`scala3-tasty-inspector`
1313
val `scala3-language-server` = Build.`scala3-language-server`
1414
val `scala3-bench` = Build.`scala3-bench`
1515
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
16+
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1617
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
1718
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
1819
val `tasty-core` = Build.`tasty-core`
Submodule scas updated 92 files

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def log(msg: String) = println(Console.GREEN + msg + Console.RESET)
2222

2323
/** Executes shell command, returns false in case of error. */
2424
def exec(projectDir: Path, binary: String, arguments: Seq[String], environment: Map[String, String]): Int =
25-
import collection.JavaConverters._
25+
import scala.jdk.CollectionConverters._
2626
val command = binary +: arguments
2727
log(command.mkString(" "))
2828
val builder = new ProcessBuilder(command: _*).directory(projectDir.toFile).inheritIO()
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
package dotty.tools
2+
3+
import scala.language.unsafeNulls
4+
5+
import scala.annotation.tailrec
6+
import scala.io.Source
7+
import scala.util.Try
8+
import java.io.File
9+
import java.lang.Thread
10+
import scala.annotation.internal.sharable
11+
import dotty.tools.dotc.util.ClasspathFromClassloader
12+
import dotty.tools.runner.ObjectRunner
13+
import dotty.tools.dotc.config.Properties.envOrNone
14+
import dotty.tools.io.Jar
15+
import dotty.tools.runner.ScalaClassLoader
16+
import java.nio.file.Paths
17+
import dotty.tools.dotc.config.CommandLineParser
18+
import dotty.tools.scripting.StringDriver
19+
20+
enum CompileMode:
21+
case Guess
22+
case Compile
23+
case Decompile
24+
case PrintTasty
25+
case Script
26+
case Repl
27+
case Run
28+
29+
case class CompileSettings(
30+
verbose: Boolean = false,
31+
classPath: List[String] = List.empty,
32+
compileMode: CompileMode = CompileMode.Guess,
33+
exitCode: Int = 0,
34+
javaArgs: List[String] = List.empty,
35+
javaProps: List[(String, String)] = List.empty,
36+
scalaArgs: List[String] = List.empty,
37+
residualArgs: List[String] = List.empty,
38+
scriptArgs: List[String] = List.empty,
39+
targetScript: String = "",
40+
compiler: Boolean = false,
41+
quiet: Boolean = false,
42+
colors: Boolean = false,
43+
) {
44+
def withCompileMode(em: CompileMode): CompileSettings = this.compileMode match
45+
case CompileMode.Guess =>
46+
this.copy(compileMode = em)
47+
case _ =>
48+
println(s"compile_mode==[$compileMode], attempted overwrite by [$em]")
49+
this.copy(exitCode = 1)
50+
end withCompileMode
51+
52+
def withScalaArgs(args: String*): CompileSettings =
53+
this.copy(scalaArgs = scalaArgs.appendedAll(args.toList.filter(_.nonEmpty)))
54+
55+
def withJavaArgs(args: String*): CompileSettings =
56+
this.copy(javaArgs = javaArgs.appendedAll(args.toList.filter(_.nonEmpty)))
57+
58+
def withJavaProps(args: (String, String)*): CompileSettings =
59+
this.copy(javaProps = javaProps.appendedAll(args.toList))
60+
61+
def withResidualArgs(args: String*): CompileSettings =
62+
this.copy(residualArgs = residualArgs.appendedAll(args.toList.filter(_.nonEmpty)))
63+
64+
def withScriptArgs(args: String*): CompileSettings =
65+
this.copy(scriptArgs = scriptArgs.appendedAll(args.toList.filter(_.nonEmpty)))
66+
67+
def withTargetScript(file: String): CompileSettings =
68+
Try(Source.fromFile(file)).toOption match
69+
case Some(_) => this.copy(targetScript = file)
70+
case None =>
71+
println(s"not found $file")
72+
this.copy(exitCode = 2)
73+
end withTargetScript
74+
75+
def withCompiler: CompileSettings =
76+
this.copy(compiler = true)
77+
78+
def withQuiet: CompileSettings =
79+
this.copy(quiet = true)
80+
81+
def withColors: CompileSettings =
82+
this.copy(colors = true)
83+
84+
def withNoColors: CompileSettings =
85+
this.copy(colors = false)
86+
}
87+
88+
object MainGenericCompiler {
89+
90+
val classpathSeparator = File.pathSeparator
91+
92+
@sharable val javaOption = raw"""-J(.*)""".r
93+
@sharable val javaPropOption = raw"""-D(.+?)=(.?)""".r
94+
@tailrec
95+
def process(args: List[String], settings: CompileSettings): CompileSettings = args match
96+
case Nil =>
97+
settings
98+
case "--" :: tail =>
99+
process(Nil, settings.withResidualArgs(tail.toList*))
100+
case ("-v" | "-verbose" | "--verbose") :: tail =>
101+
process(tail, settings.withScalaArgs("-verbose"))
102+
case ("-q" | "-quiet") :: tail =>
103+
process(tail, settings.withQuiet)
104+
case "-repl" :: tail =>
105+
process(tail, settings.withCompileMode(CompileMode.Repl))
106+
case "-script" :: targetScript :: tail =>
107+
process(Nil, settings
108+
.withCompileMode(CompileMode.Script)
109+
.withJavaProps("script.path" -> targetScript)
110+
.withTargetScript(targetScript)
111+
.withScriptArgs(tail*))
112+
case "-compile" :: tail =>
113+
process(tail, settings.withCompileMode(CompileMode.Compile))
114+
case "-decompile" :: tail =>
115+
process(tail, settings.withCompileMode(CompileMode.Decompile))
116+
case "-print-tasty" :: tail =>
117+
process(tail, settings.withCompileMode(CompileMode.PrintTasty))
118+
case "-run" :: tail =>
119+
process(tail, settings.withCompileMode(CompileMode.Run))
120+
case "-colors" :: tail =>
121+
process(tail, settings.withColors)
122+
case "-no-colors" :: tail =>
123+
process(tail, settings.withNoColors)
124+
case "-with-compiler" :: tail =>
125+
process(tail, settings.withCompiler)
126+
case ("-cp" | "-classpath" | "--class-path") :: cp :: tail =>
127+
val (tailargs, newEntries) = MainGenericRunner.processClasspath(cp, tail)
128+
process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty)))
129+
case "-Oshort" :: tail =>
130+
// Nothing is to be done here. Request that the user adds the relevant flags manually.
131+
// i.e this has no effect when MainGenericRunner is invoked programatically.
132+
val addTC="-XX:+TieredCompilation"
133+
val tStopAtLvl="-XX:TieredStopAtLevel=1"
134+
println(s"ignoring deprecated -Oshort flag, please add `-J$addTC` and `-J$tStopAtLvl` flags manually")
135+
process(tail, settings)
136+
case javaOption(stripped) :: tail =>
137+
process(tail, settings.withJavaArgs(stripped))
138+
case javaPropOption(opt, value) :: tail =>
139+
process(tail, settings.withJavaProps(opt -> value))
140+
case arg :: tail =>
141+
process(tail, settings.withResidualArgs(arg))
142+
end process
143+
144+
def main(args: Array[String]): Unit =
145+
val settings = process(args.toList, CompileSettings())
146+
if settings.exitCode != 0 then System.exit(settings.exitCode)
147+
148+
def classpathSetting =
149+
if settings.classPath.isEmpty then List()
150+
else List("-classpath", settings.classPath.mkString(classpathSeparator))
151+
152+
def reconstructedArgs() =
153+
classpathSetting ++ settings.scalaArgs ++ settings.residualArgs
154+
155+
def addJavaProps(): Unit =
156+
settings.javaProps.foreach { (k, v) => sys.props(k) = v }
157+
158+
def run(settings: CompileSettings): Unit = settings.compileMode match
159+
case CompileMode.Compile =>
160+
addJavaProps()
161+
val properArgs = reconstructedArgs()
162+
dotty.tools.dotc.Main.main(properArgs.toArray)
163+
case CompileMode.Decompile =>
164+
addJavaProps()
165+
val properArgs = reconstructedArgs()
166+
dotty.tools.dotc.decompiler.Main.main(properArgs.toArray)
167+
case CompileMode.PrintTasty =>
168+
addJavaProps()
169+
val properArgs = reconstructedArgs()
170+
dotty.tools.dotc.core.tasty.TastyPrinter.main(properArgs.toArray)
171+
case CompileMode.Script => // Naive copy from scalac bash script
172+
addJavaProps()
173+
val properArgs =
174+
reconstructedArgs()
175+
++ List("-script", settings.targetScript)
176+
++ settings.scriptArgs
177+
scripting.Main.main(properArgs.toArray)
178+
case CompileMode.Repl | CompileMode.Run =>
179+
addJavaProps()
180+
val properArgs = reconstructedArgs()
181+
repl.Main.main(properArgs.toArray)
182+
case CompileMode.Guess =>
183+
run(settings.withCompileMode(CompileMode.Compile))
184+
end run
185+
186+
run(settings)
187+
end main
188+
}

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ object MainGenericRunner {
100100

101101
val classpathSeparator = File.pathSeparator
102102

103+
def processClasspath(cp: String, tail: List[String]): (List[String], List[String]) =
104+
val cpEntries = cp.split(classpathSeparator).toList
105+
val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1
106+
val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic
107+
def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip")))
108+
if singleEntryClasspath && validGlobbedJar(cpEntries.head) then
109+
// reassemble globbed wildcard classpath
110+
// globdir is wildcard directory for globbed jar files, reconstruct the intended classpath
111+
val cpJars = tail.takeWhile( f => validGlobbedJar(f) )
112+
val remainingArgs = tail.drop(cpJars.size)
113+
(remainingArgs, cpEntries ++ cpJars)
114+
else
115+
(tail, cpEntries)
116+
103117
@sharable val javaOption = raw"""-J(.*)""".r
104118
@sharable val scalaOption = raw"""@.*""".r
105119
@sharable val colorOption = raw"""-color:.*""".r
@@ -110,21 +124,8 @@ object MainGenericRunner {
110124
case "-run" :: fqName :: tail =>
111125
process(tail, settings.withExecuteMode(ExecuteMode.Run).withTargetToRun(fqName))
112126
case ("-cp" | "-classpath" | "--class-path") :: cp :: tail =>
113-
val cpEntries = cp.split(classpathSeparator).toList
114-
val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1
115-
val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic
116-
def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip")))
117-
val (tailargs, newEntries) = if singleEntryClasspath && validGlobbedJar(cpEntries.head) then
118-
// reassemble globbed wildcard classpath
119-
// globdir is wildcard directory for globbed jar files, reconstruct the intended classpath
120-
val cpJars = tail.takeWhile( f => validGlobbedJar(f) )
121-
val remainingArgs = tail.drop(cpJars.size)
122-
(remainingArgs, cpEntries ++ cpJars)
123-
else
124-
(tail, cpEntries)
125-
127+
val (tailargs, newEntries) = processClasspath(cp, tail)
126128
process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty)))
127-
128129
case ("-version" | "--version") :: _ =>
129130
settings.copy(
130131
executeMode = ExecuteMode.Repl,
@@ -170,7 +171,7 @@ object MainGenericRunner {
170171
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
171172
process(tail, newSettings.withResidualArgs(arg))
172173
end process
173-
174+
174175
def main(args: Array[String]): Unit =
175176
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty)
176177
val allArgs = scalaOpts ++ args

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
138138
* `refedInnerClasses` may contain duplicates, need not contain the enclosing inner classes of
139139
* each inner class it lists (those are looked up and included).
140140
*
141-
* This method serializes in the InnerClasses JVM attribute in an appropriate order,
141+
* This method serializes in the InnerClasses JVM attribute in an appropriate order,
142142
* not necessarily that given by `refedInnerClasses`.
143143
*
144144
* can-multi-thread

0 commit comments

Comments
 (0)