Skip to content

Commit d31b8c4

Browse files
author
soronpo
committed
Merge branch 'master' of https://github.com/lampepfl/dotty into summonInline
� Conflicts: � docs/docs/reference/metaprogramming/compiletime-ops.md
2 parents dfc8858 + 4410752 commit d31b8c4

File tree

96 files changed

+1621
-1445
lines changed

Some content is hidden

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

96 files changed

+1621
-1445
lines changed

.github/workflows/scaladoc.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@ jobs:
7070
echo uplading docs to https://scala3doc.virtuslab.com/$DOC_DEST
7171
az storage container create --name $DOC_DEST --account-name scala3docstorage --public-access container
7272
az storage blob upload-batch -s scaladoc/output -d $DOC_DEST --account-name scala3docstorage
73+
74+
stdlib-sourcelinks-test:
75+
runs-on: ubuntu-latest
76+
if: "( github.event_name == 'pull_request'
77+
&& !contains(github.event.pull_request.body, '[skip ci]')
78+
&& !contains(github.event.pull_request.body, '[skip docs]')
79+
)
80+
|| contains(github.event.ref, 'scaladoc')
81+
|| contains(github.event.ref, 'scala3doc')
82+
|| contains(github.event.ref, 'master')"
83+
84+
steps:
85+
- name: Git Checkout
86+
uses: actions/checkout@v2
87+
88+
- name: Set up JDK 8
89+
uses: actions/setup-java@v1
90+
with:
91+
java-version: 8
92+
93+
- name: Test sourcelinks to stdlib
94+
run: ./project/scripts/sbt scaladoc/sourceLinksIntegrationTest:test

bench/profiles/exhaustivity.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ charts:
4141
- key: exhaustivity-i12241
4242
label: bootstrapped
4343

44+
- name: "exhaustivity i12358"
45+
url: https://github.com/lampepfl/dotty/blob/master/tests/patmat/i12358.scala
46+
lines:
47+
- key: exhaustivity-i12358
48+
label: bootstrapped
49+
4450
scripts:
4551

4652
patmatexhaust:
@@ -64,5 +70,8 @@ scripts:
6470
exhaustivity-i12241:
6571
- measure 20 40 3 $PROG_HOME/dotty/tests/patmat/i12241.scala
6672

73+
exhaustivity-i12358:
74+
- measure 20 40 3 $PROG_HOME/dotty/tests/patmat/i12358.scala
75+
6776
config:
6877
pr_base_url: "https://github.com/lampepfl/dotty/pull/"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
228228
resKind
229229
}
230230

231-
def genPrimitiveOp(tree: Apply, expectedType: BType): BType = tree match {
231+
def genPrimitiveOp(tree: Apply, expectedType: BType): BType = (tree: @unchecked) match {
232232
case Apply(fun @ DesugaredSelect(receiver, _), _) =>
233233
val sym = tree.symbol
234234

@@ -610,7 +610,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
610610
}
611611
}
612612

