summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-01-15 12:25:41 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-01-15 12:32:36 +0100
commit07ff3a99b75174c4e4a4e52348b34aa0b68f51b1 (patch)
treede5bbfbbc7ddde80ae5b1a97a6a8f6b6560da8af /src/compiler/scala/tools
parente089cafb5fd02e2457bafde3252da3a771d3180e (diff)
downloadscala-07ff3a99b75174c4e4a4e52348b34aa0b68f51b1.tar.gz
scala-07ff3a99b75174c4e4a4e52348b34aa0b68f51b1.tar.bz2
scala-07ff3a99b75174c4e4a4e52348b34aa0b68f51b1.zip
SI-8151 Remove -Yself-in-annots and associated implementation
This experimental option typechecked arguments of annotations with an injected value in scope named `self`: @Foo(self.foo < 1) This has been slated for removal [1] for some time. This commit removes it in one fell swoop, without any attempt at source compatibility with code that constructs or pattern matches on AnnotatedType. [1] https://groups.google.com/d/msg/scala-internals/VdZ5UJwQFGI/C6tZ493Yxx4J
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala1
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala5
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala62
12 files changed, 22 insertions, 72 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
index c68b248240..429832f22c 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
@@ -619,7 +619,7 @@ abstract class TreeBrowsers {
toDocument(result) :: ")")
)
- case AnnotatedType(annots, tp, _) =>
+ case AnnotatedType(annots, tp) =>
Document.group(
Document.nest(4, "AnnotatedType(" :/:
annots.mkString("[", ",", "]") :/:
diff --git a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala
index 633e71a756..a6d0d3b9fa 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala
@@ -393,7 +393,7 @@ trait TypeKinds { self: ICodes =>
// if the first two cases exist because they do or as a defensive measure, but
// at the time I added it, RefinedTypes were indeed reaching here.
case ExistentialType(_, t) => toTypeKind(t)
- case AnnotatedType(_, t, _) => toTypeKind(t)
+ case AnnotatedType(_, t) => toTypeKind(t)
case RefinedType(parents, _) => parents map toTypeKind reduceLeft lub
// For sure WildcardTypes shouldn't reach here either, but when
// debugging such situations this may come in handy.
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
index 64ed094a47..23b9198c7b 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
@@ -518,7 +518,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
// !!! Iulian says types which make no sense after erasure should not reach here, which includes the ExistentialType, AnnotatedType, RefinedType.
case ExistentialType(_, t) => toTypeKind(t) // TODO shouldn't get here but the following does: akka-actor/src/main/scala/akka/util/WildcardTree.scala
- case AnnotatedType(_, w, _) => toTypeKind(w) // TODO test/files/jvm/annotations.scala causes an AnnotatedType to reach here.
+ case AnnotatedType(_, w) => toTypeKind(w) // TODO test/files/jvm/annotations.scala causes an AnnotatedType to reach here.
case RefinedType(parents, _) => parents map toTypeKind reduceLeft jvmWiseLUB
// For sure WildcardTypes shouldn't reach here either, but when debugging such situations this may come in handy.
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 1f9987c83b..5f4c4a43b3 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -154,7 +154,6 @@ trait ScalaSettings extends AbsScalaSettings
val nopredef = BooleanSetting ("-Yno-predef", "Compile without importing Predef.")
val noAdaptedArgs = BooleanSetting ("-Yno-adapted-args", "Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.")
val Yrecursion = IntSetting ("-Yrecursion", "Set recursion depth used when locking symbols.", 0, Some((0, Int.MaxValue)), (_: String) => None)
- val selfInAnnots = BooleanSetting ("-Yself-in-annots", "Include a \"self\" identifier inside of annotations.")
val Xshowtrees = BooleanSetting ("-Yshow-trees", "(Requires -Xprint:) Print detailed ASTs in formatted form.")
val XshowtreesCompact
= BooleanSetting ("-Yshow-trees-compact", "(Requires -Xprint:) Print detailed ASTs in compact form.")
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
index ce3e7b1bb5..90c15bca61 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
@@ -238,9 +238,8 @@ abstract class Pickler extends SubComponent {
case ExistentialType(tparams, restpe) =>
putType(restpe)
putSymbols(tparams)
- case AnnotatedType(_, underlying, selfsym) =>
+ case AnnotatedType(_, underlying) =>
putType(underlying)
- if (settings.selfInAnnots) putSymbol(selfsym)
tp.staticAnnotations foreach putAnnotation
case _ =>
throw new FatalError("bad type: " + tp + "(" + tp.getClass + ")")
@@ -450,7 +449,7 @@ abstract class Pickler extends SubComponent {
case PolyType(tparams, restpe) => writeRef(restpe); writeRefs(tparams)
case ExistentialType(tparams, restpe) => writeRef(restpe); writeRefs(tparams)
case StaticallyAnnotatedType(annots, tp) => writeRef(tp) ; writeRefs(annots)
- case AnnotatedType(_, tp, _) => writeTypeBody(tp) // write the underlying type if there are no static annotations
+ case AnnotatedType(_, tp) => writeTypeBody(tp) // write the underlying type if there are no static annotations
case CompoundType(parents, _, clazz) => writeRef(clazz); writeRefs(parents)
}
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 6732900ef2..4bbfc945f6 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -61,7 +61,7 @@ abstract class Erasure extends AddInterfaces
parents foreach traverse
case ClassInfoType(parents, _, _) =>
parents foreach traverse
- case AnnotatedType(_, atp, _) =>
+ case AnnotatedType(_, atp) =>
traverse(atp)
case _ =>
mapOver(tp)
@@ -302,7 +302,7 @@ abstract class Erasure extends AddInterfaces
boxedSig(parent)
case ClassInfoType(parents, _, _) =>
superSig(parents)
- case AnnotatedType(_, atp, _) =>
+ case AnnotatedType(_, atp) =>
jsig(atp, existentiallyBound, toplevel, primitiveOK)
case BoundedWildcardType(bounds) =>
println("something's wrong: "+sym0+":"+sym0.tpe+" has a bounded wildcard type")
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index c505d9dc5f..3791af1629 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -438,7 +438,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case NullaryMethodType(resTpe) => specializedTypeVars(resTpe)
case MethodType(argSyms, resTpe) => specializedTypeVars(resTpe :: argSyms.map(_.tpe))
case ExistentialType(_, res) => specializedTypeVars(res)
- case AnnotatedType(_, tp, _) => specializedTypeVars(tp)
+ case AnnotatedType(_, tp) => specializedTypeVars(tp)
case TypeBounds(lo, hi) => specializedTypeVars(lo :: hi :: Nil)
case RefinedType(parents, _) => parents flatMap specializedTypeVars toSet
case _ => immutable.Set.empty
@@ -1098,7 +1098,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case (ThisType(_), _) => unify(tp1.widen, tp2, env, strict)
case (_, ThisType(_)) => unify(tp1, tp2.widen, env, strict)
case (RefinedType(_, _), RefinedType(_, _)) => env
- case (AnnotatedType(_, tp1, _), tp2) => unify(tp2, tp1, env, strict)
+ case (AnnotatedType(_, tp1), tp2) => unify(tp2, tp1, env, strict)
case (ExistentialType(_, res1), _) => unify(tp2, res1, env, strict)
case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) => unify(List(lo1, hi1), List(lo2, hi2), env, strict)
case _ =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala b/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
index 73572bcae9..1f1ccbe359 100644
--- a/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
@@ -180,7 +180,7 @@ trait DestructureTypes {
case SuperType(thistp, supertp) => product(tp, this("this", thistp), this("super", supertp))
case ThisType(clazz) => product(tp, wrapAtom(clazz))
case TypeVar(inst, constr) => product(tp, this("inst", inst), typeConstraint(constr))
- case AnnotatedType(annotations, underlying, _) => annotatedType(annotations, underlying)
+ case AnnotatedType(annotations, underlying) => annotatedType(annotations, underlying)
case ExistentialType(tparams, underlying) => polyFunction(tparams, underlying)
case PolyType(tparams, restpe) => polyFunction(tparams, restpe)
case MethodType(params, restpe) => monoFunction(params, restpe)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index fdec1edcc0..1916a18ea1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -389,7 +389,7 @@ trait Implicits {
private def dominates(dtor: Type, dted: Type): Boolean = {
def core(tp: Type): Type = tp.dealiasWiden match {
case RefinedType(parents, defs) => intersectionType(parents map core, tp.typeSymbol.owner)
- case AnnotatedType(annots, tp, selfsym) => core(tp)
+ case AnnotatedType(annots, tp) => core(tp)
case ExistentialType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.bounds.hi)))
case PolyType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.bounds.hi)))
case _ => tp
@@ -1060,7 +1060,7 @@ trait Implicits {
getParts(restpe)
case RefinedType(ps, _) =>
for (p <- ps) getParts(p)
- case AnnotatedType(_, t, _) =>
+ case AnnotatedType(_, t) =>
getParts(t)
case ExistentialType(_, t) =>
getParts(t)
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 95f2620061..330dc0434b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1431,7 +1431,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
private def checkTypeRefBounds(tp: Type, tree: Tree) = {
var skipBounds = false
tp match {
- case AnnotatedType(ann :: Nil, underlying, selfSym) if ann.symbol == UncheckedBoundsClass =>
+ case AnnotatedType(ann :: Nil, underlying) if ann.symbol == UncheckedBoundsClass =>
skipBounds = true
underlying
case TypeRef(pre, sym, args) =>
@@ -1474,7 +1474,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
}
doTypeTraversal(tree) {
- case tp @ AnnotatedType(annots, _, _) =>
+ case tp @ AnnotatedType(annots, _) =>
applyChecks(annots)
case tp =>
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index b706e1af6b..06796eca8e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -542,7 +542,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
case TypeRef(pre, _, _) => isThisType(pre)
case SingleType(pre, _) => isThisType(pre)
case RefinedType(parents, _) => parents exists isThisType
- case AnnotatedType(_, tp, _) => isThisType(tp)
+ case AnnotatedType(_, tp) => isThisType(tp)
case _ => false
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 6b5afce993..c8e634eb4c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1122,7 +1122,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (treeInfo.isMacroApplication(tree)) adapt(unmarkMacroImplRef(tree), mode, pt, original)
else tree
} else tree.tpe match {
- case atp @ AnnotatedType(_, _, _) if canAdaptAnnotations(tree, this, mode, pt) => // (-1)
+ case atp @ AnnotatedType(_, _) if canAdaptAnnotations(tree, this, mode, pt) => // (-1)
adaptAnnotations(tree, this, mode, pt)
case ct @ ConstantType(value) if mode.inNone(TYPEmode | FUNmode) && (ct <:< pt) && canAdaptConstantTypeToLiteral => // (0)
adaptConstant(value)
@@ -3470,7 +3470,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
/**
* Convert an annotation constructor call into an AnnotationInfo.
*/
- def typedAnnotation(ann: Tree, mode: Mode = EXPRmode, selfsym: Symbol = NoSymbol): AnnotationInfo = {
+ def typedAnnotation(ann: Tree, mode: Mode = EXPRmode): AnnotationInfo = {
var hasError: Boolean = false
val pending = ListBuffer[AbsTypeError]()
@@ -3519,7 +3519,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
reportAnnotationError(ArrayConstantsError(tree)); None
case ann @ Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
- val annInfo = typedAnnotation(ann, mode, NoSymbol)
+ val annInfo = typedAnnotation(ann, mode)
val annType = annInfo.tpe
if (!annType.typeSymbol.isSubClass(pt.typeSymbol))
@@ -3631,28 +3631,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
}
else {
- val typedAnn = if (selfsym == NoSymbol) {
+ val typedAnn: Tree = {
// local dummy fixes SI-5544
val localTyper = newTyper(context.make(ann, context.owner.newLocalDummy(ann.pos)))
localTyper.typed(ann, mode, annType)
}
- else {
- // Since a selfsym is supplied, the annotation should have an extra
- // "self" identifier in scope for type checking. This is implemented
- // by wrapping the rhs in a function like "self => rhs" during type
- // checking, and then stripping the "self =>" and substituting in
- // the supplied selfsym.
- val funcparm = ValDef(NoMods, nme.self, TypeTree(selfsym.info), EmptyTree)
- // The .duplicate of annot.constr deals with problems that accur
- // if this annotation is later typed again, which the compiler
- // sometimes does. The problem is that "self" ident's within
- // annot.constr will retain the old symbol from the previous typing.
- val func = Function(funcparm :: Nil, ann.duplicate)
- val funcType = appliedType(FunctionClass(1), selfsym.info, annType)
- val Function(arg :: Nil, rhs) = typed(func, mode, funcType)
-
- rhs.substituteSymbols(arg.symbol :: Nil, selfsym :: Nil)
- }
def annInfo(t: Tree): AnnotationInfo = t match {
case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
AnnotationInfo(annType, args, List()).setOriginal(typedAnn).setPos(t.pos)
@@ -3770,7 +3753,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
t match {
case ExistentialType(tparams, _) =>
boundSyms ++= tparams
- case AnnotatedType(annots, _, _) =>
+ case AnnotatedType(annots, _) =>
for (annot <- annots; arg <- annot.args) {
arg match {
case Ident(_) =>
@@ -4035,39 +4018,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (arg1.isType) {
// make sure the annotation is only typechecked once
if (ann.tpe == null) {
- // an annotated type
- val selfsym =
- if (!settings.selfInAnnots)
- NoSymbol
- else
- arg1.tpe.selfsym orElse {
- /* Implementation limitation: Currently this
- * can cause cyclical reference errors even
- * when the self symbol is not referenced at all.
- * Surely at least some of these cases can be
- * fixed by proper use of LazyType's. Lex tinkered
- * on this but did not succeed, so is leaving
- * it alone for now. Example code with the problem:
- * class peer extends Annotation
- * class NPE[T <: NPE[T] @peer]
- *
- * (Note: -Yself-in-annots must be on to see the problem)
- * */
- ( context.owner
- newLocalDummy (ann.pos)
- newValue (nme.self, ann.pos)
- setInfo (arg1.tpe.withoutAnnotations)
- )
- }
-
- val ainfo = typedAnnotation(ann, annotMode, selfsym)
- val atype0 = arg1.tpe.withAnnotation(ainfo)
- val atype =
- if ((selfsym != NoSymbol) && (ainfo.refsSymbol(selfsym)))
- atype0.withSelfsym(selfsym)
- else
- atype0 // do not record selfsym if
- // this annotation did not need it
+ val ainfo = typedAnnotation(ann, annotMode)
+ val atype = arg1.tpe.withAnnotation(ainfo)
if (ainfo.isErroneous)
// Erroneous annotations were already reported in typedAnnotation