Skip to content

Instantly share code, notes, and snippets.

View xeno-by's full-sized avatar

Eugene Burmako xeno-by

View GitHub Profile
// *** What we want to do ***
// Write a mini-cake that would take and return path-dependent universe artifacts
// retaining precise path-dependent types when returning values
trait Universe {
type Tree
}
object ru extends Universe {
class Tree
18:09 ~/Projects/210x/sandbox (2.10.x)$ scala
Welcome to Scala version 2.10.5-20140326-123924-c74e1325ff (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_40).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val tpe1 = typeOf[Some[Int]]
tpe1: reflect.runtime.universe.Type = scala.Some[Int]
scala> val tpe2a = typeOf[Option[_]]
tpe2a: reflect.runtime.universe.Type = scala.Option[_]
17:19 ~/Projects/Master/sandbox (master)$ st
[[syntax trees at end of typer]] // Test.scala
package <empty> {
abstract trait B extends scala.AnyRef;
class C1 extends scala.AnyRef {
def <init>(): C1 = {
C1.super.<init>();
()
};
scala.this.Predef.println(this)
17:20 ~/Projects/Master/sandbox (master)$ st
[[syntax trees at end of typer]] // Test.scala
package <empty> {
abstract trait B extends scala.AnyRef;
class C1 extends scala.AnyRef {
def <init>(): C1 = {
C1.super.<init>();
()
};
private[this] val x1: C1 = this;
[info] when verifying Template.this.parents.length.!=(0).&&(Template.this.parents.tail.exists(((x$3) => x$3.argss.nonEmpty))).`unary_!`
[info] found that Template.this.parents.length is not equal to 0
[info] and also Template.this.parents.tail.forall(((x$3) => x$3.argss.nonEmpty.`unary_!`)) is false
[info] context is Template(List(),List(Parent(Ident(),List(List())), Parent(Ident(),List(List()))),Self(None,None),List())
[info] when verifying !(parents.length != 0 && parents.tail.exists((_.argss.nonEmpty)))
[info] found that parents.length is not equal to 0
[info] and also parents.tail.forall(_.argss.empty) is false
[info] context is Template(List(),List(Parent(Ident(),List(List())), Parent(Ident(),List(List()))),Self(None,None),List())
class ReflectCompilationUnit {
type Icode
def icodes: List[Icode] = Nil
}
class CompilerCompilationUnit extends ReflectCompilationUnit {
type Icode = compiler.Icode
override val icodes: List[Icode] = ...
}
class ReflectTypechecker { self =>
type UnaffiliatedMacroContext <: scala.reflect.moved.macros.contexts.Context
type MacroContext = UnaffiliatedMacroContext { val universe: self.global.type }
def newContext(): MacroContext = new ReflectMacroContext().asInstanceOf[MacroContext]
}
class CompilerTypechecker extends ReflectTypechecker {
override type UnaffiliatedMacroContext = scala.reflect.macros.contexts.Context
override def newContext(): MacroContext = new CompilerMacroContext().asInstanceOf[MacroContext]
}
@clean
def foo = bar
// expands into
def foo = WartRemover.clean(bar)
11:42 ~/Projects/211x/sandbox (2.11.x)$ cat Test.scala
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox
import scala.tools.reflect.Eval
object Test extends App {
val tb = cm.mkToolBox(options = "-Ydump-classes .")
println(tb.eval(q"123"))
}
[INFO] --- scala-maven-plugin:3.1.7-SNAPSHOT:compile (scala-compile-first) @ scala ---
[WARNING] Zinc server is not available at port 3030 - reverting to normal incremental compile
[INFO] Using incremental compilation
[WARNING] extra args for zinc are ignored in non-server mode
[INFO] 'compiler-interface' not yet compiled for Scala 2.11.2. Compiling...
/var/folders/bq/rz89jq0x4f13cm4sk6ss08l80000gn/T/sbt_3f3e9cfe/CompilerInterface.scala:246: error: recursive method rootLoader needs result type
override def rootLoader = if(resident) newPackageLoaderCompat(rootLoader)(compiler.classPath) else super.rootLoader
^
/var/folders/bq/rz89jq0x4f13cm4sk6ss08l80000gn/T/sbt_3f3e9cfe/CompilerInterface.scala:246: error: value rootLoader is not a member of scala.tools.nsc.backend.JavaPlatform
override def rootLoader = if(resident) newPackageLoaderCompat(rootLoader)(compiler.classPath) else super.rootLoader