613-
def genTypeApply(t: TypeApply): BType = t match {
613+
def genTypeApply(t: TypeApply): BType = (t: @unchecked) match {
614614
case TypeApply(fun@DesugaredSelect(obj, _), targs) =>
615615

616616
val sym = fun.symbol

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
2727
*/
2828
abstract class SyncAndTryBuilder(cunit: CompilationUnit) extends PlainBodyBuilder(cunit) {
2929

30-
def genSynchronized(tree: Apply, expectedType: BType): BType = tree match {
30+
def genSynchronized(tree: Apply, expectedType: BType): BType = (tree: @unchecked) match {
3131
case Apply(TypeApply(fun, _), args) =>
3232
val monitor = locals.makeLocal(ObjectReference, "monitor", defn.ObjectType, tree.span)
3333
val monCleanup = new asm.Label

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ object GenericSignatures {
131131
*/
132132
def splitIntersection(parents: List[Type])(using Context): (List[Type], List[Type]) =
133133
val erasedParents = parents.map(erasure)
134-
val erasedCls = erasedGlb(erasedParents).classSymbol
134+
val erasedTp = erasedGlb(erasedParents)
135135
parents.zip(erasedParents)
136136
.partitionMap((parent, erasedParent) =>
137-
if erasedParent.classSymbol eq erasedCls then
137+
if erasedParent =:= erasedTp then
138138
Left(parent)
139139
else
140140
Right(parent))

compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class StringInterpolatorOpt extends MiniPhase {
121121
(sym.name == nme.f && sym.eq(defn.StringContext_f)) ||
122122
(sym.name == nme.s && sym.eq(defn.StringContext_s))
123123
if (isInterpolatedMethod)
124-
tree match {
124+
(tree: @unchecked) match {
125125
case StringContextIntrinsic(strs: List[Literal], elems: List[Tree]) =>
126126
val stri = strs.iterator
127127
val elemi = elems.iterator

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ trait SpaceLogic {
113113
/** Display space in string format */
114114
def show(sp: Space): String
115115

116-
/** Simplify space using the laws, there's no nested union after simplify */
116+
/** Simplify space such that a space equal to `Empty` becomes `Empty` */
117117
def simplify(space: Space)(using Context): Space = trace(s"simplify ${show(space)} --> ", debug, x => show(x.asInstanceOf[Space]))(space match {
118118
case Prod(tp, fun, spaces) =>
119-
val sp = Prod(tp, fun, spaces.map(simplify(_)))
120-
if (sp.params.contains(Empty)) Empty
119+
val sps = spaces.map(simplify(_))
120+
if (sps.contains(Empty)) Empty
121121
else if (canDecompose(tp) && decompose(tp).isEmpty) Empty
122-
else sp
122+
else Prod(tp, fun, sps)
123123
case Or(spaces) =>
124124
val spaces2 = spaces.map(simplify(_)).filter(_ != Empty)
125125
if spaces2.isEmpty then Empty
126+
else if spaces2.lengthCompare(1) == 0 then spaces2.head
126127
else Or(spaces2)
127128
case Typ(tp, _) =>
128129
if (canDecompose(tp) && decompose(tp).isEmpty) Empty
@@ -243,10 +244,10 @@ trait SpaceLogic {
243244
tryDecompose1(tp1)
244245
else
245246
a
246-
case (_, Or(ss)) =>
247-
ss.foldLeft(a)(minus)
248247
case (Or(ss), _) =>
249248
Or(ss.map(minus(_, b)))
249+
case (_, Or(ss)) =>
250+
ss.foldLeft(a)(minus)
250251
case (Prod(tp1, fun, ss), Typ(tp2, _)) =>
251252
// uncovered corner case: tp2 :< tp1, may happen when inheriting case class
252253
if (isSubType(tp1, tp2))
@@ -272,7 +273,10 @@ trait SpaceLogic {
272273
else if cache.forall(sub => isSubspace(sub, Empty)) then Empty
273274
else
274275
// `(_, _, _) - (Some, None, _)` becomes `(None, _, _) | (_, Some, _) | (_, _, Empty)`
275-
Or(LazyList(range: _*).map { i => Prod(tp1, fun1, ss1.updated(i, sub(i))) })
276+
val spaces = LazyList(range: _*).flatMap { i =>
277+
flatten(sub(i)).map(s => Prod(tp1, fun1, ss1.updated(i, s)))
278+
}
279+
Or(spaces)
276280
}
277281
}
278282
}
@@ -771,7 +775,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
771775
if (ctx.definitions.isTupleType(tp))
772776
"(" + params.map(doShow(_)).mkString(", ") + ")"
773777
else if (tp.isRef(scalaConsType.symbol))
774-
if (flattenList) params.map(doShow(_, flattenList)).mkString(", ")
778+
if (flattenList) params.map(doShow(_, flattenList)).filter(_.nonEmpty).mkString(", ")
775779
else params.map(doShow(_, flattenList = true)).filter(!_.isEmpty).mkString("List(", ", ", ")")
776780
else {
777781
val sym = fun.symbol
@@ -791,16 +795,18 @@ class SpaceEngine(using Context) extends SpaceLogic {
791795
def isCheckable(tp: Type): Boolean =
792796
!tp.hasAnnotation(defn.UncheckedAnnot) && {
793797
val tpw = tp.widen.dealias
798+
val classSym = tpw.classSymbol
794799
ctx.settings.YcheckAllPatmat.value ||
795-
tpw.typeSymbol.is(Sealed) ||
800+
classSym.is(Sealed) ||
796801
tpw.isInstanceOf[OrType] ||
797802
(tpw.isInstanceOf[AndType] && {
798803
val and = tpw.asInstanceOf[AndType]
799804
isCheckable(and.tp1) || isCheckable(and.tp2)
800805
}) ||
801806
tpw.isRef(defn.BooleanClass) ||
802-
tpw.typeSymbol.isAllOf(JavaEnumTrait) ||
803-
(defn.isTupleType(tpw) && tpw.argInfos.exists(isCheckable(_)))
807+
classSym.isAllOf(JavaEnumTrait) ||
808+
(defn.isProductSubType(tpw) && classSym.is(Case)
809+
&& productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_)))
804810
}
805811

806812
val res = isCheckable(sel.tpe)

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ trait Applications extends Compatibility {
990990
* { val xs = es; e' = e' + args }
991991
*/
992992
def typedOpAssign(using Context): Tree = {
993-
val (lhs1, name, rhss) = tree match
993+
val (lhs1, name, rhss) = (tree: @unchecked) match
994994
case Apply(Select(lhs, name), rhss) => (typedExpr(lhs), name, rhss)
995995
case Apply(untpd.TypedSplice(Select(lhs1, name)), rhss) => (lhs1, name, rhss)
996996
val liftedDefs = new mutable.ListBuffer[Tree]

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,15 @@ trait ImportSuggestions:
167167
allCandidates.map(_.implicitRef.underlyingRef.symbol).toSet
168168
}
169169

170+
def testContext(): Context =
171+
ctx.fresh.retractMode(Mode.ImplicitsEnabled).setExploreTyperState()
172+
170173
/** Test whether the head of a given instance matches the expected type `pt`,
171174
* ignoring any dependent implicit arguments.
172175
*/
173176
def shallowTest(ref: TermRef): Boolean =
174177
System.currentTimeMillis < deadLine
175-
&& inContext(ctx.fresh.setExploreTyperState()) {
178+
&& inContext(testContext()) {
176179
def test(pt: Type): Boolean = pt match
177180
case ViewProto(argType, OrType(rt1, rt2)) =>
178181
// Union types do not constrain results, since comparison with a union
@@ -209,7 +212,7 @@ trait ImportSuggestions:
209212
try
210213
timer.schedule(task, testOneImplicitTimeOut)
211214
typedImplicit(candidate, expectedType, argument, span)(
212-
using ctx.fresh.setExploreTyperState()).isSuccess
215+
using testContext()).isSuccess
213216
finally
214217
if task.cancel() then // timer task has not run yet
215218
assert(!ctx.run.isCancelled)

dist/bin/common

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ SBT_INTF=$(find_lib "*compiler-interface*")
159159
JLINE_READER=$(find_lib "*jline-reader-3*")
160160
JLINE_TERMINAL=$(find_lib "*jline-terminal-3*")
161161
JLINE_TERMINAL_JNA=$(find_lib "*jline-terminal-jna-3*")
162-
[[ ${conemu-} ]] || JNA=$(find_lib "*jna-5*")
163162

163+
# jna-5 only appropriate for some combinations
164+
[[ ${conemu-} && ${msys-} ]] || JNA=$(find_lib "*jna-5*")
164165

165166
compilerJavaClasspathArgs () {
166167
# echo "dotty-compiler: $DOTTY_COMP"

dist/bin/scalac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ if [ "$PROG_NAME" == "$ScriptingMain" ]; then
6767
scripting_string="-script $target_script ${scripting_args[@]}"
6868
fi
6969

70-
# exec here would prevent onExit from being called, leaving terminal in unusable state
7170
[ -n "$script_trace" ] && set -x
71+
[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405
72+
73+
# exec here would prevent onExit from being called, leaving terminal in unusable state
7274
eval "\"$JAVACMD\"" \
7375
${JAVA_OPTS:-$default_java_opts} \
7476
"${java_args[@]}" \

docs/docs/reference/changed-features/compiler-plugins.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,28 @@ import dotty.tools.dotc.plugins.{PluginPhase, StandardPlugin}
6363
import dotty.tools.dotc.transform.{Pickler, Staging}
6464

6565
class DivideZero extends StandardPlugin:
66-
val name: String = "divideZero"
67-
override val description: String = "divide zero check"
66+
val name: String = "divideZero"
67+
override val description: String = "divide zero check"
6868

69-
def init(options: List[String]): List[PluginPhase] =
70-
(new DivideZeroPhase) :: Nil
69+
def init(options: List[String]): List[PluginPhase] =
70+
(new DivideZeroPhase) :: Nil
7171

7272
class DivideZeroPhase extends PluginPhase:
73-
import tpd.*
73+
import tpd.*
7474

75-
val phaseName = "divideZero"
75+
val phaseName = "divideZero"
7676

77-
override val runsAfter = Set(Pickler.name)
78-
override val runsBefore = Set(Staging.name)
77+
override val runsAfter = Set(Pickler.name)
78+
override val runsBefore = Set(Staging.name)
7979

80-
override def transformApply(tree: Apply)(implicit ctx: Context): Tree =
81-
tree match
82-
case Apply(Select(rcvr, nme.DIV), List(Literal(Constant(0))))
83-
if rcvr.tpe <:< defn.IntType =>
84-
report.error("dividing by zero", tree.pos)
85-
case _ =>
86-
()
87-
tree
80+
override def transformApply(tree: Apply)(implicit ctx: Context): Tree =
81+
tree match
82+
case Apply(Select(rcvr, nme.DIV), List(Literal(Constant(0))))
83+
if rcvr.tpe <:< defn.IntType =>
84+
report.error("dividing by zero", tree.pos)
85+
case _ =>
86+
()
87+
tree
8888
end DivideZeroPhase
8989
```
9090

@@ -109,11 +109,11 @@ import dotty.tools.dotc.core.Phases.Phase
109109
import dotty.tools.dotc.plugins.ResearchPlugin
110110

111111
class DummyResearchPlugin extends ResearchPlugin:
112-
val name: String = "dummy"
113-
override val description: String = "dummy research plugin"
112+
val name: String = "dummy"
113+
override val description: String = "dummy research plugin"
114114

115-
def init(options: List[String], phases: List[List[Phase]])(implicit ctx: Context): List[List[Phase]] =
116-
phases
115+
def init(options: List[String], phases: List[List[Phase]])(implicit ctx: Context): List[List[Phase]] =
116+
phases
117117
end DummyResearchPlugin
118118
```
119119

docs/docs/reference/changed-features/implicit-conversions-spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The standard library defines an abstract class `Conversion`:
1717
package scala
1818
@java.lang.FunctionalInterface
1919
abstract class Conversion[-T, +U] extends Function1[T, U]:
20-
def apply(x: T): U
20+
def apply(x: T): U
2121
```
2222

2323
Function literals are automatically converted to `Conversion` values.

docs/docs/reference/changed-features/implicit-conversions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ method that expects a `java.lang.Integer`
3434
```scala
3535
import scala.language.implicitConversions
3636
implicit def int2Integer(x: Int): java.lang.Integer =
37-
x.asInstanceOf[java.lang.Integer]
37+
x.asInstanceOf[java.lang.Integer]
3838
```
3939

4040
The second example shows how to use `Conversion` to define an
@@ -44,11 +44,11 @@ types:
4444
```scala
4545
import scala.language.implicitConversions
4646
implicit def ordT[T, S](
47-
implicit conv: Conversion[T, S],
48-
ordS: Ordering[S]
47+
implicit conv: Conversion[T, S],
48+
ordS: Ordering[S]
4949
): Ordering[T] =
50-
// `ordS` compares values of type `S`, but we can convert from `T` to `S`
51-
(x: T, y: T) => ordS.compare(x, y)
50+
// `ordS` compares values of type `S`, but we can convert from `T` to `S`
51+
(x: T, y: T) => ordS.compare(x, y)
5252

5353
class A(val x: Int) // The type for which we want an `Ordering`
5454

docs/docs/reference/changed-features/implicit-resolution.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ where the type may still be inferred:
1313
```scala
1414
class C {
1515

16-
val ctx: Context = ... // ok
16+
val ctx: Context = ... // ok
1717

18-
/*!*/ implicit val x = ... // error: type must be given explicitly
18+
/*!*/ implicit val x = ... // error: type must be given explicitly
1919

20-
/*!*/ implicit def y = ... // error: type must be given explicitly
20+
/*!*/ implicit def y = ... // error: type must be given explicitly
2121
}
2222
val y = {
23-
implicit val ctx = this.ctx // ok
24-
...
23+
implicit val ctx = this.ctx // ok
24+
...
2525
}
2626
```
2727
**2.** Nesting is now taken into account for selecting an implicit. Consider for instance the following scenario:
2828
```scala
2929
def f(implicit i: C) = {
30-
def g(implicit j: C) = {
31-
implicitly[C]
32-
}
30+
def g(implicit j: C) = {
31+
implicitly[C]
32+
}
3333
}
3434
```
3535
This will now resolve the `implicitly` call to `j`, because `j` is nested
@@ -45,8 +45,8 @@ no longer applies.
4545
given a: A = A()
4646

4747
object o:
48-
given b: B = B()
49-
type C
48+
given b: B = B()
49+
type C
5050
```
5151
Both `a` and `b` are visible as implicits at the point of the definition
5252
of `type C`. However, a reference to `p.o.C` outside of package `p` will

docs/docs/reference/changed-features/imports.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ If you want to import a member named `*` specifically, you can use backticks aro
1616

1717
```scala
1818
object A:
19-
def * = ...
20-
def min = ...
19+
def * = ...
20+
def min = ...
2121

2222
object B:
2323
import A.`*` // imports just `*`

0 commit comments

Comments
 (0)