Skip to content

Commit 1055156

Browse files
committed
Merge remote-tracking branch 'origin/master' into promotion-rule-2
2 parents ed95b88 + 0dbe970 commit 1055156

File tree

232 files changed

+3011
-1031
lines changed

Some content is hidden

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

232 files changed

+3011
-1031
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,6 @@
184184
[submodule "community-build/community-projects/akka"]
185185
path = community-build/community-projects/akka
186186
url = https://github.com/dotty-staging/akka.git
187+
[submodule "community-build/community-projects/protoquill"]
188+
path = community-build/community-projects/protoquill
189+
url = https://github.com/dotty-staging/protoquill.git
Submodule protoquill added at 5246493

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ final case class SbtCommunityProject(
9191
dependencies: List[CommunityProject] = Nil,
9292
sbtPublishCommand: String = null,
9393
sbtDocCommand: String = null,
94-
scalacOptions: List[String] = List("-Ycheck-init")
94+
scalacOptions: List[String] = SbtCommunityProject.scalacOptions
9595
) extends CommunityProject:
9696
override val binaryName: String = "sbt"
9797

@@ -127,6 +127,12 @@ final case class SbtCommunityProject(
127127
s"--addPluginSbtFile=$sbtPluginFilePath"
128128
)
129129

130+
object SbtCommunityProject:
131+
def scalacOptions = List(
132+
"-Ycheck:macros",
133+
"-Ycheck-init",
134+
)
135+
130136
object projects:
131137

132138
private def forceDoc(projects: String*) =
@@ -452,6 +458,7 @@ object projects:
452458
project = "verify",
453459
sbtTestCommand = "verifyJVM/test",
454460
sbtDocCommand = "verifyJVM/doc",
461+
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ycheck:macros") // TODO enable -Ycheck:macros
455462
)
456463

457464
lazy val discipline = SbtCommunityProject(
@@ -473,7 +480,7 @@ object projects:
473480
sbtTestCommand = "test",
474481
sbtPublishCommand = "coreJVM/publishLocal;coreJS/publishLocal",
475482
dependencies = List(discipline),
476-
scalacOptions = Nil // disable -Ycheck-init
483+
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ycheck-init")
477484
)
478485

479486
lazy val simulacrumScalafixAnnotations = SbtCommunityProject(
@@ -487,7 +494,8 @@ object projects:
487494
sbtTestCommand = "set scalaJSStage in Global := FastOptStage;buildJVM;validateAllJS",
488495
sbtPublishCommand = "catsJVM/publishLocal;catsJS/publishLocal",
489496
dependencies = List(discipline, disciplineMunit, scalacheck, simulacrumScalafixAnnotations),
490-
scalacOptions = Nil // disable -Ycheck-init, due to -Xfatal-warning
497+
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ycheck-init") // disable -Ycheck-init, due to -Xfatal-warning
498+
491499
)
492500

493501
lazy val catsMtl = SbtCommunityProject(
@@ -598,6 +606,14 @@ object projects:
598606
dependencies = List(scalatest, scalatestplusJunit, scalatestplusScalacheck)
599607
)
600608

609+
lazy val protoquill = SbtCommunityProject(
610+
project = "protoquill",
611+
sbtTestCommand = "test",
612+
sbtPublishCommand = "publishLocal",
613+
dependencies = List(), // TODO add scalatest and pprint (see protoquill/build.sbt)
614+
scalacOptions = List("-language:implicitConversions"), // disabled -Ycheck-init, due to bug in macro
615+
)
616+
601617
end projects
602618

603619
def allProjects = List(
@@ -663,6 +679,7 @@ def allProjects = List(
663679
projects.izumiReflect,
664680
projects.perspective,
665681
projects.akka,
682+
projects.protoquill,
666683
)
667684

668685
lazy val projectMap = allProjects.groupBy(_.project)

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class CommunityBuildTestA extends CommunityBuildTest:
108108
@Test def upickle = projects.upickle.run()
109109
@Test def utest = projects.utest.run()
110110
@Test def zio = projects.zio.run()
111+
@Test def protoquill = projects.protoquill.run()
111112

112113
// 'scala-stm' and 'Sciss/Lucre':
113114
// @Test def scissEqual = projects.scissEqual .run()

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
335335
emitAssocs(av, assocs, BCodeHelpers.this)(this)
336336
}
337337

