Skip to content

Commit 1b28c63

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dotty-explicit-nulls-only
2 parents 5c7c312 + c1e0e04 commit 1b28c63

File tree

110 files changed

+2200
-1443
lines changed

Some content is hidden

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

110 files changed

+2200
-1443
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@
5656
[submodule "community-build/community-projects/intent"]
5757
path = community-build/community-projects/intent
5858
url = https://github.com/dotty-staging/intent
59+
[submodule "community-build/community-projects/utest"]
60+
path = community-build/community-projects/utest
61+
url = https://github.com/dotty-staging/utest.git
Submodule scalap updated 1 file
Submodule scopt updated 1 file
Submodule utest added at 0fe508a

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

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ class CommunityBuildTest {
1616
new String(Files.readAllBytes(file), UTF_8)
1717
}
1818

19+
def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil) = {
20+
// Workaround for https://github.com/sbt/sbt/issues/4395
21+
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
22+
val pluginFilePath = communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
23+
24+
// Run the sbt command with the compiler version and sbt plugin set in the build
25+
val arguments = {
26+
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match {
27+
case Some(ivyHome) =>
28+
Seq(s"-Dsbt.ivy.home=$ivyHome")
29+
case _ =>
30+
Seq()
31+
}
32+
extraSbtArgs ++ sbtProps ++ Seq(
33+
"-sbt-version", "1.2.7",
34+
s"--addPluginSbtFile=$pluginFilePath",
35+
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $testCommand"
36+
)
37+
}
38+
39+
test(project, "sbt", arguments)
40+
}
41+
42+
def testMill(project: String, testCommand: String, extraMillArgs: Seq[String] = Nil) =
43+
test(project, "./mill", extraMillArgs :+ testCommand)
44+
1945
/** Build the given project with the published local compiler and sbt plugin.
2046
*
2147
* This test reads the compiler version from community-build/dotty-bootstrapped.version
@@ -26,7 +52,7 @@ class CommunityBuildTest {
2652
* @param updateCommand The sbt command used to update the project
2753
* @param extraSbtArgs Extra arguments to pass to sbt
2854
*/
29-
def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil): Unit = {
55+
def test(project: String, command: String, arguments: Seq[String]): Unit = {
3056
def log(msg: String) = println(Console.GREEN + msg + Console.RESET)
3157

3258
log(s"Building $project with dotty-bootstrapped $compilerVersion...")
@@ -53,149 +79,135 @@ class CommunityBuildTest {
5379
exitCode
5480
}
5581

56-
// Workaround for https://github.com/sbt/sbt/issues/4395
57-
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
58-
val pluginFilePath = communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
59-
60-
// Run the sbt command with the compiler version and sbt plugin set in the build
61-
val arguments = {
62-
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match {
63-
case Some(ivyHome) =>
64-
Seq(s"-Dsbt.ivy.home=$ivyHome")
65-
case _ =>
66-
Seq()
67-
}
68-
extraSbtArgs ++ sbtProps ++ Seq(
69-
"-sbt-version", "1.2.7",
70-
s"--addPluginSbtFile=$pluginFilePath",
71-
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $testCommand"
72-
)
73-
}
74-
75-
val exitCode = exec("sbt", arguments: _*)
82+
val exitCode = exec(command, arguments: _*)
7683

7784
if (exitCode != 0) {
7885
fail(s"""
7986
|
80-
|sbt exited with an error code. To reproduce without JUnit, use:
87+
|$command exited with an error code. To reproduce without JUnit, use:
8188
|
8289
| sbt community-build/prepareCommunityBuild
8390
| cd community-build/community-projects/$project
84-
| sbt ${arguments.init.mkString(" ")} "${arguments.last}"
91+
| $command ${arguments.init.mkString(" ")} "${arguments.last}"
8592
|
86-
|For a faster feedback loop, one can try to extract a direct call to dotc
93+
|For a faster feedback loop on SBT projects, one can try to extract a direct call to dotc
8794
|using the sbt export command. For instance, for scalacheck, use
8895
| sbt export jvm/test:compileIncremental
8996
|
9097
|""".stripMargin)
9198
}
9299
}
93100

94-
@Test def intent = test(
101+
@Test def utest = testMill(
102+
project = "utest",
103+
testCommand = s"utest.jvm[$compilerVersion].test",
104+
extraMillArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
105+
)
106+
107+
@Test def intent = testSbt(
95108
project = "intent",
96109
testCommand = "test",
97110
updateCommand = "update"
98111
)
99112

100-
@Test def algebra = test(
113+
@Test def algebra = testSbt(
101114
project = "algebra",
102115
testCommand = "coreJVM/compile",
103116
updateCommand = "coreJVM/update"
104117
)
105118

106-
@Test def scalacheck = test(
119+
@Test def scalacheck = testSbt(
107120
project = "scalacheck",
108121
testCommand = "jvm/test:compile",
109122
updateCommand = "jvm/test:update"
110123
)
111124

112-
@Test def scalatest = test(
125+
@Test def scalatest = testSbt(
113126
project = "scalatest",
114127
testCommand = ";scalacticDotty/clean;scalacticTestDotty/test;scalatestTestDotty/test",
115128
updateCommand = "scalatest/update"
116129
)
117130

118-
@Test def scalaXml = test(
131+
@Test def scalaXml = testSbt(
119132
project = "scala-xml",
120133
testCommand = "xml/test",
121134
updateCommand = "xml/update"
122135
)
123136

124-
@Test def scopt = test(
137+
@Test def scopt = testSbt(
125138
project = "scopt",
126139
testCommand = "scoptJVM/compile",
127140
updateCommand = "scoptJVM/update"
128141
)
129142

130-
@Test def scalap = test(
143+
@Test def scalap = testSbt(
131144
project = "scalap",
132145
testCommand = "scalap/compile",
133146
updateCommand = "scalap/update"
134147
)
135148

136-
@Test def squants = test(
149+
@Test def squants = testSbt(
137150
project = "squants",
138151
testCommand = "squantsJVM/compile",
139152
updateCommand = "squantsJVM/update"
140153
)
141154

142-
@Test def betterfiles = test(
155+
@Test def betterfiles = testSbt(
143156
project = "betterfiles",
144157
testCommand = "dotty-community-build/compile",
145158
updateCommand = "dotty-community-build/update"
146159
)
147160

148-
@Test def ScalaPB = test(
161+
@Test def ScalaPB = testSbt(
149162
project = "ScalaPB",
150163
testCommand = "dotty-community-build/compile",
151164
updateCommand = "dotty-community-build/update"
152165
)
153166

154-
@Test def minitest = test(
167+
@Test def minitest = testSbt(
155168
project = "minitest",
156169
testCommand = "dotty-community-build/compile",
157170
updateCommand = "dotty-community-build/update"
158171
)
159172

160-
@Test def fastparse = test(
173+
@Test def fastparse = testSbt(
161174
project = "fastparse",
162175
testCommand = "dotty-community-build/compile;dotty-community-build/test:compile",
163176
updateCommand = "dotty-community-build/update"
164177
)
165178

166-
// TODO: revert to sourcecodeJVM/test
167-
@Test def sourcecode = test(
168-
project = "sourcecode",
169-
testCommand = "sourcecode/compile;sourcecode/test:compile",
170-
updateCommand = "sourcecode/update"
179+
@Test def sourcecode = testMill(
180+
project = "sourcecode",
181+
testCommand = s"sourcecode.jvm[$compilerVersion].test",
182+
extraMillArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
171183
)
172184

173-
@Test def stdLib213 = test(
185+
@Test def stdLib213 = testSbt(
174186
project = "stdLib213",
175187
testCommand = "library/compile",
176188
updateCommand = "library/update",
177189
extraSbtArgs = Seq("-Dscala.build.compileWithDotty=true")
178190
)
179191

180-
@Test def shapeless = test(
192+
@Test def shapeless = testSbt(
181193
project = "shapeless",
182194
testCommand = "test",
183195
updateCommand = "update"
184196
)
185197

186-
@Test def xmlInterpolator = test(
198+
@Test def xmlInterpolator = testSbt(
187199
project = "xml-interpolator",
188200
testCommand = "test",
189201
updateCommand = "update"
190202
)
191203

192-
@Test def semanticdb = test(
204+
@Test def semanticdb = testSbt(
193205
project = "semanticdb",
194206
testCommand = "test:compile",
195207
updateCommand = "update"
196208
)
197209

198-
@Test def effpi = test(
210+
@Test def effpi = testSbt(
199211
project = "effpi",
200212
// We set `useEffpiPlugin := false` because we don't want to run their
201213
// compiler plugin since it relies on external binaries (from the model
@@ -225,6 +237,6 @@ class UpdateCategory
225237

226238
@Category(Array(classOf[UpdateCategory]))
227239
class CommunityBuildUpdate extends CommunityBuildTest {
228-
override def test(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
229-
super.test(project, updateCommand, null, extraSbtArgs)
240+
override def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String]): Unit =
241+
super.testSbt(project, updateCommand, null, extraSbtArgs)
230242
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,14 @@ object desugar {
830830
val impl = mdef.impl
831831
val mods = mdef.mods
832832
impl.constr match {
833-
case DefDef(_, tparams, (vparams @ (vparam :: Nil)) :: _, _, _) =>
833+
case DefDef(_, tparams, (vparams @ (vparam :: Nil)) :: givenParamss, _, _) =>
834834
assert(mods.is(Given))
835835
return moduleDef(
836836
cpy.ModuleDef(mdef)(
837837
mdef.name,
838838
cpy.Template(impl)(
839839
constr = emptyConstructor,
840-
body = impl.body.map(makeExtensionDef(_, tparams, vparams)))))
840+
body = impl.body.map(makeExtensionDef(_, tparams, vparams, givenParamss)))))
841841
case _ =>
842842
}
843843

@@ -892,16 +892,19 @@ object desugar {
892892
* If the given member `mdef` is not of this form, flag it as an error.
893893
*/
894894

895-
def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef])(given ctx: Context): Tree = {
895+
def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef],
896+
givenParamss: List[List[ValDef]])(given ctx: Context): Tree = {
896897
val allowed = "allowed here, since collective parameters are given"
897898
mdef match {
898899
case mdef: DefDef =>
899900
if (mdef.mods.is(Extension)) {
900901
ctx.error(em"No extension method $allowed", mdef.sourcePos)
901902
mdef
902903
}
903-
else cpy.DefDef(mdef)(tparams = tparams ++ mdef.tparams, vparamss = leadingParams :: mdef.vparamss)
904-
.withFlags(Extension)
904+
else cpy.DefDef(mdef)(
905+
tparams = tparams ++ mdef.tparams,
906+
vparamss = leadingParams :: givenParamss ::: mdef.vparamss
907+
).withMods(mdef.mods | Extension)
905908
case mdef: Import =>
906909
mdef
907910
case mdef =>
@@ -1095,7 +1098,10 @@ object desugar {
10951098
val firstDef =
10961099
ValDef(tmpName, TypeTree(), matchExpr)
10971100
.withSpan(pat.span.union(rhs.span)).withMods(patMods)
1098-
def selector(n: Int) = Select(Ident(tmpName), nme.selectorName(n))
1101+
val useSelectors = vars.length <= 22
1102+
def selector(n: Int) =
1103+
if useSelectors then Select(Ident(tmpName), nme.selectorName(n))
1104+
else Apply(Select(Ident(tmpName), nme.apply), Literal(Constant(n)) :: Nil)
10991105
val restDefs =
11001106
for (((named, tpt), n) <- vars.zipWithIndex if named.name != nme.WILDCARD)
11011107
yield
@@ -1737,7 +1743,8 @@ object desugar {
17371743
new TreeTraverser {
17381744
def traverse(tree: untpd.Tree)(implicit ctx: Context): Unit = tree match {
17391745
case Splice(expr) => collect(expr)
1740-
case TypSplice(expr) => collect(expr)
1746+
case TypSplice(expr) =>
1747+
ctx.error("Type splices cannot be used in val patterns. Consider using `match` instead.", tree.sourcePos)
17411748
case _ => traverseChildren(tree)
17421749
}
17431750
}.traverse(expr)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ object DesugarEnums {
9999
val privateValuesDef =
100100
ValDef(nme.DOLLAR_VALUES, TypeTree(),
101101
New(TypeTree(defn.EnumValuesClass.typeRef.appliedTo(enumClass.typeRef :: Nil)), ListOfNil))
102-
.withFlags(Private)
102+
.withFlags(Private | Synthetic)
103103

104104
val valuesOfExnMessage = Apply(
105105
Select(Literal(Constant("key not found: ")), "concat".toTermName),

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
876876
def appliedToArgs(args: List[Tree])(implicit ctx: Context): Apply =
877877
Apply(tree, args)
878878

879+
/** An applied node that accepts only varargs as arguments */
880+
def appliedToVarargs(args: List[Tree], tpt: Tree)(given Context): Tree =
881+
appliedTo(repeated(args, tpt))
882+
879883
/** The current tree applied to given argument lists:
880884
* `tree (argss(0)) ... (argss(argss.length -1))`
881885
*/
@@ -893,6 +897,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
893897
def appliedToTypes(targs: List[Type])(implicit ctx: Context): Tree =
894898
appliedToTypeTrees(targs map (TypeTree(_)))
895899

900+
/** The current tree applied to given type argument: `tree[targ]` */
901+
def appliedToTypeTree(targ: Tree)(implicit ctx: Context): Tree =
902+
appliedToTypeTrees(targ :: Nil)
903+
896904
/** The current tree applied to given type argument list: `tree[targs(0), ..., targs(targs.length - 1)]` */
897905
def appliedToTypeTrees(targs: List[Tree])(implicit ctx: Context): Tree =
898906
if (targs.isEmpty) tree else TypeApply(tree, targs)
@@ -1365,5 +1373,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13651373
val targs = atp.argTypes
13661374
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
13671375
}
1368-
}
13691376

1377+
/** Convert a list of trees to a vararg-compatible tree.
1378+
* Used to make arguments for methods that accept varargs.
1379+
*/
1380+
def repeated(trees: List[Tree], tpt: Tree)(given ctx: Context): Tree =
1381+
ctx.typeAssigner.arrayToRepeated(JavaSeqLiteral(trees, tpt))
1382+
1383+
/** Create a tree representing a list containing all
1384+
* the elements of the argument list. A "list of tree to
1385+
* tree of list" conversion.
1386+
*
1387+
* @param trees the elements the list represented by
1388+
* the resulting tree should contain.
1389+
* @param tpe the type of the elements of the resulting list.
1390+
*
1391+
*/
1392+
def mkList(trees: List[Tree], tpe: Tree)(given Context): Tree =
1393+
ref(defn.ListModule).select(nme.apply)
1394+
.appliedToTypeTree(tpe)
1395+
.appliedToVarargs(trees, tpe)
1396+
}

0 commit comments

Comments
 (0)