Skip to content

Commit 41ff7c2

Browse files
committed
Drop tpd.modsDeco
Prefer to access directly via symbol.
1 parent d096f00 commit 41ff7c2

File tree

8 files changed

+28
-46
lines changed

8 files changed

+28
-46
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
944944
}
945945

946946
object ValDef extends ValDefDeconstructor {
947-
def _1: Modifiers = field.mods
947+
def _1: Modifiers = tpd.Modifiers(field.symbol)
948948
def _2: Name = field.name
949949
def _3: Tree = field.tpt
950950
def _4: Tree = field.rhs
@@ -1055,7 +1055,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10551055
}
10561056

10571057
object DefDef extends DefDefDeconstructor {
1058-
def _1: Modifiers = field.mods
1058+
def _1: Modifiers = tpd.Modifiers(field.symbol)
10591059
def _2: Name = field.name
10601060
def _3: List[TypeDef] = field.tparams
10611061
def _4: List[List[ValDef]] = field.vparamss
@@ -1081,7 +1081,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10811081
}
10821082

10831083
object ClassDef extends ClassDefDeconstructor {
1084-
def _1: Modifiers = field.mods
1084+
def _1: Modifiers = tpd.Modifiers(field.symbol)
10851085
def _2: Name = field.name
10861086
def _4: Template = field.rhs.asInstanceOf[Template]
10871087
def _3: List[TypeDef] = Nil

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,6 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
249249
/** Is this case guarded? */
250250
def isGuardedCase(cdef: CaseDef) = cdef.guard ne EmptyTree
251251

252-
/** True iff definition is a val or def with no right-hand-side, or it
253-
* is an abstract typoe declaration
254-
*/
255-
def lacksDefinition(mdef: MemberDef)(implicit ctx: Context) = mdef match {
256-
case mdef: ValOrDefDef =>
257-
mdef.unforcedRhs == EmptyTree && !mdef.name.isConstructorName && !mdef.mods.is(ParamAccessor)
258-
case mdef: TypeDef =>
259-
mdef.rhs.isEmpty || mdef.rhs.isInstanceOf[TypeBoundsTree]
260-
case _ => false
261-
}
262-
263252
/** The underlying pattern ignoring any bindings */
264253
def unbind(x: Tree): Tree = unsplice(x) match {
265254
case Bind(_, y) => unbind(y)
@@ -279,9 +268,21 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
279268

280269
trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped] =>
281270
import TreeInfo._
271+
import untpd._
272+
273+
/** True iff definition is a val or def with no right-hand-side, or it
274+
* is an abstract typoe declaration
275+
*/
276+
def lacksDefinition(mdef: MemberDef)(implicit ctx: Context) = mdef match {
277+
case mdef: ValOrDefDef =>
278+
mdef.unforcedRhs == EmptyTree && !mdef.name.isConstructorName && !mdef.mods.is(ParamAccessor)
279+
case mdef: TypeDef =>
280+
mdef.rhs.isEmpty || mdef.rhs.isInstanceOf[TypeBoundsTree]
281+
case _ => false
282+
}
282283

283284
def isFunctionWithUnknownParamType(tree: Tree) = tree match {
284-
case untpd.Function(args, _) =>
285+
case Function(args, _) =>
285286
args.exists {
286287
case ValDef(_, tpt, _) => tpt.isEmpty
287288
case _ => false
@@ -307,7 +308,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
307308
| DefDef(_, _, _, _, _) =>
308309
Pure
309310
case vdef @ ValDef(_, _, _) =>
310-
if (vdef.mods is Mutable) Impure else exprPurity(vdef.rhs)
311+
if (vdef.symbol.flags is Mutable) Impure else exprPurity(vdef.rhs)
311312
case _ =>
312313
Impure
313314
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ object Trees {
322322

323323
private[this] var myMods: Modifiers[T] = null
324324

325-
private[ast] def rawMods: Modifiers[T] =
325+
private[dotc] def rawMods: Modifiers[T] =
326326
if (myMods == null) genericEmptyModifiers else myMods
327327

328328
def rawComment: Option[Comment] = getAttachment(DocComment)
@@ -870,11 +870,6 @@ object Trees {
870870
case ys => Thicket(ys)
871871
}
872872

873-
// ----- Accessing modifiers ----------------------------------------------------
874-
875-
abstract class ModsDeco { def mods: Modifiers }
876-
implicit def modsDeco(mdef: MemberDef)(implicit ctx: Context): ModsDeco
877-
878873
// ----- Helper classes for copying, transforming, accumulating -----------------
879874

880875
val cpy: TreeCopier

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
446446
} else foldOver(sym, tree)
447447
}
448448

449-
implicit class modsDeco(mdef: MemberDef)(implicit ctx: Context) extends ModsDeco {
450-
def mods = if (mdef.hasType) Modifiers(mdef.symbol) else mdef.rawMods
451-
}
452-
453449
override val cpy = new TypedTreeCopier
454450

455451
class TypedTreeCopier extends TreeCopier {

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,11 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
264264
/** A repeated argument such as `arg: _*` */
265265
def repeated(arg: Tree)(implicit ctx: Context) = Typed(arg, Ident(tpnme.WILDCARD_STAR))
266266

267-
// ------- Decorators -------------------------------------------------
267+
// ----- Accessing modifiers ----------------------------------------------------
268268

269-
implicit class UntypedTreeDecorator(val self: Tree) extends AnyVal {
270-
def locateEnclosing(base: List[Tree], pos: Position): List[Tree] = {
271-
def encloses(elem: Any) = elem match {
272-
case t: Tree => t.pos contains pos
273-
case _ => false
274-
}
275-
base.productIterator find encloses match {
276-
case Some(tree: Tree) => locateEnclosing(tree :: base, pos)
277-
case none => base
278-
}
279-
}
280-
}
269+
abstract class ModsDecorator { def mods: Modifiers }
281270

282-
implicit class modsDeco(val mdef: MemberDef)(implicit ctx: Context) extends ModsDeco {
271+
implicit class modsDeco(val mdef: MemberDef)(implicit ctx: Context) {
283272
def mods = mdef.rawMods
284273
}
285274

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
161161
import untpd.{modsDeco => _, _}
162162

163163
/** Print modifiers from symbols if tree has type, overriding the untpd behavior. */
164-
implicit def modsDeco(mdef: untpd.MemberDef)(implicit ctx: Context): untpd.ModsDeco =
165-
tpd.modsDeco(mdef.asInstanceOf[tpd.MemberDef]).asInstanceOf[untpd.ModsDeco]
164+
implicit def modsDeco(mdef: untpd.MemberDef)(implicit ctx: Context): untpd.ModsDecorator =
165+
new untpd.ModsDecorator {
166+
def mods = if (mdef.hasType) tpd.Modifiers(mdef.symbol) else mdef.rawMods
167+
}
166168

167169
def isLocalThis(tree: Tree) = tree.typeOpt match {
168170
case tp: ThisType => tp.cls == ctx.owner.enclosingClass

src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
210210
def transformMemberDefNonVolatile(x: ValOrDefDef)(implicit ctx: Context) = {
211211
val claz = x.symbol.owner.asClass
212212
val tpe = x.tpe.widen.resultType.widen
213-
assert(!(x.mods is Flags.Mutable))
213+
assert(!(x.symbol is Flags.Mutable))
214214
val containerName = ctx.freshName(x.name.asTermName.lazyLocalName).toTermName
215215
val containerSymbol = ctx.newSymbol(claz, containerName,
216216
x.symbol.flags &~ containerFlagsMask | containerFlags | Flags.Private,
@@ -331,7 +331,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
331331
}
332332

333333
def transformMemberDefVolatile(x: ValOrDefDef)(implicit ctx: Context) = {
334-
assert(!(x.mods is Flags.Mutable))
334+
assert(!(x.symbol is Flags.Mutable))
335335

336336
val tpe = x.tpe.widen.resultType.widen
337337
val claz = x.symbol.owner.asClass
@@ -377,7 +377,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
377377
}
378378

379379
val containerName = ctx.freshName(x.name.asTermName.lazyLocalName).toTermName
380-
val containerSymbol = ctx.newSymbol(claz, containerName, (x.mods &~ containerFlagsMask | containerFlags).flags, tpe, coord = x.symbol.coord).enteredAfter(this)
380+
val containerSymbol = ctx.newSymbol(claz, containerName, x.symbol.flags &~ containerFlagsMask | containerFlags, tpe, coord = x.symbol.coord).enteredAfter(this)
381381

382382
val containerTree = ValDef(containerSymbol, defaultValue(tpe))
383383

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class TreeChecker extends Phase with SymTransformer {
164164
tree match {
165165
case t: MemberDef =>
166166
if (t.name ne sym.name) ctx.warning(s"symbol ${sym.fullName} name doesn't correspond to AST: ${t}")
167-
if (sym.flags != t.mods.flags) ctx.warning(s"symbol ${sym.fullName} flags ${sym.flags} doesn't match AST definition flags ${t.mods.flags}")
168167
// todo: compare trees inside annotations
169168
case _ =>
170169
}

0 commit comments

Comments
 (0)