Skip to content

Commit c9c5853

Browse files
authored
Merge branch 'main' into 17266
2 parents 8414ab6 + ed319e8 commit c9c5853

File tree

418 files changed

+34892
-7195
lines changed

Some content is hidden

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

418 files changed

+34892
-7195
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134

135135
- name: Cmd Tests
136136
run: |
137-
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
137+
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped-tasty-tests/run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
138138
./project/scripts/cmdTests
139139
./project/scripts/bootstrappedOnlyCmdTests
140140
@@ -488,7 +488,7 @@ jobs:
488488

489489
- name: Test
490490
run: |
491-
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test"
491+
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped-tasty-tests/run ;stdlib-bootstrapped-tasty-tests/test"
492492
./project/scripts/cmdTests
493493
./project/scripts/bootstrappedOnlyCmdTests
494494

NOTICE.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,19 @@ major authors were omitted by oversight.
8989
details.
9090

9191
* dotty.tools.dotc.coverage: Coverage instrumentation utilities have been
92-
adapted from the scoverage plugin for scala 2 [5], which is under the
92+
adapted from the scoverage plugin for scala 2 [4], which is under the
9393
Apache 2.0 license.
9494

95+
* dooty.tools.pc: Presentation compiler implementation adapted from
96+
scalameta/metals [5] mtags module, which is under the Apache 2.0 license.
97+
9598
* The Dotty codebase contains parts which are derived from
96-
the ScalaPB protobuf library [4], which is under the Apache 2.0 license.
99+
the ScalaPB protobuf library [6], which is under the Apache 2.0 license.
97100

98101

99102
[1] https://github.com/scala/scala
100103
[2] https://github.com/adriaanm/scala/tree/sbt-api-consolidate/src/compiler/scala/tools/sbt
101104
[3] https://github.com/sbt/sbt/tree/0.13/compile/interface/src/main/scala/xsbt
102-
[4] https://github.com/lampepfl/dotty/pull/5783/files
103-
[5] https://github.com/scoverage/scalac-scoverage-plugin
105+
[4] https://github.com/scoverage/scalac-scoverage-plugin
106+
[5] https://github.com/scalameta/metals
107+
[6] https://github.com/lampepfl/dotty/pull/5783/files

