Skip to content

Commit d59ab5d

Browse files
committed
Remove dead annotation typing code
Annotations are checked by completing them. No need to type modifiers in Typer at all.
1 parent d70d184 commit d59ab5d

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ object SymDenotations {
265265
/** Make sure this denotation is completed */
266266
final def ensureCompleted()(implicit ctx: Context): Unit = info
267267

268+
/** Make sure all annotations of this symbol are full computed */
269+
final def ensureAnnotationsCompleted()(implicit ctx: Context): Unit =
270+
annotations.foreach(_.tree)
271+
268272
/** The symbols defined in this class or object.
269273
* Careful! This does not force the type, so is compilation order dependent.
270274
* This method should be used only in the following circumstances:

src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class ReTyper extends Typer {
7272
override def tryInsertApplyOrImplicit(tree: Tree, pt: ProtoType)(fallBack: (Tree, TyperState) => Tree)(implicit ctx: Context): Tree =
7373
fallBack(tree, ctx.typerState)
7474

75-
override def addTypedModifiersAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit =
76-
() // was: typedModifiers(Modifiers(sym), sym)
77-
// but annotations are not transformed after typer, so no use to check them.
78-
7975
override def ensureConstrCall(cls: ClassSymbol, parents: List[Tree])(implicit ctx: Context): List[Tree] =
8076
parents
8177

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -859,24 +859,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
859859
assignType(cpy.Alternative(tree)(trees1), trees1)
860860
}
861861

862-
def addTypedModifiersAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit = {
863-
val mods1 = typedModifiers(untpd.modsDeco(mdef).mods, sym)
864-
sym.annotations.foreach(_.tree) // force trees to be computed
865-
}
866-
867-
def typedModifiers(mods: untpd.Modifiers, sym: Symbol)(implicit ctx: Context): Modifiers = track("typedModifiers") {
868-
val annotations1 = mods.annotations mapconserve typedAnnotation
869-
if (annotations1 eq mods.annotations) mods.asInstanceOf[Modifiers]
870-
else Modifiers(mods.flags, mods.privateWithin, annotations1)
871-
}
872-
873862
def typedAnnotation(annot: untpd.Tree)(implicit ctx: Context): Tree = track("typedAnnotation") {
874863
typed(annot, defn.AnnotationClass.typeRef)
875864
}
876865

877866
def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = track("typedValDef") {
878867
val ValDef(name, tpt, _) = vdef
879-
addTypedModifiersAnnotations(vdef, sym)
880868
val tpt1 = typedType(tpt)
881869
val rhs1 = vdef.rhs match {
882870
case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe
@@ -887,7 +875,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
887875

888876
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = track("typedDefDef") {
889877
val DefDef(name, tparams, vparamss, tpt, _) = ddef
890-
addTypedModifiersAnnotations(ddef, sym)
891878
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
892879
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
893880
if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1)
@@ -899,7 +886,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
899886

900887
def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedTypeDef") {
901888
val TypeDef(name, rhs) = tdef
902-
addTypedModifiersAnnotations(tdef, sym)
903889
val _ = typedType(rhs) // unused, typecheck only to remove from typedTree
904890
assignType(cpy.TypeDef(tdef)(name, TypeTree(sym.info), Nil), sym)
905891
}
@@ -916,7 +902,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
916902
result
917903
}
918904

919-
addTypedModifiersAnnotations(cdef, cls)
920905
val constr1 = typed(constr).asInstanceOf[DefDef]
921906
val parentsWithClass = ensureFirstIsClass(parents mapconserve typedParent, cdef.pos.toSynthetic)
922907
val parents1 = ensureConstrCall(cls, parentsWithClass)(superCtx)
@@ -1023,11 +1008,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10231008
case tree: untpd.Bind => typedBind(tree, pt)
10241009
case tree: untpd.ValDef =>
10251010
if (tree.isEmpty) tpd.EmptyValDef
1026-
else typedValDef(tree, sym)(localContext(tree, sym).setNewScope)
1011+
else {
1012+
sym.ensureAnnotationsCompleted()
1013+
typedValDef(tree, sym)(localContext(tree, sym).setNewScope)
1014+
}
10271015
case tree: untpd.DefDef =>
1016+
sym.ensureAnnotationsCompleted()
10281017
val typer1 = localTyper(sym)
10291018
typer1.typedDefDef(tree, sym)(localContext(tree, sym).setTyper(typer1))
10301019
case tree: untpd.TypeDef =>
1020+
sym.ensureAnnotationsCompleted()
10311021
if (tree.isClassDef)
10321022
typedClassDef(tree, sym.asClass)(localContext(tree, sym).setMode(ctx.mode &~ Mode.InSuperCall))
10331023
else

0 commit comments

Comments
 (0)