@@ -687,90 +687,14 @@ class Namer { typer: Typer =>
687
687
ctxWithStats
688
688
}
689
689
690
- /** Add all annotations of definitions in `stats` to the defined symbols */
691
- def annotate (stats : List [Tree ])(implicit ctx : Context ): Unit = {
692
- def recur (stat : Tree ): Unit = stat match {
693
- case pcl : PackageDef =>
694
- annotate(pcl.stats)
695
- case stat : untpd.MemberDef =>
696
- stat.getAttachment(SymOfTree ) match {
697
- case Some (sym) =>
698
- sym.infoOrCompleter match {
699
- case info : Completer if ! defn.isPredefClass(sym.owner) =>
700
- // Annotate Predef methods only when they are completed;
701
- // This is necessary to break a cyclic dependence between `Predef`
702
- // and `deprecated` in test `compileStdLib`.
703
- addAnnotations(sym, stat)(info.creationContext)
704
- case _ =>
705
- // Annotations were already added as part of the symbol's completion
706
- }
707
- case none =>
708
- assert(stat.typeOpt.exists, i " no symbol for $stat" )
709
- }
710
- case stat : untpd.Thicket =>
711
- stat.trees.foreach(recur)
712
- case _ =>
713
- }
714
-
715
- for (stat <- stats) recur(expanded(stat))
716
- }
717
-
718
- /** Add annotations of `stat` to `sym`.
719
- * This method can be called twice on a symbol (e.g. once
720
- * during the `annotate` phase and then again during completion).
721
- * Therefore, care needs to be taken not to add annotations again
722
- * that are already added to the symbol.
723
- */
724
- def addAnnotations (sym : Symbol , stat : MemberDef )(implicit ctx : Context ) = {
725
- // (1) The context in which an annotation of a top-level class or module is evaluated
726
- // is the closest enclosing context which has the enclosing package as owner.
727
- // (2) The context in which an annotation for any other symbol is evaluated is the
728
- // closest enclosing context which has the owner of the class enclosing the symbol as owner.
729
- // E.g in
730
- //
731
- // package p
732
- // import a.b
733
- // class C {
734
- // import d.e
735
- // @ann m() ...
736
- // }
737
- //
738
- // `@ann` is evaluated in the context just outside `C`, where the `a.b`
739
- // import is visible but the `d.e` import is forgotten. This measure is necessary
740
- // in order to avoid cycles.
741
- lazy val annotCtx = {
742
- var target = sym.owner.lexicallyEnclosingClass
743
- if (! target.is(PackageClass )) target = target.owner
744
- var c = ctx
745
- while (c.owner != target) c = c.outer
746
- c
747
- }
748
-
749
- for (annotTree <- untpd.modsDeco(stat).mods.annotations) {
750
- val cls = typedAheadAnnotationClass(annotTree)(annotCtx)
751
- if (sym.unforcedAnnotation(cls).isEmpty) {
752
- val ann = Annotation .deferred(cls, implicit ctx => typedAheadAnnotation(annotTree))
753
- sym.addAnnotation(ann)
754
- if (cls == defn.ForceInlineAnnot && sym.is(Method , butNot = Accessor ))
755
- sym.setFlag(Inline )
756
- }
757
- }
758
- }
759
-
760
- def indexAndAnnotate (stats : List [Tree ])(implicit ctx : Context ): Context = {
761
- val localCtx = index(stats)
762
- annotate(stats)
763
- localCtx
764
- }
765
-
766
- /** Index and annotate symbols in `tree` while asserting the `lateCompile` flag.
690
+ /** Index symbols in `tree` while asserting the `lateCompile` flag.
767
691
* This will cause any old top-level symbol with the same fully qualified
768
692
* name as a newly created symbol to be replaced.
769
693
*/
770
694
def lateEnter (tree : Tree )(implicit ctx : Context ) = {
771
695
val saved = lateCompile
772
696
lateCompile = true
773
- try indexAndAnnotate (tree :: Nil ) finally lateCompile = saved
697
+ try index (tree :: Nil ) finally lateCompile = saved
774
698
}
775
699
776
700
def missingType (sym : Symbol , modifier : String )(implicit ctx : Context ) = {
@@ -822,6 +746,19 @@ class Namer { typer: Typer =>
822
746
else completeInCreationContext(denot)
823
747
}
824
748
749
+ protected def addAnnotations (sym : Symbol ): Unit = original match {
750
+ case original : untpd.MemberDef =>
751
+ lazy val annotCtx = annotContext(original, sym)
752
+ for (annotTree <- untpd.modsDeco(original).mods.annotations) {
753
+ val cls = typedAheadAnnotationClass(annotTree)(annotCtx)
754
+ val ann = Annotation .deferred(cls, implicit ctx => typedAnnotation(annotTree))
755
+ sym.addAnnotation(ann)
756
+ if (cls == defn.ForceInlineAnnot && sym.is(Method , butNot = Accessor ))
757
+ sym.setFlag(Inline )
758
+ }
759
+ case _ =>
760
+ }
761
+
825
762
private def addInlineInfo (sym : Symbol ) = original match {
826
763
case original : untpd.DefDef if sym.isInlineableMethod =>
827
764
Inliner .registerInlineInfo(
@@ -836,10 +773,7 @@ class Namer { typer: Typer =>
836
773
*/
837
774
def completeInCreationContext (denot : SymDenotation ): Unit = {
838
775
val sym = denot.symbol
839
- original match {
840
- case original : MemberDef => addAnnotations(sym, original)
841
- case _ =>
842
- }
776
+ addAnnotations(sym)
843
777
addInlineInfo(sym)
844
778
denot.info = typeSig(sym)
845
779
Checking .checkWellFormed(sym)
@@ -955,7 +889,7 @@ class Namer { typer: Typer =>
955
889
}
956
890
}
957
891
958
- addAnnotations(denot.symbol, original )
892
+ addAnnotations(denot.symbol)
959
893
960
894
val selfInfo =
961
895
if (self.isEmpty) NoType
@@ -978,9 +912,7 @@ class Namer { typer: Typer =>
978
912
// accessors, that's why the constructor needs to be completed before
979
913
// the parent types are elaborated.
980
914
index(constr)
981
- annotate(constr :: params)
982
-
983
- indexAndAnnotate(rest)(ctx.inClassContext(selfInfo))
915
+ index(rest)(ctx.inClassContext(selfInfo))
984
916
symbolOfTree(constr).ensureCompleted()
985
917
986
918
val parentTypes = ensureFirstIsClass(parents.map(checkedParentType(_)), cls.pos)
@@ -1025,7 +957,7 @@ class Namer { typer: Typer =>
1025
957
1026
958
/** Enter and typecheck parameter list */
1027
959
def completeParams (params : List [MemberDef ])(implicit ctx : Context ) = {
1028
- indexAndAnnotate (params)
960
+ index (params)
1029
961
for (param <- params) typedAheadExpr(param)
1030
962
}
1031
963
@@ -1222,7 +1154,7 @@ class Namer { typer: Typer =>
1222
1154
// 3. Info of CP is computed (to be copied to DP).
1223
1155
// 4. CP is completed.
1224
1156
// 5. Info of CP is copied to DP and DP is completed.
1225
- indexAndAnnotate (tparams)
1157
+ index (tparams)
1226
1158
if (isConstructor) sym.owner.typeParams.foreach(_.ensureCompleted())
1227
1159
for (tparam <- tparams) typedAheadExpr(tparam)
1228
1160
0 commit comments