build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ val `scala3-bench` = Build.`scala3-bench`
1515
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
1616
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1717
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
18+
val `stdlib-bootstrapped-tasty` = Build.`stdlib-bootstrapped-tasty`
1819
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
1920
val `tasty-core` = Build.`tasty-core`
2021
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`
@@ -28,6 +29,8 @@ val `scala3-bench-run` = Build.`scala3-bench-run`
2829
val dist = Build.dist
2930
val `community-build` = Build.`community-build`
3031
val `sbt-community-build` = Build.`sbt-community-build`
32+
val `scala3-presentation-compiler` = Build.`scala3-presentation-compiler`
33+
val `scala3-presentation-compiler-bootstrapped` = Build.`scala3-presentation-compiler-bootstrapped`
3134

3235
val sjsSandbox = Build.sjsSandbox
3336
val sjsJUnitTests = Build.sjsJUnitTests

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ final case class SbtCommunityProject(
140140
case Some(ivyHome) => List(s"-Dsbt.ivy.home=$ivyHome")
141141
case _ => Nil
142142
extraSbtArgs ++ sbtProps ++ List(
143-
"-sbt-version", "1.8.2",
143+
"-sbt-version", "1.9.0",
144144
"-Dsbt.supershell=false",
145145
s"-Ddotty.communitybuild.dir=$communitybuildDir",
146146
s"--addPluginSbtFile=$sbtPluginFilePath"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class CommunityBuildTestC:
9494
@Test def shapeless = projects.shapeless.run()
9595
@Test def sourcecode = projects.sourcecode.run()
9696
@Test def specs2 = projects.specs2.run()
97+
9798
@Test def stdLib213 = projects.stdLib213.run()
9899
@Test def ujson = projects.ujson.run()
99100
@Test def upickle = projects.upickle.run()

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
2323

2424
def postProcessAndSendToDisk(generatedDefs: GeneratedDefs): Unit = {
2525
val GeneratedDefs(classes, tasty) = generatedDefs
26+
if !ctx.settings.YoutputOnlyTasty.value then
27+
postProcessClassesAndSendToDisk(classes)
28+
postProcessTastyAndSendToDisk(tasty)
29+
}
30+
31+
private def postProcessClassesAndSendToDisk(classes: List[GeneratedClass]): Unit = {
2632
for (GeneratedClass(classNode, sourceFile, isArtifact, onFileCreated) <- classes) {
2733
val bytes =
2834
try
@@ -46,8 +52,10 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
4652
if clsFile != null then onFileCreated(clsFile)
4753
}
4854
}
55+
}
4956

50-
for (GeneratedTasty(classNode, binaryGen) <- tasty){
57+
private def postProcessTastyAndSendToDisk(tasty: List[GeneratedTasty]): Unit = {
58+
for (GeneratedTasty(classNode, binaryGen) <- tasty) {
5159
classfileWriter.writeTasty(classNode.name.nn, binaryGen())
5260
}
5361
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import core._
55
import Contexts._
66
import SymDenotations.ClassDenotation
77
import Symbols._
8+
import Comments.Comment
89
import util.{FreshNameCreator, SourceFile, NoSource}
910
import util.Spans.Span
1011
import ast.{tpd, untpd}
@@ -69,6 +70,9 @@ class CompilationUnit protected (val source: SourceFile) {
6970
/** Can this compilation unit be suspended */
7071
def isSuspendable: Boolean = true
7172

73+
/** List of all comments present in this compilation unit */
74+
var comments: List[Comment] = Nil
75+
7276
/** Suspends the compilation unit by thowing a SuspendException
7377
* and recording the suspended compilation unit
7478
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
308308

309309
private def printTree(last: PrintedTree)(using Context): PrintedTree = {
310310
val unit = ctx.compilationUnit
311-
val fusedPhase = ctx.phase.prevMega
311+
val fusedPhase = ctx.phase.prev.megaPhase
312312
val echoHeader = f"[[syntax trees at end of $fusedPhase%25s]] // ${unit.source}"
313313
val tree = if ctx.isAfterTyper then unit.tpdTree else unit.untpdTree
314314
val treeString = fusedPhase.show(tree)

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

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import printing.Formatting.hl
1919
import config.Printers
2020

2121
import scala.annotation.internal.sharable
22+
import scala.annotation.threadUnsafe
2223

2324
object desugar {
2425
import untpd._
@@ -363,6 +364,31 @@ object desugar {
363364
adaptToExpectedTpt(tree)
364365
}
365366

367+
/** Split out the quoted pattern type variable definition from the pattern.
368+
*
369+
* Type variable definitions are all the `type t` defined at the start of a quoted pattern.
370+
* Where name `t` is a pattern type variable name (i.e. lower case letters).
371+
*
372+
* ```
373+
* type t1; ...; type tn; <pattern>
374+
* ```
375+
* is split into
376+
* ```
377+
* (List(<type t1>; ...; <type tn>), <pattern>)
378+
* ```
379+
*/
380+
def quotedPatternTypeVariables(tree: untpd.Tree)(using Context): (List[untpd.TypeDef], untpd.Tree) =
381+
tree match
382+
case untpd.Block(stats, expr) =>
383+
val (untpdTypeVariables, otherStats) = stats.span {
384+
case tdef @ untpd.TypeDef(name, _) => name.isVarPattern
385+
case _ => false
386+
}
387+
val pattern = if otherStats.isEmpty then expr else untpd.cpy.Block(tree)(otherStats, expr)
388+
(untpdTypeVariables.asInstanceOf[List[untpd.TypeDef]], pattern)
389+
case _ =>
390+
(Nil, tree)
391+
366392
/** Add all evidence parameters in `params` as implicit parameters to `meth`.
367393
* If the parameters of `meth` end in an implicit parameter list or using clause,
368394
* evidence parameters are added in front of that list. Otherwise they are added
@@ -462,6 +488,7 @@ object desugar {
462488
def isNonEnumCase = !isEnumCase && (isCaseClass || isCaseObject)
463489
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
464490
// This is not watertight, but `extends AnyVal` will be replaced by `inline` later.
491+
val caseClassInScala2StdLib = isCaseClass && ctx.settings.Yscala2Stdlib.value
465492

466493
val originalTparams = constr1.leadingTypeParams
467494
val originalVparamss = asTermOnly(constr1.trailingParamss)
@@ -637,10 +664,7 @@ object desugar {
637664
// new C[...](p1, ..., pN)(moreParams)
638665
val (caseClassMeths, enumScaffolding) = {
639666
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
640-
val mods =
641-
if ctx.settings.Yscala2Stdlib.value then synthetic | Inline
642-
else synthetic
643-
DefDef(name, Nil, tpt, rhs).withMods(mods)
667+
DefDef(name, Nil, tpt, rhs).withMods(synthetic)
644668

645669
def productElemMeths =
646670
val caseParams = derivedVparamss.head.toArray
@@ -671,12 +695,14 @@ object desugar {
671695
cpy.ValDef(vparam)(rhs = refOfDef(vparam)))
672696
val copyRestParamss = derivedVparamss.tail.nestedMap(vparam =>
673697
cpy.ValDef(vparam)(rhs = EmptyTree))
698+
var flags = Synthetic | constr1.mods.flags & copiedAccessFlags
699+
if ctx.settings.Yscala2Stdlib.value then flags &~= Private
674700
DefDef(
675701
nme.copy,
676702
joinParams(derivedTparams, copyFirstParams :: copyRestParamss),
677703
TypeTree(),
678704
creatorExpr
679-
).withMods(Modifiers(Synthetic | constr1.mods.flags & copiedAccessFlags, constr1.mods.privateWithin)) :: Nil
705+
).withMods(Modifiers(flags, constr1.mods.privateWithin)) :: Nil
680706
}
681707
}
682708

@@ -730,7 +756,9 @@ object desugar {
730756
if (mods.is(Abstract)) Nil
731757
else {
732758
val appMods =
733-
Modifiers(Synthetic | constr1.mods.flags & copiedAccessFlags).withPrivateWithin(constr1.mods.privateWithin)
759+
var flags = Synthetic | constr1.mods.flags & copiedAccessFlags
760+
if ctx.settings.Yscala2Stdlib.value then flags &~= Private
761+
Modifiers(flags).withPrivateWithin(constr1.mods.privateWithin)
734762
val appParamss =
735763
derivedVparamss.nestedZipWithConserve(constrVparamss)((ap, cp) =>
736764
ap.withMods(ap.mods | (cp.mods.flags & HasDefault)))
@@ -753,7 +781,7 @@ object desugar {
753781
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
754782
val unapplyRHS =
755783
if (arity == 0) Literal(Constant(true))
756-
else if ctx.settings.Yscala2Stdlib.value then scala2LibCompatUnapplyRhs(unapplyParam.name)
784+
else if caseClassInScala2StdLib then scala2LibCompatUnapplyRhs(unapplyParam.name)
757785
else Ident(unapplyParam.name)
758786
val unapplyResTp = if (arity == 0) Literal(Constant(true)) else TypeTree()
759787

@@ -1036,6 +1064,40 @@ object desugar {
10361064
name
10371065
}
10381066

1067+
/** Strip parens and empty blocks around the body of `tree`. */
1068+
def normalizePolyFunction(tree: PolyFunction)(using Context): PolyFunction =
1069+
def stripped(body: Tree): Tree = body match
1070+
case Parens(body1) =>
1071+
stripped(body1)
1072+
case Block(Nil, body1) =>
1073+
stripped(body1)
1074+
case _ => body
1075+
cpy.PolyFunction(tree)(tree.targs, stripped(tree.body)).asInstanceOf[PolyFunction]
1076+
1077+
/** Desugar [T_1, ..., T_M] => (P_1, ..., P_N) => R
1078+
* Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R }
1079+
*/
1080+
def makePolyFunctionType(tree: PolyFunction)(using Context): RefinedTypeTree =
1081+
val PolyFunction(tparams: List[untpd.TypeDef] @unchecked, fun @ untpd.Function(vparamTypes, res)) = tree: @unchecked
1082+
val funFlags = fun match
1083+
case fun: FunctionWithMods =>
1084+
fun.mods.flags
1085+
case _ => EmptyFlags
1086+
1087+
// TODO: make use of this in the desugaring when pureFuns is enabled.
1088+
// val isImpure = funFlags.is(Impure)
1089+
1090+
// Function flags to be propagated to each parameter in the desugared method type.
1091+
val paramFlags = funFlags.toTermFlags & Given
1092+
val vparams = vparamTypes.zipWithIndex.map:
1093+
case (p: ValDef, _) => p.withAddedFlags(paramFlags)
1094+
case (p, n) => makeSyntheticParameter(n + 1, p).withAddedFlags(paramFlags)
1095+
1096+
RefinedTypeTree(ref(defn.PolyFunctionType), List(
1097+
DefDef(nme.apply, tparams :: vparams :: Nil, res, EmptyTree).withFlags(Synthetic)
1098+
)).withSpan(tree.span)
1099+
end makePolyFunctionType
1100+
10391101
/** Invent a name for an anonympus given of type or template `impl`. */
10401102
def inventGivenOrExtensionName(impl: Tree)(using Context): SimpleName =
10411103
val str = impl match
@@ -1429,17 +1491,20 @@ object desugar {
14291491
}
14301492

14311493
/** Make closure corresponding to function.
1432-
* params => body
1494+
* [tparams] => params => body
14331495
* ==>
1434-
* def $anonfun(params) = body
1496+
* def $anonfun[tparams](params) = body
14351497
* Closure($anonfun)
14361498
*/
1437-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree | Null = null, isContextual: Boolean, span: Span)(using Context): Block =
1499+
def makeClosure(tparams: List[TypeDef], vparams: List[ValDef], body: Tree, tpt: Tree | Null = null, span: Span)(using Context): Block =
1500+
val paramss: List[ParamClause] =
1501+
if tparams.isEmpty then vparams :: Nil
1502+
else tparams :: vparams :: Nil
14381503
Block(
1439-
DefDef(nme.ANON_FUN, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
1504+
DefDef(nme.ANON_FUN, paramss, if (tpt == null) TypeTree() else tpt, body)
14401505
.withSpan(span)
14411506
.withMods(synthetic | Artifact),
1442-
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree))
1507+
Closure(Nil, Ident(nme.ANON_FUN), EmptyTree))
14431508

14441509
/** If `nparams` == 1, expand partial function
14451510
*
@@ -1728,62 +1793,6 @@ object desugar {
17281793
}
17291794
}
17301795

1731-
def makePolyFunction(targs: List[Tree], body: Tree, pt: Type): Tree = body match {
1732-
case Parens(body1) =>
1733-
makePolyFunction(targs, body1, pt)
1734-
case Block(Nil, body1) =>
1735-
makePolyFunction(targs, body1, pt)
1736-
case Function(vargs, res) =>
1737-
assert(targs.nonEmpty)
1738-
// TODO: Figure out if we need a `PolyFunctionWithMods` instead.
1739-
val mods = body match {
1740-
case body: FunctionWithMods => body.mods
1741-
case _ => untpd.EmptyModifiers
1742-
}
1743-
val polyFunctionTpt = ref(defn.PolyFunctionType)
1744-
val applyTParams = targs.asInstanceOf[List[TypeDef]]
1745-
if (ctx.mode.is(Mode.Type)) {
1746-
// Desugar [T_1, ..., T_M] -> (P_1, ..., P_N) => R
1747-
// Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R }
1748-
1749-
val applyVParams = vargs.zipWithIndex.map {
1750-
case (p: ValDef, _) => p.withAddedFlags(mods.flags)
1751-
case (p, n) => makeSyntheticParameter(n + 1, p).withAddedFlags(mods.flags.toTermFlags)
1752-
}
1753-
RefinedTypeTree(polyFunctionTpt, List(
1754-
DefDef(nme.apply, applyTParams :: applyVParams :: Nil, res, EmptyTree).withFlags(Synthetic)
1755-
))
1756-
}
1757-
else {
1758-
// Desugar [T_1, ..., T_M] -> (x_1: P_1, ..., x_N: P_N) => body
1759-
// with pt [S_1, ..., S_M] -> (O_1, ..., O_N) => R
1760-
// Into new scala.PolyFunction { def apply[T_1, ..., T_M](x_1: P_1, ..., x_N: P_N): R2 = body }
1761-
// where R2 is R, with all references to S_1..S_M replaced with T1..T_M.
1762-
1763-
def typeTree(tp: Type) = tp match
1764-
case RefinedType(parent, nme.apply, PolyType(_, mt)) if parent.typeSymbol eq defn.PolyFunctionClass =>
1765-
var bail = false
1766-
def mapper(tp: Type, topLevel: Boolean = false): Tree = tp match
1767-
case tp: TypeRef => ref(tp)
1768-
case tp: TypeParamRef => Ident(applyTParams(tp.paramNum).name)
1769-
case AppliedType(tycon, args) => AppliedTypeTree(mapper(tycon), args.map(mapper(_)))
1770-
case _ => if topLevel then TypeTree() else { bail = true; genericEmptyTree }
1771-
val mapped = mapper(mt.resultType, topLevel = true)
1772-
if bail then TypeTree() else mapped
1773-
case _ => TypeTree()
1774-
1775-
val applyVParams = vargs.asInstanceOf[List[ValDef]]
1776-
.map(varg => varg.withAddedFlags(mods.flags | Param))
1777-
New(Template(emptyConstructor, List(polyFunctionTpt), Nil, EmptyValDef,
1778-
List(DefDef(nme.apply, applyTParams :: applyVParams :: Nil, typeTree(pt), res))
1779-
))
1780-
}
1781-
case _ =>
1782-
// may happen for erroneous input. An error will already have been reported.
1783-
assert(ctx.reporter.errorsReported)
1784-
EmptyTree
1785-
}
1786-
17871796
// begin desugar
17881797

17891798
// Special case for `Parens` desugaring: unlike all the desugarings below,
@@ -1796,8 +1805,6 @@ object desugar {
17961805
}
17971806

17981807
val desugared = tree match {
1799-
case PolyFunction(targs, body) =>
1800-
makePolyFunction(targs, body, pt) orElse tree
18011808
case SymbolLit(str) =>
18021809
Apply(
18031810
ref(defn.ScalaSymbolClass.companionModule.termRef),

0 commit comments

Comments
 (0)