diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-08-15 13:37:26 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-08-15 17:46:11 +0200 |
commit | 46d57d47e81c8794a9a3594e080576788cc92324 (patch) | |
tree | b527c1dfb44d2753c8ae925580838d688e5fccd0 /src/compiler/scala/tools/nsc/typechecker | |
parent | ce90a46a6964e524933ffe193ac38d58d3df07be (diff) | |
download | scala-46d57d47e81c8794a9a3594e080576788cc92324.tar.gz scala-46d57d47e81c8794a9a3594e080576788cc92324.tar.bz2 scala-46d57d47e81c8794a9a3594e080576788cc92324.zip |
cleanup of reflection- and macro-related stuff
mostly removes [Eugene] marks that I left back then and reviews related code
some of those tokens got left in place, because I don't know to how fix them
without imposing risks on 2.10.0
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
6 files changed, 22 insertions, 37 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index f9035f26b9..924d590edb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1185,10 +1185,6 @@ trait Implicits { // ClassTags are not path-dependent, so their materializer doesn't care about prefixes if (tagClass eq ClassTagClass) gen.mkBasisUniverseRef else pre match { - // [Eugene to Martin] this is the crux of the interaction between - // implicits and reifiers here we need to turn a (supposedly - // path-dependent) type into a tree that will be used as a prefix I'm - // not sure if I've done this right - please, review case SingleType(prePre, preSym) => gen.mkAttributedRef(prePre, preSym) setType pre // necessary only to compile typetags used inside the Universe cake @@ -1373,7 +1369,8 @@ trait Implicits { /** The result of the implicit search: * First search implicits visible in current context. * If that fails, search implicits in expected type `pt`. - * // [Eugene] the following lines should be deleted after we migrate delegate tag materialization to implicit macros + * + * todo. the following lines should be deleted after we migrate delegate tag materialization to implicit macros * If that fails, and `pt` is an instance of a ClassTag, try to construct a class tag. * If that fails, and `pt` is an instance of a TypeTag, try to construct a type tag. * If that fails, and `pt` is an instance of a ClassManifest, try to construct a class manifest. diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index c8bf70e9e0..c2ab5edbb6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -132,9 +132,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { // there are some more clever cases when seemingly non-static method ends up being statically accessible // however, the code below doesn't account for these guys, because it'd take a look of time to get it right // for now I leave it as a todo and move along to more the important stuff - // [Eugene] relies on the fact that macro implementations can only be defined in static classes - // [Martin to Eugene++] There's similar logic buried in Symbol#flatname. Maybe we can refactor? - // [Eugene] we will refactor once I get my hands on https://issues.scala-lang.org/browse/SI-5498 + // todo. refactor when fixing SI-5498 def className: String = { def loop(sym: Symbol): String = sym match { case sym if sym.owner.isPackageClass => @@ -445,7 +443,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { // because it's adapt which is responsible for automatic expansion during typechecking def typecheckRhs(rhs: Tree): Tree = { try { - val prevNumErrors = reporter.ERROR.count // [Eugene] funnily enough, the isErroneous check is not enough + val prevNumErrors = reporter.ERROR.count var rhs1 = if (hasError) EmptyTree else typer.typed1(rhs, EXPRmode, WildcardType) def typecheckedWithErrors = (rhs1 exists (_.isErroneous)) || reporter.ERROR.count != prevNumErrors def rhsNeedsMacroExpansion = rhs1.symbol != null && rhs1.symbol.isTermMacro && !rhs1.symbol.isErroneous @@ -681,8 +679,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { // transform type parameters of a macro implementation into type parameters of a macro definition runtimeType = runtimeType map { case TypeRef(pre, sym, args) => - // [Eugene] not sure which of these deSkolemizes are necessary - // sym.paramPos is unreliable (see another case below) + // sym.paramPos is unreliable (see an example in `macroArgs`) val tparams = macroImpl.typeParams map (_.deSkolemize) val paramPos = tparams indexOf sym.deSkolemize val sym1 = @@ -745,7 +742,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { * Loads classes from from -cp (aka the library classpath). * Is also capable of detecting REPL and reusing its classloader. */ - private lazy val macroClassloader: ClassLoader = { + lazy val macroClassloader: ClassLoader = { if (global.forMSIL) throw new UnsupportedOperationException("Scala reflection not available on this platform") @@ -753,7 +750,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { macroLogVerbose("macro classloader: initializing from -cp: %s".format(classpath)) val loader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) - // [Eugene] a heuristic to detect the REPL + // a heuristic to detect the REPL if (global.settings.exposeEmptyPackage.value) { macroLogVerbose("macro classloader: initializing from a REPL classloader".format(global.classPath.asURLs)) import scala.tools.nsc.interpreter._ @@ -787,9 +784,11 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { val methName = binding.methName macroLogVerbose(s"resolved implementation as $className.$methName") - // [Eugene++] I don't use Scala reflection here, because it seems to interfere with JIT magic + // I don't use Scala reflection here, because it seems to interfere with JIT magic // whenever you instantiate a mirror (and not do anything with in, just instantiate), performance drops by 15-20% // I'm not sure what's the reason - for me it's pure voodoo + // upd. my latest experiments show that everything's okay + // it seems that in 2.10.1 we can easily switch to Scala reflection try { macroTraceVerbose("loading implementation class: ")(className) macroTraceVerbose("classloader is: ")(ReflectionUtils.show(macroClassloader)) @@ -889,7 +888,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { val targ = binding.targs(paramPos).tpe.typeSymbol val tpe = if (targ.isTypeParameterOrSkolem) { if (targ.owner == macroDef) { - // [Eugene] doesn't work when macro def is compiled separately from its usages + // doesn't work when macro def is compiled separately from its usages // then targ is not a skolem and isn't equal to any of macroDef.typeParams // val argPos = targ.deSkolemize.paramPos val argPos = macroDef.typeParams.indexWhere(_.name == targ.name) @@ -970,7 +969,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { // so I added this dummy local for the ease of debugging var expectedTpe = expandee.tpe - // [Eugene] weird situation. what's the conventional way to deal with it? val isNullaryInvocation = expandee match { case TypeApply(Select(_, _), _) => true case TypeApply(Ident(_), _) => true @@ -1117,8 +1115,9 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { macroLogLite("typechecking macro expansion %s at %s".format(expandee, expandee.pos)) macroArgs(typer, expandee).fold(failExpansion(): MacroExpansionResult) { args => (args: @unchecked) match { - // [Eugene++] crashes virtpatmat: + // crashes virtpatmat: // case args @ ((context: MacroContext) :: _) => + // todo. extract a minimized test case case args @ (context0 :: _) => val context = context0.asInstanceOf[MacroContext] if (nowDelayed) { @@ -1197,7 +1196,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { } private def handleMacroExpansionException(typer: Typer, expandee: Tree, ex: Throwable): MacroExpansionResult = { - // [Eugene] any ideas about how to improve this one? val realex = ReflectionUtils.unwrapThrowable(ex) realex match { case realex: reflect.macros.runtime.AbortMacroException => diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index dd180e6b76..f7ba189e0f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -31,7 +31,6 @@ trait MethodSynthesis { else DefDef(sym, body) def applyTypeInternal(tags: List[TT[_]]): Type = { - // [Eugene++ to Paul] needs review!! val symbols = tags map compilerSymbolFromTag val container :: args = symbols val tparams = container.typeConstructor.typeParams @@ -53,21 +52,14 @@ trait MethodSynthesis { applyTypeInternal(List(t1)) def applyType[CC[X1], X1](implicit t1: TT[CC[_]], t2: TT[X1]): Type = - applyTypeInternal(List[TT[_]](t1, t2)) + applyTypeInternal(List(t1, t2)) def applyType[CC[X1, X2], X1, X2](implicit t1: TT[CC[_,_]], t2: TT[X1], t3: TT[X2]): Type = - // [Eugene++] without an explicit type annotation for List, we get this: - // [scalacfork] C:\Projects\KeplerUnderRefactoring\src\compiler\scala\tools\nsc\typechecker\MethodSynthesis.scala:59: error: no type parameters for method apply: (xs: A*)List[A] in object List exist so that it can be applied to arguments (scala.tools.nsc.typechecker.MethodSynthesis.synthesisUtil.TT[CC[_, _]], scala.tools.nsc.typechecker.MethodSynthesis.synthesisUtil.TT[X1], scala.tools.nsc.typechecker.MethodSynthesis.synthesisUtil.TT[X2]) - // [scalacfork] --- because --- - // [scalacfork] undetermined type - // [scalacfork] applyTypeInternal(List(t1, t2, t3)) - applyTypeInternal(List[TT[_]](t1, t2, t3)) + applyTypeInternal(List(t1, t2, t3)) def applyType[CC[X1, X2, X3], X1, X2, X3](implicit t1: TT[CC[_,_,_]], t2: TT[X1], t3: TT[X2], t4: TT[X3]): Type = - applyTypeInternal(List[TT[_]](t1, t2, t3, t4)) + applyTypeInternal(List(t1, t2, t3, t4)) - // [Martin->Eugene] !!! reinstantiate when typeables are in. - // [Eugene++->Martin] now this compiles, will soon check it out def newMethodType[F](owner: Symbol)(implicit t: TT[F]): Type = { val fnSymbol = compilerSymbolFromTag(t) val formals = compilerTypeFromTag(t).typeArguments diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index c7c9d2f4aa..d227f485c2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -63,7 +63,7 @@ trait SyntheticMethods extends ast.TreeDSL { // in the original order. def accessors = clazz.caseFieldAccessors sortBy { acc => originalAccessors indexWhere { orig => - (acc.name == orig.name) || (acc.name startsWith (orig.name append "$").asInstanceOf[Name]) // [Eugene++] why do we need this cast? + (acc.name == orig.name) || (acc.name startsWith (orig.name append "$").asInstanceOf[Name]) // [Eugene] why do we need this cast? } } val arity = accessors.size @@ -87,7 +87,7 @@ trait SyntheticMethods extends ast.TreeDSL { ) def forwardToRuntime(method: Symbol): Tree = - forwardMethod(method, getMember(ScalaRunTimeModule, (method.name prepend "_").asInstanceOf[Name]))(mkThis :: _) // [Eugene++] why do we need this cast? + forwardMethod(method, getMember(ScalaRunTimeModule, (method.name prepend "_").asInstanceOf[Name]))(mkThis :: _) // [Eugene] why do we need this cast? def callStaticsMethod(name: String)(args: Tree*): Tree = { val method = termMember(RuntimeStaticsModule, name) diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 4a0977eb90..f0dca64a00 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -462,7 +462,6 @@ trait TypeDiagnostics { case CyclicReference(sym, info: TypeCompleter) => if (context0.owner.isTermMacro) { // see comments to TypeSigError for an explanation of this special case - // [Eugene] is there a better way? throw ex } else { val pos = info.tree match { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a6d7fcda75..7c509f4d33 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -51,7 +51,6 @@ trait Typers extends Modes with Adaptations with Tags { transformed.clear() } - // [Eugene] shouldn't this be converted to resetAllAttrs? object UnTyper extends Traverser { override def traverse(tree: Tree) = { if (tree != EmptyTree) tree.tpe = null @@ -909,7 +908,7 @@ trait Typers extends Modes with Adaptations with Tags { def adaptType(): Tree = { if (inFunMode(mode)) { - // [Eugene++] the commented line below makes sense for typechecking, say, TypeApply(Ident(`some abstract type symbol`), List(...)) + // todo. the commented line below makes sense for typechecking, say, TypeApply(Ident(`some abstract type symbol`), List(...)) // because otherwise Ident will have its tpe set to a TypeRef, not to a PolyType, and `typedTypeApply` will fail // but this needs additional investigation, because it crashes t5228, gadts1 and maybe something else // tree setType tree.tpe.normalize @@ -2609,7 +2608,7 @@ trait Typers extends Modes with Adaptations with Tags { val stats1 = typedStats(stats, NoSymbol) // this code kicks in only after typer, so `stats` will never be filled in time // as a result, most of compound type trees with non-empty stats will fail to reify - // [Eugene++] todo. investigate whether something can be done about this + // todo. investigate whether something can be done about this val att = templ.attachments.get[CompoundTypeTreeOriginalAttachment].getOrElse(CompoundTypeTreeOriginalAttachment(Nil, Nil)) templ.removeAttachment[CompoundTypeTreeOriginalAttachment] templ addAttachment att.copy(stats = stats1) @@ -3416,7 +3415,7 @@ trait Typers extends Modes with Adaptations with Tags { } if (hasError) annotationError - else AnnotationInfo(annType, List(), nvPairs map {p => (p._1.asInstanceOf[Name], p._2.get)}).setOriginal(Apply(typedFun, args).setPos(ann.pos)) // [Eugene+] why do we need this cast? + else AnnotationInfo(annType, List(), nvPairs map {p => (p._1.asInstanceOf[Name], p._2.get)}).setOriginal(Apply(typedFun, args).setPos(ann.pos)) // [Eugene] why do we need this cast? } } else if (requireJava) { reportAnnotationError(NestedAnnotationError(ann, annType)) @@ -5105,7 +5104,7 @@ trait Typers extends Modes with Adaptations with Tags { erasure.GenericArray.unapply(tpt.tpe).isDefined) => // !!! todo simplify by using extractor // convert new Array[T](len) to evidence[ClassTag[T]].newArray(len) // convert new Array^N[T](len) for N > 1 to evidence[ClassTag[Array[...Array[T]...]]].newArray(len), where Array HK gets applied (N-1) times - // [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions) + // no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions) val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe) val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last val newArrayApp = atPos(tree.pos) { |