Skip to content

Commit 75a3df2

Browse files
Merge branch 'master' into ct_ops_expansion
2 parents 762d90e + e94032c commit 75a3df2

File tree

173 files changed

+2529
-671
lines changed

Some content is hidden

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

173 files changed

+2529
-671
lines changed

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ If you're not sure what version you're using, run `print scalaVersion` from sbt
1414

1515
## Minimized code
1616

17+
<!--
18+
This code should be self contained, compilable (with possible failures) and as small as possible.
19+
20+
Ideally, we should be able to just copy this code in a file and run `scalac` (and maybe `scala`) to reproduce the issue.
21+
-->
22+
1723
```Scala
1824
println("hello, world")
1925
```

.github/ISSUE_TEMPLATE/crash.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ If you're not sure what version you're using, run `print scalaVersion` from sbt
1414

1515
## Minimized code
1616

17+
<!--
18+
This code should be self contained, compilable (with possible failures) and as small as possible.
19+
20+
Ideally, we should be able to just copy this code in a file and run `scalac` (and maybe `scala`) to reproduce the issue.
21+
-->
22+
1723
```Scala
1824
println("hello, world")
1925
```
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
name: Syntax highlighting
3-
about: Please create a syntax highlighting issue here https://github.com/scala/vscode-scala-syntax/issues
3+
about: ''
44
title: ''
55
labels: ''
66
assignees: ''
77

88
---
99

