Skip to content

Commit 12cdd19

Browse files
committed
Add missing scala doc
1 parent 8f2f7f5 commit 12cdd19

File tree

10 files changed

+42
-27
lines changed

10 files changed

+42
-27
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,11 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
391391
* @DarkDimius: need to make sure that lazy accessor methods have Lazy and Stable
392392
* flags set.
393393
*/
394-
private def refPurity(tree: Tree)(implicit ctx: Context): PurityLevel = {
395-
if (tree.symbol.is(Unused) || !tree.tpe.widen.isParameterless) Pure
394+
private def refPurity(tree: Tree)(implicit ctx: Context): PurityLevel =
395+
if (!tree.tpe.widen.isParameterless || tree.symbol.is(Unused)) Pure
396396
else if (!tree.symbol.isStable) Impure
397397
else if (tree.symbol.is(Lazy)) Idempotent // TODO add Module flag, sinxce Module vals or not Lazy from the start.
398398
else Pure
399-
}
400399

401400
def isPureRef(tree: Tree)(implicit ctx: Context) =
402401
refPurity(tree) == Pure

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,8 @@ class Definitions {
837837
* - FunctionN for 22 > N >= 0 remains as FunctionN
838838
* - ImplicitFunctionN for N > 22 becomes FunctionXXL
839839
* - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN
840+
* - UnusedFunctionN becomes Function0
841+
* - ImplicitUnusedFunctionN becomes Function0
840842
* - anything else becomes a NoSymbol
841843
*/
842844
def erasedFunctionClass(cls: Symbol): Symbol = {
@@ -852,6 +854,8 @@ class Definitions {
852854
* - FunctionN for 22 > N >= 0 remains as FunctionN
853855
* - ImplicitFunctionN for N > 22 becomes FunctionXXL
854856
* - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN
857+
* - UnusedFunctionN becomes Function0
858+
* - ImplicitUnusedFunctionN becomes Function0
855859
* - anything else becomes a NoType
856860
*/
857861
def erasedFunctionType(cls: Symbol): Type = {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,27 @@ object NameOps {
180180
/** Is a function name
181181
* - FunctionN for N >= 0
182182
* - ImplicitFunctionN for N >= 1
183+
* - UnusedFunctionN for N >= 1
184+
* - UnusedImplicitFunctionN for N >= 1
183185
* - false otherwise
184186
*/
185187
def isFunction: Boolean = functionArity >= 0
186188

187189
/** Is a implicit function name
188190
* - ImplicitFunctionN for N >= 1
191+
* - UnusedImplicitFunctionN for N >= 1
189192
* - false otherwise
190193
*/
191194
def isImplicitFunction: Boolean = {
192195
functionArityFor(str.ImplicitFunction) >= 1 ||
193196
functionArityFor(str.UnusedImplicitFunction) >= 1
194197
}
195198

199+
/** Is a implicit function name
200+
* - UnusedFunctionN for N >= 1
201+
* - UnusedImplicitFunctionN for N >= 1
202+
* - false otherwise
203+
*/
196204
def isUnusedFunction: Boolean = {
197205
functionArityFor(str.UnusedFunction) >= 1 ||
198206
functionArityFor(str.UnusedImplicitFunction) >= 1
@@ -201,6 +209,8 @@ object NameOps {
201209
/** Is a synthetic function name
202210
* - FunctionN for N > 22
203211
* - ImplicitFunctionN for N >= 1
212+
* - UnusedFunctionN for N >= 1
213+
* - UnusedImplicitFunctionN for N >= 1
204214
* - false otherwise
205215
*/
206216
def isSyntheticFunction: Boolean = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ object Parsers {
25022502
stats ++= importClause()
25032503
else if (isExprIntro)
25042504
stats += expr(Location.InBlock)
2505-
else if (isDefIntro(localModifierTokens)) {
2505+
else if (isDefIntro(localModifierTokens))
25062506
if (in.token == IMPLICIT || in.token == UNUSED) {
25072507
val start = in.offset
25082508
var imods = EmptyModifiers
@@ -2513,7 +2513,7 @@ object Parsers {
25132513
} else {
25142514
stats +++= localDef(in.offset)
25152515
}
2516-
} else if (!isStatSep && (in.token != CASE)) {
2516+
else if (!isStatSep && (in.token != CASE)) {
25172517
exitOnError = mustStartStat
25182518
val addendum = if (isModifier) " (no modifiers allowed here)" else ""
25192519
syntaxErrorOrIncomplete("illegal start of statement" + addendum)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
666666
else if (sym.isClass && flags.is(Case)) "case class"
667667
else if (flags is Module) "object"
668668
else if (sym.isTerm && !flags.is(Param) && flags.is(Implicit)) "implicit val"
669-
else if (sym.isTerm && !flags.is(Param) && sym.is(Unused)) "unused val"
669+
else if (sym.isTerm && !flags.is(Param) && flags.is(Unused)) "unused val"
670670
else super.keyString(sym)
671671
}
672672

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,14 +1710,14 @@ object messages {
17101710

17111711
case class FunctionTypeNeedsNonEmptyParameterList(isImplicit: Boolean = true, isUnused: Boolean = true)(implicit ctx: Context)
17121712
extends Message(FunctionTypeNeedsNonEmptyParameterListID) {
1713-
// TODO use isImplicit and isUnused
17141713
val kind = "Syntax"
1715-
val msg = "implicit function type needs non-empty parameter list"
1714+
val mods = ((isImplicit, "implicit") :: (isUnused, "unused") :: Nil).filter(_._1).mkString(" ")
1715+
val msg = mods + " function type needs non-empty parameter list"
17161716
val explanation = {
1717-
val code1 = "type Transactional[T] = implicit Transaction => T"
1717+
val code1 = s"type Transactional[T] = $mods Transaction => T"
17181718
val code2 = "val cl: implicit A => B"
1719-
hl"""It is not allowed to leave implicit function parameter list empty.
1720-
|Possible ways to define implicit function type:
1719+
hl"""It is not allowed to leave $mods function parameter list empty.
1720+
|Possible ways to define $mods function type:
17211721
|
17221722
|$code1
17231723
|

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ import dotty.tools.dotc.core.Flags._
88
import dotty.tools.dotc.core.Symbols._
99
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
1010

11-
// TODO
12-
/** THis phase ...
11+
/** This phase checks that unused `def`s, `val`s and parameters are only used in valid place.
12+
* It also checks that the `unused` keyword is only used on `def`, `val` and parameters lists
13+
*
14+
* Unused values can be used:
15+
* - As parameters to an unused function
16+
* - In statement position
17+
* - Anywhere in the RHS of an `unused def` or `unused val`
1318
*/
1419
class UnusedChecks extends MiniPhaseTransform {
1520
import tpd._
@@ -61,11 +66,13 @@ class UnusedChecks extends MiniPhaseTransform {
6166

6267
/* private methods */
6368

69+
/** Check that unused values are not of type Nothing */
6470
private def checkUnusedNothing(tree: Tree)(implicit ctx: Context): Unit = {
6571
if (tree.symbol.is(Unused) && tree.tpe.widen.finalResultType.isBottomType)
6672
ctx.error("unused " + tree.symbol.showKind + " cannot have type Nothing", tree.pos)
6773
}
6874

75+
/** Check that the expression is not a reference to an unused value */
6976
private def checkedValOrDefDefRHS(tree: ValOrDefDef)(implicit ctx: Context): tree.type =
7077
if (tree.symbol.is(Unused)) tree
7178
else checked(tree)(tree.rhs, "Cannot return `unused` value in a def without `unused`")
@@ -90,6 +97,6 @@ class UnusedChecks extends MiniPhaseTransform {
9097
tree0
9198
}
9299

93-
def isUnusedContext(implicit ctx: Context): Boolean =
100+
private def isUnusedContext(implicit ctx: Context): Boolean =
94101
ctx.owner.ownersIterator.exists(_.is(Unused)) // TODO make context mode?
95102
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,4 @@ class UnusedDecls extends MiniPhaseTransform with InfoTransformer {
5151
else tp.derivedClassInfo(decls = tp.decls.filteredScope(!_.is(Unused)))
5252
case _ => tp
5353
}
54-
5554
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.ast.Trees._
55
import dotty.tools.dotc.core.Contexts._
66
import dotty.tools.dotc.core.DenotTransformers.InfoTransformer
7-
import dotty.tools.dotc.core.Designators._
87
import dotty.tools.dotc.core.Symbols._
98
import dotty.tools.dotc.core.Types._
10-
import dotty.tools.dotc.core.Names._
11-
import dotty.tools.dotc.core.NameOps._
12-
import dotty.tools.dotc.core.Decorators._
139
import dotty.tools.dotc.core.StdNames._
1410
import dotty.tools.dotc.core.Flags._
1511
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, Transforme
1717
*
1818
* if `unused val x: T = ...` including parameters
1919
* then `x` --> `(default value for T)`
20+
* `x.Y` --> `T#Y`
2021
*/
2122
class UnusedRefs extends MiniPhaseTransform with InfoTransformer {
2223
import tpd._
@@ -48,17 +49,17 @@ class UnusedRefs extends MiniPhaseTransform with InfoTransformer {
4849

4950
/* Tree transform */
5051

51-
override def transformApply(tree: tpd.Apply)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = transformUnused(tree)
52-
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = transformUnused(tree)
53-
override def transformSelect(tree: tpd.Select)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = transformUnused(tree)
52+
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = transformUnused(tree)
53+
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo): Tree = transformUnused(tree)
54+
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = transformUnused(tree)
5455

55-
private def transformUnused(tree: tpd.Tree)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
56+
private def transformUnused(tree: Tree)(implicit ctx: Context, info: TransformerInfo): Tree = {
5657
if (!tree.symbol.is(Unused)) tree
5758
else {
5859
tree.tpe.widen match {
5960
case _: MethodType => tree // Do the transformation higher in the tree if needed
6061
case _ =>
61-
val result = tpd.defaultValue(tree.tpe) match {
62+
val result = defaultValue(tree.tpe) match {
6263
case t @ TypeApply(fun, args) => cpy.TypeApply(t)(fun = fun, args = args.map(transform)) // asInstanceOf inserted by defaultValue
6364
case t => t
6465
}
@@ -70,7 +71,7 @@ class UnusedRefs extends MiniPhaseTransform with InfoTransformer {
7071
}
7172
}
7273

73-
override def transformTypeTree(tree: tpd.TypeTree)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
74+
override def transformTypeTree(tree: TypeTree)(implicit ctx: Context, info: TransformerInfo): Tree = {
7475
val newType = removeUnusedPaths(tree.tpe)
7576
if (tree.tpe == newType) tree
7677
else TypeTree(newType)
@@ -79,8 +80,7 @@ class UnusedRefs extends MiniPhaseTransform with InfoTransformer {
7980

8081
/* Tree info */
8182

82-
override def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type =
83-
removeUnusedPaths(tp)
83+
override def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = removeUnusedPaths(tp)
8484

8585
private def removeUnusedPaths(tp: Type)(implicit ctx: Context): Type = {
8686
// TODO: handle variance

0 commit comments

Comments
 (0)