Skip to content

Commit 327ae1c

Browse files
authored
Merge branch 'master' into change-rewrite
2 parents 13a73bc + 3bf8a16 commit 327ae1c

File tree

98 files changed

+2467
-2151
lines changed

Some content is hidden

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

98 files changed

+2467
-2151
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
626626

627627
def symbol: Symbol = a.tree.symbol
628628

629-
def args: List[Tree] = List.empty // those arguments to scala-defined annotations. they are never emmited
629+
def args: List[Tree] = List.empty // those arguments to scala-defined annotations. they are never emmitted
630630
}
631631

632632
def assocsFromApply(tree: Tree): List[(Name, Tree)] = {
@@ -810,7 +810,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
810810
def annotations: List[Annotation] = toDenot(sym).annotations
811811
def companionModuleMembers: List[Symbol] = {
812812
// phase travel to exitingPickler: this makes sure that memberClassesOf only sees member classes,
813-
// not local classes of the companion module (E in the exmaple) that were lifted by lambdalift.
813+
// not local classes of the companion module (E in the example) that were lifted by lambdalift.
814814
if (linkedClass.isTopLevelModuleClass) /*exitingPickler*/ linkedClass.memberClasses
815815
else Nil
816816
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Driver extends DotClass {
118118
*
119119
* In most cases, you do not need a custom `Context` and should
120120
* instead use one of the other overloads of `process`. However,
121-
* the other overloads cannot be overriden, instead you
121+
* the other overloads cannot be overridden, instead you
122122
* should override this one which they call internally.
123123
*
124124
* Usage example: [[https://github.com/lampepfl/dotty/tree/master/test/test/OtherEntryPointsTest.scala]]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ abstract class Positioned extends DotClass with Product {
168168
def check(p: Any): Unit = p match {
169169
case p: Positioned =>
170170
assert(pos contains p.pos,
171-
s"""position error, parent position does not contain child positon
171+
s"""position error, parent position does not contain child position
172172
|parent = $this,
173173
|parent position = $pos,
174174
|child = $p,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10171017
lastParam.tpe match {
10181018
case defn.ArrayOf(el2) if el2 <:< el =>
10191019
// we have a JavaSeqLiteral with a more precise type
1020-
// we cannot construct a tree as JavaSeqLiteral infered to precise type
1020+
// we cannot construct a tree as JavaSeqLiteral inferred to precise type
10211021
// if we add typed than it would be both type-correct and
10221022
// will pass Ycheck
10231023
prefix ::: List(tpd.Typed(lastParam, TypeTree(defn.ArrayOf(el))))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ object Config {
120120

121121
/** If this flag is set, it is checked that class type parameters are
122122
* only references with NoPrefix or ThisTypes as prefixes. This option
123-
* is usally disabled, because there are still some legitimate cases where
123+
* is usually disabled, because there are still some legitimate cases where
124124
* this can arise (e.g. for pos/Map.scala, in LambdaType.integrate).
125125
*/
126126
final val checkTypeParamRefs = false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ class Definitions {
12331233
// Temporary measure, as long as we do not read these classes from Tasty.
12341234
// Scala-2 classes don't have NoInits set even if they are pure. We override this
12351235
// for Product and Serializable so that case classes can be pure. A full solution
1236-
// requiers that we read all Scala code from Tasty.
1236+
// requires that we read all Scala code from Tasty.
12371237
ProductClass.setFlag(NoInits)
12381238
SerializableClass.setFlag(NoInits)
12391239

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ object SymDenotations {
10681068
if (!canMatchInheritedSymbols && (owner ne inClass)) NoSymbol
10691069
else matchingDecl(inClass, owner.thisType)
10701070

1071-
/** All symbols overriden by this denotation. */
1071+
/** All symbols overridden by this denotation. */
10721072
final def allOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] =
10731073
if (!canMatchInheritedSymbols) Iterator.empty
10741074
else overriddenFromType(owner.info)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
350350
* - For a refined type scala.Array+[T]:
351351
* - if T is Nothing or Null, []Object
352352
* - otherwise, if T <: Object, []|T|
353-
* - otherwise, if T is a type paramter coming from Java, []Object
353+
* - otherwise, if T is a type parameter coming from Java, []Object
354354
* - otherwise, Object
355355
* - For a term ref p.x, the type <noprefix> # x.
356356
* - For a typeref scala.Any, scala.AnyVal or scala.Singleton: |java.lang.Object|

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,9 +2309,9 @@ object Types {
23092309
}
23102310

23112311
/** A refined type parent { refinement }
2312-
* @param refinedName The name of the refinement declaration
2313-
* @param infoFn: A function that produces the info of the refinement declaration,
2314-
* given the refined type itself.
2312+
* @param parent The type being refined
2313+
* @param refinedName The name of the refinement declaration
2314+
* @param refinedInfo The info of the refinement declaration
23152315
*/
23162316
abstract case class RefinedType(parent: Type, refinedName: Name, refinedInfo: Type) extends RefinedOrRecType {
23172317

@@ -2370,6 +2370,31 @@ object Types {
23702370
}
23712371
}
23722372

2373+
/** A recursive type. Instances should be constructed via the companion object.
2374+
*
2375+
* @param parentExp A function that, given a recursive type R, produces a type
2376+
* that can refer to R via a `RecThis(R)` node. This is used to
2377+
* "tie the knot".
2378+
*
2379+
* For example, in
2380+
* class C { type T1; type T2 }
2381+
* type C2 = C { type T1; type T2 = T1 }
2382+
*
2383+
* The type of `C2` is a recursive type `{(x) => C{T1; T2 = x.T1}}`, written as
2384+
*
2385+
* RecType(
2386+
* RefinedType(
2387+
* RefinedType(
2388+
* TypeRef(...,class C),
2389+
* T1,
2390+
* TypeBounds(...)),
2391+
* T2,
2392+
* TypeBounds(
2393+
* TypeRef(RecThis(...),T1),
2394+
* TypeRef(RecThis(...),T1))))
2395+
*
2396+
* Where `RecThis(...)` points back to the enclosing `RecType`.
2397+
*/
23732398
class RecType(parentExp: RecType => Type) extends RefinedOrRecType with BindingType {
23742399

23752400
// See discussion in findMember#goRec why these vars are needed
@@ -2438,7 +2463,7 @@ object Types {
24382463
* 1. Nested Rec types on the type's spine are merged with the outer one.
24392464
* 2. Any refinement of the form `type T = z.T` on the spine of the type
24402465
* where `z` refers to the created rec-type is replaced by
2441-
* `type T`. This avoids infinite recursons later when we
2466+
* `type T`. This avoids infinite recursions later when we
24422467
* try to follow these references.
24432468
* TODO: Figure out how to guarantee absence of cycles
24442469
* of length > 1
@@ -2459,6 +2484,8 @@ object Types {
24592484
}
24602485
unique(rt.derivedRecType(normalize(rt.parent))).checkInst
24612486
}
2487+
2488+
/** Create a `RecType`, but only if the type generated by `parentExp` is indeed recursive. */
24622489
def closeOver(parentExp: RecType => Type)(implicit ctx: Context) = {
24632490
val rt = this(parentExp)
24642491
if (rt.isReferredToBy(rt.parent)) rt else rt.parent

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ object TastyFormat {
274274

275275
final val OBJECTCLASS = 23 // The name of an object class (or: module class) `<name>$`.
276276

277-
final val SIGNED = 63 // A pair of a name and a signature, used to idenitfy
277+
final val SIGNED = 63 // A pair of a name and a signature, used to idenitify
278278
// possibly overloaded methods.
279279
}
280280
object NameTags extends NameTags

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ object Parsers {
262262
def deprecationWarning(msg: => Message, offset: Int = in.offset) =
263263
ctx.deprecationWarning(msg, source atPos Position(offset))
264264

265-
/** Issue an error at current offset taht input is incomplete */
265+
/** Issue an error at current offset that input is incomplete */
266266
def incompleteInputError(msg: => Message) =
267267
ctx.incompleteInputError(msg, source atPos Position(in.offset))
268268

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ object Formatting {
244244
* ```
245245
* found: List[Int]
246246
* required: List[T]
247-
* where: T is a type in the initalizer of value s which is an alias of
247+
* where: T is a type in the initializer of value s which is an alias of
248248
* String
249249
* ```
250250
*

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
435435
else if (ownr.isAnonymousFunction) nextOuter("function")
436436
else if (isEmptyPrefix(ownr)) ""
437437
else if (ownr.isLocalDummy) showLocation(ownr.owner, "locally defined in")
438-
else if (ownr.isTerm && !ownr.is(Module | Method)) showLocation(ownr, "in the initalizer of")
438+
else if (ownr.isTerm && !ownr.is(Module | Method)) showLocation(ownr, "in the initializer of")
439439
else showLocation(ownr, "in")
440440
}
441441
recur(sym.owner, "")

compiler/src/dotty/tools/dotc/printing/Printer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class Printer {
3434
def changePrec(prec: Precedence)(op: => Text): Text =
3535
if (prec < this.prec) atPrec(prec) ("(" ~ op ~ ")") else atPrec(prec)(op)
3636

37-
/** The name, possibley with with namespace suffix if debugNames is set:
37+
/** The name, possibly with with namespace suffix if debugNames is set:
3838
* /L for local names, /V for other term names, /T for type names
3939
*/
4040
def nameString(name: Name): String
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.ast.tpd
4+
5+
trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with TastyCoreImpl with Helpers {
6+
7+
def CaseDefDeco(caseDef: CaseDef): CaseDefAPI = new CaseDefAPI {
8+
def pattern(implicit ctx: Context): Pattern = caseDef.pat
9+
def guard(implicit ctx: Context): Option[Term] = optional(caseDef.guard)
10+
def rhs(implicit ctx: Context): Term = caseDef.body
11+
}
12+
13+
object CaseDef extends CaseDefExtractor {
14+
def unapply(x: CaseDef): Option[(Pattern, Option[Term], Term)] = x match {
15+
case x: tpd.CaseDef =>
16+
Some(x.pat, optional(x.guard), x.body)
17+
case _ => None
18+
}
19+
}
20+
21+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.core.Constants
4+
5+
import scala.tasty.util.Show
6+
7+
trait ConstantOpsImpl extends scala.tasty.reflect.ConstantOps with TastyCoreImpl {
8+
9+
def ConstantDeco(const: Constant): ConstantAPI = new ConstantAPI {
10+
def value: Any = const.value
11+
}
12+
13+
object Constant extends ConstantModule {
14+
15+
object Unit extends UnitExtractor {
16+
def unapply(x: Constant): Boolean = x match {
17+
case x: Constants.Constant => x.tag == Constants.UnitTag
18+
case _ => false
19+
}
20+
}
21+
22+
object Null extends NullExtractor {
23+
def unapply(x: Constant): Boolean = x match {
24+
case x: Constants.Constant => x.tag == Constants.NullTag
25+
case _ => false
26+
}
27+
}
28+
29+
object Boolean extends BooleanExtractor {
30+
def unapply(x: Constant): Option[Boolean] = x match {
31+
case x: Constants.Constant if x.tag == Constants.BooleanTag => Some(x.booleanValue)
32+
case _ => None
33+
}
34+
}
35+
36+
object Byte extends ByteExtractor {
37+
def unapply(x: Constant): Option[Byte] = x match {
38+
case x: Constants.Constant if x.tag == Constants.ByteTag => Some(x.byteValue)
39+
case _ => None
40+
}
41+
}
42+
43+
object Short extends ShortExtractor {
44+
def unapply(x: Constant): Option[Short] = x match {
45+
case x: Constants.Constant if x.tag == Constants.ShortTag => Some(x.shortValue)
46+
case _ => None
47+
}
48+
}
49+
50+
object Char extends CharExtractor {
51+
def unapply(x: Constant): Option[Char] = x match {
52+
case x: Constants.Constant if x.tag == Constants.CharTag => Some(x.charValue)
53+
case _ => None
54+
}
55+
}
56+
57+
object Int extends IntExtractor {
58+
def unapply(x: Constant): Option[Int] = x match {
59+
case x: Constants.Constant if x.tag == Constants.IntTag => Some(x.intValue)
60+
case _ => None
61+
}
62+
}
63+
64+
object Long extends LongExtractor {
65+
def unapply(x: Constant): Option[Long] = x match {
66+
case x: Constants.Constant if x.tag == Constants.LongTag => Some(x.longValue)
67+
case _ => None
68+
}
69+
}
70+
71+
object Float extends FloatExtractor {
72+
def unapply(x: Constant): Option[Float] = x match {
73+
case x: Constants.Constant if x.tag == Constants.FloatTag => Some(x.floatValue)
74+
case _ => None
75+
}
76+
}
77+
78+
object Double extends DoubleExtractor {
79+
def unapply(x: Constant): Option[Double] = x match {
80+
case x: Constants.Constant if x.tag == Constants.DoubleTag => Some(x.doubleValue)
81+
case _ => None
82+
}
83+
}
84+
85+
object String extends StringExtractor {
86+
def unapply(x: Constant): Option[String] = x match {
87+
case x: Constants.Constant if x.tag == Constants.StringTag => Some(x.stringValue)
88+
case _ => None
89+
}
90+
}
91+
92+
object ClassTag extends ClassTagExtractor {
93+
def unapply(x: Constant): Option[Type] = x match {
94+
case x: Constants.Constant if x.tag == Constants.ClazzTag => Some(x.typeValue)
95+
case _ => None
96+
}
97+
}
98+
99+
object Symbol extends SymbolExtractor {
100+
def unapply(x: Constant): Option[scala.Symbol] = x match {
101+
case x: Constants.Constant if x.tag == Constants.ScalaSymbolTag => Some(x.scalaSymbolValue)
102+
case _ => None
103+
}
104+
}
105+
}
106+
107+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.core.Contexts
4+
import dotty.tools.dotc.tastyreflect.FromSymbol.definitionFromSym
5+
import dotty.tools.dotc.util.{Positions, SourcePosition}
6+
7+
trait ContextOpsImpl extends scala.tasty.reflect.ContextOps with TastyCoreImpl {
8+
9+
val rootContext: Contexts.Context
10+
11+
def ContextDeco(ctx: Context): ContextAPI = new ContextAPI {
12+
def owner: Definition = definitionFromSym(ctx.owner)(ctx)
13+
14+
def source: java.nio.file.Path = ctx.compilationUnit.source.file.jpath
15+
}
16+
17+
def rootPosition: SourcePosition = SourcePosition(rootContext.source, Positions.NoPosition)
18+
19+
}

compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.dotc.tastyreflect
33
import dotty.tools.dotc.core.Flags
44
import dotty.tools.dotc.core.Flags._
55

6-
class FlagSet(flags: Flags.FlagSet) extends scala.tasty.FlagSet {
6+
class FlagSet(flags: Flags.FlagSet) extends scala.tasty.reflect.FlagSet {
77

88
def isProtected: Boolean = flags.is(Protected)
99
def isAbstract: Boolean = flags.is(Abstract)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.ast.Trees
4+
5+
trait Helpers {
6+
7+
protected final def optional[T <: Trees.Tree[_]](tree: T): Option[tree.type] =
8+
if (tree.isEmpty) None else Some(tree)
9+
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.core.Decorators._
4+
5+
trait IdOpsImpl extends scala.tasty.reflect.IdOps with TastyCoreImpl {
6+
7+
def IdDeco(id: Id): IdAPI = new IdAPI {
8+
def pos(implicit ctx: Context): Position = id.pos
9+
def name(implicit ctx: Context): String = id.name.toString
10+
}
11+
12+
object Id extends IdExtractor {
13+
def unapply(id: Id): Option[String] = Some(id.name.toString)
14+
}
15+
16+
}

0 commit comments

Comments
 (0)