diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-07-02 00:37:59 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-07-02 00:53:04 +0200 |
commit | 105d3efcc723cb7312a25a898a7769c7f762b57e (patch) | |
tree | c36e1188cd883b1b9da10b36369c6ee2611cf7f9 /src/compiler/scala/tools/reflect/ReflectGlobal.scala | |
parent | cd1e6f94e92f2c8fc79aa3c76b1e3b813182e2d3 (diff) | |
download | scala-105d3efcc723cb7312a25a898a7769c7f762b57e.tar.gz scala-105d3efcc723cb7312a25a898a7769c7f762b57e.tar.bz2 scala-105d3efcc723cb7312a25a898a7769c7f762b57e.zip |
moves reflective compiler into scala.tools.reflect
Diffstat (limited to 'src/compiler/scala/tools/reflect/ReflectGlobal.scala')
-rw-r--r-- | src/compiler/scala/tools/reflect/ReflectGlobal.scala | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/reflect/ReflectGlobal.scala b/src/compiler/scala/tools/reflect/ReflectGlobal.scala new file mode 100644 index 0000000000..f8ded56ec6 --- /dev/null +++ b/src/compiler/scala/tools/reflect/ReflectGlobal.scala @@ -0,0 +1,40 @@ +package scala.tools +package reflect + +import scala.tools.nsc.Global +import scala.tools.nsc.reporters.Reporter +import scala.tools.nsc.Settings + +/** A version of Global that uses reflection to get class + * infos, instead of reading class or source files. + */ +class ReflectGlobal(currentSettings: Settings, reporter: Reporter, override val rootClassLoader: ClassLoader) + extends Global(currentSettings, reporter) with scala.tools.reflect.ReflectSetup with scala.reflect.runtime.SymbolTable { + + override def transformedType(sym: Symbol) = + erasure.transformInfo(sym, + uncurry.transformInfo(sym, + refChecks.transformInfo(sym, sym.info))) + + override def isCompilerUniverse = true + + // Typically `runtimeMirror` creates a new mirror for every new classloader + // and shares symbols between the created mirrors. + // + // However we can't do that for the compiler. + // The problem is that symbol sharing violates owner chain assumptions that the compiler has. + // + // For example, we can easily end up with a situation when: + // + // Predef defined in package scala loaded by the classloader that has scala-library.jar + // + // cannot be accessed in: + // + // package scala for the rootMirror of ReflectGlobal that might correspond to a different classloader + // + // This happens because, despite the fact that `Predef` is shared between multiple `scala` packages (i.e. multiple scopes) + // (each mirror has its own set package symbols, because of the peculiarities of symbol loading in scala), + // that `Predef` symbol only has a single owner, and this messes up visibility, which is calculated based on owners, not scopes. + override def runtimeMirror(cl: ClassLoader): Mirror = rootMirror +} + |