10-
Please create a syntax highlighting issue here: [scala/vscode-scala-syntax](https://github.com/scala/vscode-scala-syntax/issues).
10+
Please create a syntax highlighting issue here
11+
* VS Code / GitHub: https://github.com/scala/vscode-scala-syntax/issues
12+
* IntelliJ: https://youtrack.jetbrains.com/issues/SCL?q=tag:%20%7BScala%203%7D%20tag:%20%7BSyntax%20Highlighting%7D
13+
* highlight.js: https://github.com/highlightjs/highlight.js/issues

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,6 @@
213213
[submodule "community-build/community-projects/scala-java8-compat"]
214214
path = community-build/community-projects/scala-java8-compat
215215
url = https://github.com/dotty-staging/scala-java8-compat.git
216+
[submodule "community-build/community-projects/specs2"]
217+
path = community-build/community-projects/specs2
218+
url = https://github.com/dotty-staging/specs2.git

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Dotty
33
[![Dotty CI](https://github.com/lampepfl/dotty/workflows/Dotty/badge.svg?branch=master)](https://github.com/lampepfl/dotty/actions?query=branch%3Amaster)
44
[![Join the chat at https://gitter.im/scala/scala](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/scala/scala?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
55

6-
* [Homepage](http://dotty.epfl.ch)
6+
* [Homepage](https://dotty.epfl.ch)
77
* [Documentation](https://dotty.epfl.ch/docs)
88

99
Try it out
Submodule specs2 added at 0652dae

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,13 @@ object projects:
731731
dependencies = List(scalaJava8Compat, scalatest)
732732
)
733733

734+
lazy val specs2 = SbtCommunityProject(
735+
project = "specs2",
736+
sbtTestCommand = "core/testOnly -- exclude ci",
737+
sbtPublishCommand = "core/publishLocal",
738+
dependencies = List()
739+
)
740+
734741
end projects
735742

736743
def allProjects = List(
@@ -809,6 +816,7 @@ def allProjects = List(
809816
projects.fs2,
810817
projects.libretto,
811818
projects.jacksonModuleScala,
819+
projects.specs2,
812820
)
813821

814822
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
@@ -91,6 +91,7 @@ class CommunityBuildTestC:
9191
@Test def sconfig = projects.sconfig.run()
9292
@Test def shapeless = projects.shapeless.run()
9393
@Test def sourcecode = projects.sourcecode.run()
94+
@Test def specs2 = projects.specs2.run()
9495
@Test def stdLib213 = projects.stdLib213.run()
9596
@Test def ujson = projects.ujson.run()
9697
@Test def upickle = projects.upickle.run()

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4706,7 +4706,7 @@ object JSCodeGen {
47064706
if (!overloads.isOverloaded)
47074707
overloads.symbol
47084708
else
4709-
overloads.suchThat(_.is(HasDefaultParams)).symbol
4709+
overloads.suchThat(_.is(HasDefaultParams, butNot = Bridge)).symbol
47104710
}
47114711
}
47124712

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,29 +1410,6 @@ object desugar {
14101410
FunctionWithMods(params, body, Modifiers(mods))
14111411
}
14121412

1413-
/** Add annotation to tree:
1414-
* tree @fullName
1415-
*
1416-
* The annotation is usually represented as a TypeTree referring to the class
1417-
* with the given name `fullName`. However, if the annotation matches a file name
1418-
* that is still to be entered, the annotation is represented as a cascade of `Selects`
1419-
* following `fullName`. This is necessary so that we avoid reading an annotation from
1420-
* the classpath that is also compiled from source.
1421-
*/
1422-
def makeAnnotated(fullName: String, tree: Tree)(using Context): Annotated = {
1423-
val parts = fullName.split('.')
1424-
val ttree = typerPhase match {
1425-
case phase: TyperPhase if phase.stillToBeEntered(parts.last) =>
1426-
val prefix =
1427-
parts.init.foldLeft(Ident(nme.ROOTPKG): Tree)((qual, name) =>
1428-
Select(qual, name.toTermName))
1429-
Select(prefix, parts.last.toTypeName)
1430-
case _ =>
1431-
TypeTree(requiredClass(fullName).typeRef)
1432-
}
1433-
Annotated(tree, New(ttree, Nil))
1434-
}
1435-
14361413
private def derivedValDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers)(using Context) = {
14371414
val vdef = ValDef(named.name.asTermName, tpt, rhs)
14381415
.withMods(mods)

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,12 @@ object DesugarEnums {
179179
* }
180180
*/
181181
private def enumValueCreator(using Context) = {
182-
val fieldMethods = if isJavaEnum then Nil else ordinalMeth(Ident(nme.ordinalDollar_)) :: Nil
183182
val creator = New(Template(
184183
constr = emptyConstructor,
185184
parents = enumClassRef :: scalaRuntimeDot(tpnme.EnumValue) :: Nil,
186185
derived = Nil,
187186
self = EmptyValDef,
188-
body = fieldMethods
187+
body = Nil
189188
).withAttachment(ExtendsSingletonMirror, ()))
190189
DefDef(nme.DOLLAR_NEW,
191190
List(List(param(nme.ordinalDollar_, defn.IntType), param(nme.nameDollar, defn.StringType))),
@@ -270,8 +269,6 @@ object DesugarEnums {
270269
def param(name: TermName, typ: Type)(using Context): ValDef = param(name, TypeTree(typ))
271270
def param(name: TermName, tpt: Tree)(using Context): ValDef = ValDef(name, tpt, EmptyTree).withFlags(Param)
272271

273-
private def isJavaEnum(using Context): Boolean = enumClass.derivesFrom(defn.JavaEnumClass)
274-
275272
def ordinalMeth(body: Tree)(using Context): DefDef =
276273
DefDef(nme.ordinal, Nil, TypeTree(defn.IntType), body).withAddedFlags(Synthetic)
277274

@@ -290,10 +287,8 @@ object DesugarEnums {
290287
expandSimpleEnumCase(name, mods, definesLookups, span)
291288
else {
292289
val (tag, scaffolding) = nextOrdinal(name, CaseKind.Object, definesLookups)
293-
val impl1 = cpy.Template(impl)(
294-
parents = impl.parents :+ scalaRuntimeDot(tpnme.EnumValue),
295-
body = if isJavaEnum then Nil else ordinalMethLit(tag) :: Nil
296-
).withAttachment(ExtendsSingletonMirror, ())
290+
val impl1 = cpy.Template(impl)(parents = impl.parents :+ scalaRuntimeDot(tpnme.EnumValue), body = Nil)
291+
.withAttachment(ExtendsSingletonMirror, ())
297292
val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods.withAddedFlags(EnumValue, span))
298293
flatTree(vdef :: scaffolding).withSpan(span)
299294
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import core.Contexts._
55
import core.Decorators._
66
import util.Spans._
77
import Trees.{MemberDef, DefTree, WithLazyField}
8+
import dotty.tools.dotc.core.Annotations.ConcreteAnnotation
9+
import dotty.tools.dotc.core.Types.AnnotatedType
10+
import dotty.tools.dotc.core.Types.ImportType
11+
import dotty.tools.dotc.core.Types.Type
812

913
/** Utility functions to go from typed to untyped ASTs */
1014
// TODO: Handle trees with mixed source files
@@ -86,6 +90,18 @@ object NavigateAST {
8690
}
8791
bestFit
8892
}
93+
/*
94+
* Annotations trees are located in the Type
95+
*/
96+
def unpackAnnotations(t: Type, path: List[Positioned]): List[Positioned] =
97+
t match {
98+
case ann: AnnotatedType =>
99+
unpackAnnotations(ann.parent, childPath(ann.annot.tree.productIterator, path))
100+
case imp: ImportType =>
101+
childPath(imp.expr.productIterator, path)
102+
case other =>
103+
path
104+
}
89105
def singlePath(p: Positioned, path: List[Positioned]): List[Positioned] =
90106
if (p.span.exists && !(skipZeroExtent && p.span.isZeroExtent) && p.span.contains(span)) {
91107
// FIXME: We shouldn't be manually forcing trees here, we should replace
@@ -98,7 +114,12 @@ object NavigateAST {
98114
}
99115
childPath(p.productIterator, p :: path)
100116
}
101-
else path
117+
else {
118+
p match {
119+
case t: untpd.TypeTree => unpackAnnotations(t.typeOpt, path)
120+
case _ => path
121+
}
122+
}
102123
singlePath(from, Nil)
103124
}
104125
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ import Decorators._
1919

2020
object Trees {
2121

22-
// Note: it would be more logical to make Untyped = Nothing.
23-
// However, this interacts in a bad way with Scala's current type inference.
24-
// In fact, we cannot write something like Select(pre, name), where pre is
25-
// of type Tree[Nothing]; type inference will treat the Nothing as an uninstantiated
26-
// value and will not infer Nothing as the type parameter for Select.
27-
// We should come back to this issue once type inference is changed.
28-
type Untyped = Null
22+
type Untyped = Nothing
2923

3024
/** The total number of created tree nodes, maintained if Stats.enabled */
3125
@sharable var ntrees: Int = 0
@@ -44,8 +38,7 @@ object Trees {
4438
*
4539
* - You can never observe a `tpe` which is `null` (throws an exception)
4640
* - So when creating a typed tree with `withType` we can re-use
47-
* the existing tree transparently, assigning its `tpe` field,
48-
* provided it was `null` before.
41+
* the existing tree transparently, assigning its `tpe` field.
4942
* - It is impossible to embed untyped trees in typed ones.
5043
* - Typed trees can be embedded in untyped ones provided they are rooted
5144
* in a TypedSplice node.

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
121121
Closure(Nil, call, targetTpt))
122122
}
123123

124-
/** A closure whole anonymous function has the given method type */
124+
/** A closure whose anonymous function has the given method type */
125125
def Lambda(tpe: MethodType, rhsFn: List[Tree] => Tree)(using Context): Block = {
126-
val meth = newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, tpe)
126+
val meth = newAnonFun(ctx.owner, tpe)
127127
Closure(meth, tss => rhsFn(tss.head).changeOwner(ctx.owner, meth))
128128
}
129129

@@ -1104,6 +1104,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11041104
if (sym.exists) sym.defTree = tree
11051105
tree
11061106
}
1107+
1108+
def etaExpandCFT(using Context): Tree =
1109+
def expand(target: Tree, tp: Type)(using Context): Tree = tp match
1110+
case defn.ContextFunctionType(argTypes, resType, isErased) =>
1111+
val anonFun = newAnonFun(
1112+
ctx.owner,
1113+
MethodType.companion(isContextual = true, isErased = isErased)(argTypes, resType),
1114+
coord = ctx.owner.coord)
1115+
def lambdaBody(refss: List[List[Tree]]) =
1116+
expand(target.select(nme.apply).appliedToArgss(refss), resType)(
1117+
using ctx.withOwner(anonFun))
1118+
Closure(anonFun, lambdaBody)
1119+
case _ =>
1120+
target
1121+
expand(tree, tree.tpe.widen)
11071122
}
11081123

11091124
inline val MapRecursionLimit = 10

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object ScalaSettings:
2424
val jdkVersion = JDK9Reflectors.runtimeVersionMajor(JDK9Reflectors.runtimeVersion()).intValue()
2525
val maxVersion = Math.min(jdkVersion, maxTargetVersion)
2626
(minTargetVersion to maxVersion).toList.map(_.toString)
27-
else List()
27+
else List(minTargetVersion).map(_.toString)
2828

2929
def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")
3030

@@ -218,6 +218,7 @@ private sealed trait XSettings:
218218
val Xtarget: Setting[String] = ChoiceSetting("-Xtarget", "target", "Emit bytecode for the specified version of the Java platform. This might produce bytecode that will break at runtime. When on JDK 9+, consider -release as a safer alternative.", ScalaSettings.supportedTargetVersions, "", aliases = List("--Xtarget"))
219219
val XcheckMacros: Setting[Boolean] = BooleanSetting("-Xcheck-macros", "Check some invariants of macro generated code while expanding macros", aliases = List("--Xcheck-macros"))
220220
val XmainClass: Setting[String] = StringSetting("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d <jar>)", "")
221+
val XimplicitSearchLimit: Setting[Int] = IntSetting("-Ximplicit-search-limit", "Maximal number of expressions to be generated in an implicit search", 50000)
221222

222223
val XmixinForceForwarders = ChoiceSetting(
223224
name = "-Xmixin-force-forwarders",

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,33 @@ object Settings:
9898
changed = true
9999
ArgsSummary(updateIn(sstate, value1), args, errors, dangers)
100100
end update
101+
101102
def fail(msg: String, args: List[String]) =
102103
ArgsSummary(sstate, args, errors :+ msg, warnings)
104+
103105
def missingArg =
104106
fail(s"missing argument for option $name", args)
107+
105108
def setString(argValue: String, args: List[String]) =
106109
choices match
107110
case Some(xs) if !xs.contains(argValue) =>
108111
fail(s"$argValue is not a valid choice for $name", args)
109112
case _ =>
110113
update(argValue, args)
114+
115+
def setInt(argValue: String, args: List[String]) =
116+
try
117+
val x = argValue.toInt
118+
choices match
119+
case Some(r: Range) if x < r.head || r.last < x =>
120+
fail(s"$argValue is out of legal range ${r.head}..${r.last} for $name", args)
121+
case Some(xs) if !xs.contains(x) =>
122+
fail(s"$argValue is not a valid choice for $name", args)
123+
case _ =>
124+
update(x, args)
125+
catch case _: NumberFormatException =>
126+
fail(s"$argValue is not an integer argument for $name", args)
127+
111128
def doSet(argRest: String) = ((implicitly[ClassTag[T]], args): @unchecked) match {
112129
case (BooleanTag, _) =>
113130
update(true, args)
@@ -136,23 +153,10 @@ object Settings:
136153
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
137154
update(output, args)
138155
}
139-
case (IntTag, _) =>
140-
val arg2 :: args2 = if (argRest == "") args else argRest :: args
141-
try {
142-
val x = arg2.toInt
143-
choices match {
144-
case Some(r: Range) if x < r.head || r.last < x =>
145-
fail(s"$arg2 is out of legal range ${r.head}..${r.last} for $name", args2)
146-
case Some(xs) if !xs.contains(x) =>
147-
fail(s"$arg2 is not a valid choice for $name", args)
148-
case _ =>
149-
update(x, args2)
150-
}
151-
}
152-
catch {
153-
case _: NumberFormatException =>
154-
fail(s"$arg2 is not an integer argument for $name", args2)
155-
}
156+
case (IntTag, args) if argRest.nonEmpty =>
157+
setInt(argRest, args)
158+
case (IntTag, arg2 :: args2) =>
159+
setInt(arg2, args2)
156160
case (VersionTag, _) =>
157161
ScalaVersion.parse(argRest) match {
158162
case Success(v) => update(v, args)

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ class Definitions {
736736
@tu lazy val NoneModule: Symbol = requiredModule("scala.None")
737737

738738
@tu lazy val EnumClass: ClassSymbol = requiredClass("scala.reflect.Enum")
739+
@tu lazy val Enum_ordinal: Symbol = EnumClass.requiredMethod(nme.ordinal)
739740

740741
@tu lazy val EnumValueSerializationProxyClass: ClassSymbol = requiredClass("scala.runtime.EnumValueSerializationProxy")
741742
@tu lazy val EnumValueSerializationProxyConstructor: TermSymbol =
@@ -1380,23 +1381,6 @@ class Definitions {
13801381
def isBoxedUnitClass(cls: Symbol): Boolean =
13811382
cls.isClass && (cls.owner eq ScalaRuntimePackageClass) && cls.name == tpnme.BoxedUnit
13821383

1383-
/** Returns the erased class of the function class `cls`
1384-
* - FunctionN for N > 22 becomes FunctionXXL
1385-
* - FunctionN for 22 > N >= 0 remains as FunctionN
1386-
* - ContextFunctionN for N > 22 becomes FunctionXXL
1387-
* - ContextFunctionN for N <= 22 becomes FunctionN
1388-
* - ErasedFunctionN becomes Function0
1389-
* - ImplicitErasedFunctionN becomes Function0
1390-
* - anything else becomes a NoSymbol
1391-
*/
1392-
def erasedFunctionClass(cls: Symbol): Symbol = {
1393-
val arity = scalaClassName(cls).functionArity
1394-
if (cls.name.isErasedFunction) FunctionClass(0)
1395-
else if (arity > 22) FunctionXXLClass
1396-
else if (arity >= 0) FunctionClass(arity)
1397-
else NoSymbol
1398-
}
1399-
14001384
/** Returns the erased type of the function class `cls`
14011385
* - FunctionN for N > 22 becomes FunctionXXL
14021386
* - FunctionN for 22 > N >= 0 remains as FunctionN
@@ -1406,13 +1390,12 @@ class Definitions {
14061390
* - ImplicitErasedFunctionN becomes Function0
14071391
* - anything else becomes a NoType
14081392
*/
1409-
def erasedFunctionType(cls: Symbol): Type = {
1393+
def functionTypeErasure(cls: Symbol): Type =
14101394
val arity = scalaClassName(cls).functionArity
1411-
if (cls.name.isErasedFunction) FunctionType(0)
1412-
else if (arity > 22) FunctionXXLClass.typeRef
1413-
else if (arity >= 0) FunctionType(arity)
1395+
if cls.name.isErasedFunction then FunctionType(0)
1396+
else if arity > 22 then FunctionXXLClass.typeRef
1397+
else if arity >= 0 then FunctionType(arity)
14141398
else NoType
1415-
}
14161399

14171400
val predefClassNames: Set[Name] =
14181401
Set("Predef$", "DeprecatedPredef", "LowPriorityImplicits").map(_.toTypeName.unmangleClassName)

0 commit comments

Comments
 (0)