338+
/*
339+
* must-single-thread
340+
*/
341+
def emitParamNames(jmethod: asm.MethodVisitor, params: List[Symbol]) =
342+
for param <- params do
343+
var access = asm.Opcodes.ACC_FINAL
344+
jmethod.visitParameter(param.name.mangledString, access)
345+
338346
/*
339347
* must-single-thread
340348
*/

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
615615
/*
616616
* must-single-thread
617617
*/
618-
def initJMethod(flags: Int, paramAnnotations: List[List[Annotation]]): Unit = {
618+
def initJMethod(flags: Int, params: List[Symbol]): Unit = {
619619

620620
val jgensig = getGenericSignature(methSymbol, claszSymbol)
621621
val (excs, others) = methSymbol.annotations.partition(_.symbol eq defn.ThrowsAnnot)
@@ -637,7 +637,8 @@ trait BCodeSkelBuilder extends BCodeHelpers {
637637
// TODO param names: (m.params map (p => javaName(p.sym)))
638638

639639
emitAnnotations(mnode, others)
640-
emitParamAnnotations(mnode, paramAnnotations)
640+
emitParamNames(mnode, params)
641+
emitParamAnnotations(mnode, params.map(_.annotations))
641642

642643
} // end of method initJMethod
643644

@@ -749,7 +750,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
749750
.addFlagIf(isNative, asm.Opcodes.ACC_NATIVE) // native methods of objects are generated in mirror classes
750751

751752
// TODO needed? for(ann <- m.symbol.annotations) { ann.symbol.initialize }
752-
initJMethod(flags, params.map(p => p.symbol.annotations))
753+
initJMethod(flags, params.map(_.symbol))
753754

754755

755756
if (!isAbstractMethod && !isNative) {

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Compiler {
4242
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files
4343
List(new PostTyper) :: // Additional checks and cleanups after type checking
4444
List(new sjs.PrepJSInterop) :: // Additional checks and transformations for Scala.js (Scala.js only)
45-
List(new Staging) :: // Check PCP, heal quoted types and expand macros
4645
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
4746
List(new SetRootTree) :: // Set the `rootTreeOrProvider` on class symbols
4847
Nil
@@ -51,6 +50,7 @@ class Compiler {
5150
protected def picklerPhases: List[List[Phase]] =
5251
List(new Pickler) :: // Generate TASTY info
5352
List(new Inlining) :: // Inline and execute macros
53+
List(new Staging) :: // Check staging levels and heal staged types
5454
List(new PickleQuotes) :: // Turn quoted trees into explicit run-time data structures
5555
Nil
5656

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,30 @@ class Driver {
6464

6565
protected def sourcesRequired: Boolean = true
6666

67-
def setup(args: Array[String], rootCtx: Context): (List[AbstractFile], Context) = {
67+
protected def command: CompilerCommand = ScalacCommand
68+
69+
/** Setup context with initialized settings from CLI arguments, then check if there are any settings that
70+
* would change the default behaviour of the compiler.
71+
*
72+
* @return If there is no setting like `-help` preventing us from continuing compilation,
73+
* this method returns a list of files to compile and an updated Context.
74+
* If compilation should be interrupted, this method returns None.
75+
*/
76+
def setup(args: Array[String], rootCtx: Context): Option[(List[AbstractFile], Context)] = {
6877
val ictx = rootCtx.fresh
69-
val summary = CompilerCommand.distill(args)(using ictx)
78+
val summary = command.distill(args, ictx.settings)(ictx.settingsState)(using ictx)
7079
ictx.setSettings(summary.sstate)
7180
MacroClassLoader.init(ictx)
7281
Positioned.init(using ictx)
7382

7483
inContext(ictx) {
7584
if !ctx.settings.YdropComments.value || ctx.mode.is(Mode.ReadComments) then
7685
ictx.setProperty(ContextDoc, new ContextDocstrings)
77-
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)
78-
val files = fileNames.map(ctx.getFile)
79-
(files, fromTastySetup(files))
86+
val fileNamesOrNone = command.checkUsage(summary, sourcesRequired)(using ctx.settings)(using ctx.settingsState)
87+
fileNamesOrNone.map { fileNames =>
88+
val files = fileNames.map(ctx.getFile)
89+
(files, fromTastySetup(files))
90+
}
8091
}
8192
}
8293

@@ -182,8 +193,11 @@ class Driver {
182193
* if compilation succeeded.
183194
*/
184195
def process(args: Array[String], rootCtx: Context): Reporter = {
185-
val (files, compileCtx) = setup(args, rootCtx)
186-
doCompile(newCompiler(using compileCtx), files)(using compileCtx)
196+
setup(args, rootCtx) match
197+
case Some((files, compileCtx)) =>
198+
doCompile(newCompiler(using compileCtx), files)(using compileCtx)
199+
case None =>
200+
rootCtx.reporter
187201
}
188202

189203
def main(args: Array[String]): Unit = {

compiler/src/dotty/tools/dotc/Resident.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ class Resident extends Driver {
4040

4141
final override def process(args: Array[String], rootCtx: Context): Reporter = {
4242
@tailrec def loop(args: Array[String], prevCtx: Context): Reporter = {
43-
var (files, ctx) = setup(args, prevCtx)
44-
inContext(ctx) { doCompile(residentCompiler, files) }
45-
var nextCtx = ctx
46-
var line = getLine()
47-
while (line == reset) {
48-
nextCtx = rootCtx
49-
line = getLine()
50-
}
51-
if (line.startsWith(quit)) ctx.reporter
52-
else loop(line split "\\s+", nextCtx)
43+
setup(args, prevCtx) match
44+
case Some((files, ctx)) =>
45+
inContext(ctx) {
46+
doCompile(residentCompiler, files)
47+
}
48+
var nextCtx = ctx
49+
var line = getLine()
50+
while (line == reset) {
51+
nextCtx = rootCtx
52+
line = getLine()
53+
}
54+
if (line.startsWith(quit)) ctx.reporter
55+
else loop(line split "\\s+", nextCtx)
56+
case None =>
57+
prevCtx.reporter
5358
}
5459
loop(args, rootCtx)
5560
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.tools.dotc
2+
3+
import config.Properties._
4+
import config.CompilerCommand
5+
6+
object ScalacCommand extends CompilerCommand:
7+
override def cmdName: String = "scalac"
8+
override def versionMsg: String = s"Scala compiler $versionString -- $copyrightString"
9+
override def ifErrorsMsg: String = " scalac -help gives more information"

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,14 +914,22 @@ object desugar {
914914
def badRightAssoc(problem: String) =
915915
report.error(i"right-associative extension method $problem", mdef.srcPos)
916916
ext.paramss ++ mdef.paramss
917-
params1 match
917+
def noVParam = badRightAssoc("must start with a single parameter")
918+
def checkVparam(params: ParamClause) = params match
918919
case ValDefs(vparam :: Nil) =>
919920
if !vparam.mods.is(Given) then
920921
val (leadingUsing, otherExtParamss) = ext.paramss.span(isUsingOrTypeParamClause)
921922
leadingUsing ::: params1 :: otherExtParamss ::: paramss1
922923
else badRightAssoc("cannot start with using clause")
923924
case _ =>
924-
badRightAssoc("must start with a single parameter")
925+
noVParam
926+
params1 match
927+
case TypeDefs(_) => paramss1 match
928+
case params2 :: _ => checkVparam(params2)
929+
case _ => noVParam
930+
case _ =>
931+
checkVparam(params1)
932+
925933
case _ =>
926934
ext.paramss ++ mdef.paramss
927935
).withMods(mdef.mods | ExtensionMethod)

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,16 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
251251
case TypeDefs(_) => true
252252
case _ => isUsingClause(params)
253253

254+
private val languageSubCategories = Set(nme.experimental, nme.deprecated)
255+
254256
/** If `path` looks like a language import, `Some(name)` where name
255257
* is `experimental` if that sub-module is imported, and the empty
256258
* term name otherwise.
257259
*/
258260
def languageImport(path: Tree): Option[TermName] = path match
259-
case Select(p1, nme.experimental) =>
261+
case Select(p1, name: TermName) if languageSubCategories.contains(name) =>
260262
languageImport(p1) match
261-
case Some(EmptyTermName) => Some(nme.experimental)
263+
case Some(EmptyTermName) => Some(name)
262264
case _ => None
263265
case p1: RefTree if p1.name == nme.language =>
264266
p1.qualifier match
@@ -936,10 +938,15 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
936938
* The result can be the contents of a term or type quote, which
937939
* will return a term or type tree respectively.
938940
*/
939-
def unapply(tree: tpd.Tree)(using Context): Option[tpd.Tree] = tree match {
940-
case tree: GenericApply if tree.symbol.isQuote => Some(tree.args.head)
941-
case _ => None
942-
}
941+
def unapply(tree: tpd.Apply)(using Context): Option[tpd.Tree] =
942+
if tree.symbol == defn.QuotedRuntime_exprQuote then
943+
// quoted.runtime.Expr.quote[T](<body>)
944+
Some(tree.args.head)
945+
else if tree.symbol == defn.QuotedTypeModule_of then
946+
// quoted.Type.of[<body>](quotes)
947+
val TypeApply(_, body :: _) = tree.fun
948+
Some(body)
949+
else None
943950
}
944951

945952
/** Extractors for splices */

compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
2626
* - be tail-recursive where possible
2727
* - don't re-allocate trees where nothing has changed
2828
*/
29-
def transformStats(stats: List[Tree], exprOwner: Symbol)(using Context): List[Tree] = {
29+
override def transformStats(stats: List[Tree], exprOwner: Symbol)(using Context): List[Tree] = {
3030

3131
@tailrec def traverse(curStats: List[Tree])(using Context): List[Tree] = {
3232

@@ -85,23 +85,23 @@ class TreeMapWithImplicits extends tpd.TreeMap {
8585
}
8686

8787
override def transform(tree: Tree)(using Context): Tree = {
88-
def localCtx =
89-
if (tree.hasType && tree.symbol.exists) ctx.withOwner(tree.symbol) else ctx
9088
try tree match {
91-
case tree: Block =>
92-
super.transform(tree)(using nestedScopeCtx(tree.stats))
89+
case Block(stats, expr) =>
90+
inContext(nestedScopeCtx(stats)) {
91+
if stats.exists(_.isInstanceOf[Import]) then
92+
// need to transform stats and expr together to account for import visibility
93+
val stats1 = transformStats(stats :+ expr, ctx.owner)
94+
cpy.Block(tree)(stats1.init, stats1.last)
95+
else super.transform(tree)
96+
}
9397
case tree: DefDef =>
94-
inContext(localCtx) {
98+
inContext(localCtx(tree)) {
9599
cpy.DefDef(tree)(
96100
tree.name,
97101
transformParamss(tree.paramss),
98102
transform(tree.tpt),
99103
transform(tree.rhs)(using nestedScopeCtx(tree.paramss.flatten)))
100104
}
101-
case EmptyValDef =>
102-
tree
103-
case _: PackageDef | _: MemberDef =>
104-
super.transform(tree)(using localCtx)
105105
case impl @ Template(constr, parents, self, _) =>
106106
cpy.Template(tree)(
107107
transformSub(constr),

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class TreeTypeMap(
130130
}
131131
}
132132

133-
override def transformStats(trees: List[tpd.Tree])(using Context): List[Tree] =
133+
override def transformStats(trees: List[tpd.Tree], exprOwner: Symbol)(using Context): List[Tree] =
134134
transformDefs(trees)._2
135135

136136
def transformDefs[TT <: tpd.Tree](trees: List[TT])(using Context): (TreeTypeMap, List[TT]) = {

0 commit comments

Comments
 (0)