diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-01-21 00:50:15 -0800 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-01-21 00:50:15 -0800 |
commit | 26387cacaa8f78105419044fc33acc8fd8343662 (patch) | |
tree | 15fe66051230bb183786d945c65270cb49049cd6 /src/compiler | |
parent | af89c3d258c98351868e5ed5acee97e5b2268452 (diff) | |
parent | 07ff3a99b75174c4e4a4e52348b34aa0b68f51b1 (diff) | |
download | scala-26387cacaa8f78105419044fc33acc8fd8343662.tar.gz scala-26387cacaa8f78105419044fc33acc8fd8343662.tar.bz2 scala-26387cacaa8f78105419044fc33acc8fd8343662.zip |
Merge pull request #3368 from retronym/ticket/8151
SI-8151 Remove -Yself-in-annots and associated implementation
Diffstat (limited to 'src/compiler')
13 files changed, 25 insertions, 75 deletions
diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala index 99b968be3b..a90a3a338b 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala @@ -60,7 +60,7 @@ trait GenTypes { reifyProduct(tpe) case tpe @ NullaryMethodType(restpe) => reifyProduct(tpe) - case tpe @ AnnotatedType(anns, underlying, selfsym) => + case tpe @ AnnotatedType(anns, underlying) => reifyAnnotatedType(tpe) case _ => reifyToughType(tpe) @@ -162,8 +162,8 @@ trait GenTypes { /** Reify an annotated type, i.e. the one that makes us deal with AnnotationInfos */ private def reifyAnnotatedType(tpe: AnnotatedType): Tree = { - val AnnotatedType(anns, underlying, selfsym) = tpe - mirrorFactoryCall(nme.AnnotatedType, mkList(anns map reifyAnnotationInfo), reify(underlying), reify(selfsym)) + val AnnotatedType(anns, underlying) = tpe + mirrorFactoryCall(nme.AnnotatedType, mkList(anns map reifyAnnotationInfo), reify(underlying)) } /** Reify a tough type, i.e. the one that leads to creation of auxiliary symbols */ 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 6b1bb5b220..18ccced75e 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala @@ -516,7 +516,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 307f42c0bc..a3114a3d7b 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -161,7 +161,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 06a1e21e8b..91321d4700 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 4ba8d56da0..68d724b6fc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1427,7 +1427,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) => @@ -1470,7 +1470,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 a5334a6779..9776b1e80e 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) @@ -3493,7 +3493,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]() @@ -3542,7 +3542,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)) @@ -3654,28 +3654,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) @@ -3793,7 +3776,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(_) => @@ -4058,39 +4041,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 |