Skip to content

Shared backend #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
Dec 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7d470b3
Sharing backend between scalac and dotty.
DarkDimius Nov 25, 2014
24954cd
Erasure is on by default.
DarkDimius Nov 27, 2014
4b948aa
Update to scala 2.11.4
DarkDimius Nov 27, 2014
9c8976d
Hack ClassFileParser to not treat Null$ or Nothing$ as modules.
DarkDimius Nov 27, 2014
6aa4613
Move methods shared between Mixin and Backend to SymUtils.
DarkDimius Nov 27, 2014
c742e95
Remove duplicate isAnonymousFunction
DarkDimius Nov 27, 2014
0db32d2
New phase: collectEntryPoints
DarkDimius Nov 27, 2014
7bc36d8
Depend on custom compiler with https://github.com/scala/scala/pull/41…
DarkDimius Nov 27, 2014
feff447
remove dependency on Btypes from DottyPrimitives. Rely on symbols ins…
DarkDimius Nov 27, 2014
e51d0d1
GenBcode phase implemented.
DarkDimius Nov 27, 2014
e2dbf88
Add member lookups needed by backend.
DarkDimius Nov 27, 2014
6878d9b
Complete DottyBackendInterface.
DarkDimius Nov 27, 2014
156b62c
Enable new phases.
DarkDimius Nov 27, 2014
1ba9f18
Disable backend by default in tests.
DarkDimius Nov 27, 2014
0b73ed1
Mixing now also changes Scala2 traits into interfaces.
DarkDimius Nov 27, 2014
1c5e7b7
Modify runner script to include modified scalac on class path.
DarkDimius Nov 27, 2014
339b746
Add test for backend.
DarkDimius Nov 27, 2014
3943aa8
Update class-path dependant tests. Disable one.
DarkDimius Nov 27, 2014
f78ef2c
Label test with nested cycles and simple patterns.
DarkDimius Dec 1, 2014
15bfcda
Implemented handling of <label> DefDefs in backend.
DarkDimius Dec 1, 2014
6446bbb
Fix bug in dotty interface: wrong symbols used to get box\unbox methods
DarkDimius Dec 1, 2014
d23cab1
Handle Arrays in backend.
DarkDimius Dec 1, 2014
20e9051
Fix StackOverflow in handling of try. Try is now supported by backend
DarkDimius Dec 1, 2014
7b29889
Support LabelDef's with Arguments. Fixes tailrec.
DarkDimius Dec 1, 2014
f2681f5
Update to newer version of scalac fork
DarkDimius Dec 1, 2014
f715875
Make LambdaLifted methods follow JVM8 lambda parameters order.
DarkDimius Dec 2, 2014
f3c74e1
Adapt dotty to changes in BackendInterface that save allocation on Pr…
DarkDimius Dec 2, 2014
fd21e6e
Implemented handling of Closures.
DarkDimius Dec 2, 2014
eb50bc4
Fix originalOwner for symbols that did not exist at typer.
DarkDimius Dec 2, 2014
07b4b87
Mixin makes all traits Java Interfaces.
DarkDimius Dec 2, 2014
c165784
Java8 is the default target
DarkDimius Dec 2, 2014
48d9a29
Fix TypeSymbol for This references in backend
DarkDimius Dec 2, 2014
6509f59
Disable PrivateToStatic until it is fixed.
DarkDimius Dec 2, 2014
f9d19ce
implement isQualifierSafeToElide
DarkDimius Dec 2, 2014
9e15d16
Fix generation of lambdas for Unit-returning closures.
DarkDimius Dec 3, 2014
81130ce
Fix bugs around emulating scalac linkedClassOfClass.
DarkDimius Dec 3, 2014
ff3de34
Adapt backend to changes in scalac: new symbols get positions and types.
DarkDimius Dec 3, 2014
cf53701
Differentiate between scala and java's flags: private and final
DarkDimius Dec 3, 2014
4b98e22
Stop using deprecated methods in GenBcode.
DarkDimius Dec 3, 2014
e6fcd3f
Mimic scalac originalOwner.
DarkDimius Dec 3, 2014
9657586
Fix #257 ModuleDefs had invalid constructors.
DarkDimius Dec 3, 2014
89c2f12
Handle JavaSeqLiterals.
DarkDimius Dec 4, 2014
7b2c5ba
Add default methods generation.
DarkDimius Dec 4, 2014
68e2a8c
Untroduce SumUtils.superInterfaces which is different from mixins.
DarkDimius Dec 5, 2014
4eccc1b
Desugar dotty Idents to selects
DarkDimius Dec 5, 2014
d498b6a
Rely on Trait flag to generate interfaces.
DarkDimius Dec 5, 2014
72c979e
Fix #258: string trailing $ in module names in backend.
DarkDimius Dec 5, 2014
e556edf
Use correct methods to get super interfaces of a class.
DarkDimius Dec 5, 2014
81d56b0
Fix loading of static methods in java.lang.String.
DarkDimius Dec 5, 2014
92dceb1
Handle Array.clone
DarkDimius Dec 12, 2014
4a5e732
Fix concatenation of multiple strings
DarkDimius Dec 12, 2014
281da4f
Update version of scalac fork
DarkDimius Dec 12, 2014
11e7dd8
Update docs and make memberClasses uses typeNameFilter.
DarkDimius Dec 15, 2014
38ac631
Make String_valueOf_Object agnostic of whether it runs before or afte…
DarkDimius Dec 15, 2014
c3bdd0b
Stay compatible with scalac and javac in -d cli option
DarkDimius Dec 15, 2014
4c11203
Enable backend specific tests. Flag those that fail
DarkDimius Dec 15, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions bin/dotc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


# Configuration
SCALA_VERSION=2.11.1
SCALA_VERSION=2.11.4
SCALA_BINARY_VERSION=2.11
SCALA_COMPILER_VERSION=2.11.5-20141212-151631-beaa78b033
DOTTY_VERSION=0.1
bootcp=true
default_java_opts="-Xmx768m -Xms768m"
Expand Down Expand Up @@ -62,12 +63,18 @@ if [ "$SCALA_REFLECT_JAR" == "" ]
then
SCALA_REFLECT_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-$SCALA_VERSION.jar
fi
if [ "$SCALA_COMPILER_JAR" == "" ]
then
SCALA_COMPILER_JAR=$HOME/.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-$SCALA_COMPILER_VERSION.jar
fi

if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" ]
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" ]
then
echo To use this script please set
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)"
echo SCALA_COMPILER_JAR to point to scala-compiler-$SCALA_VERSION.jar with bcode patches "(currently $SCALA_COMPILER_JAR)"

fi

ifdebug () {
Expand Down Expand Up @@ -156,7 +163,7 @@ trap onExit INT
# to java to suppress "." from materializing.
classpathArgs () {
if [[ -n $bootcp ]]; then
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR -classpath $MAIN_JAR"
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$MAIN_JAR -classpath $MAIN_JAR"
else
echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR"
fi
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

name := "dotty"

scalaVersion in Global := "2.11.1"
scalaVersion in Global := "2.11.4"

version in Global := "0.1-SNAPSHOT"

Expand Down
Empty file added out/.keep
Empty file.
5 changes: 3 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ object DottyBuild extends Build {

// get reflect and xml onboard
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang.modules" %% "scala-xml" % "1.0.1"),
"org.scala-lang.modules" %% "scala-xml" % "1.0.1",
"me.d-d" % "scala-compiler" % "2.11.5-20141212-151631-beaa78b033"),

// get junit onboard
libraryDependencies += "com.novocode" % "junit-interface" % "0.11-RC1" % "test",
Expand All @@ -53,7 +54,7 @@ object DottyBuild extends Build {

// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
javaOptions <++= (managedClasspath in Runtime, packageBin in Compile) map { (attList, bin) =>
// put the Scala {library, reflect, compiler} in the classpath
// put the Scala {library, reflect} in the classpath
val path = for {
file <- attList.map(_.data)
path = file.getAbsolutePath
Expand Down
120 changes: 120 additions & 0 deletions src/dotty/tools/backend/jvm/CollectEntryPoints.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package dotty.tools.backend.jvm

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Types
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransform, MiniPhase, MiniPhaseTransform}
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc
import dotty.tools.dotc.backend.jvm.DottyPrimitives
import dotty.tools.dotc.core.Flags.FlagSet
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.transform.SymUtils._
import java.io.{File => JFile}

import scala.collection.generic.Clearable
import scala.collection.mutable
import scala.reflect.ClassTag
import scala.reflect.internal.util.WeakHashSet
import scala.reflect.io.{Directory, PlainDirectory, AbstractFile}
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
import dotty.tools.dotc.core._
import Periods._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Denotations._
import Phases._
import java.lang.AssertionError
import dotty.tools.dotc.util.Positions.Position
import Decorators._
import tpd._
import StdNames.nme

/**
* Created by dark on 26/11/14.
*/
class CollectEntryPoints extends MiniPhaseTransform {
def phaseName: String = "Collect entry points"

override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
if((tree.symbol ne NoSymbol) && CollectEntryPoints.isJavaEntyPoint(tree.symbol)) {
ctx.genBCodePhase.asInstanceOf[GenBCode].registerEntryPoint(tree.symbol)
}
tree
}
}

object CollectEntryPoints{
def isJavaEntyPoint(sym: Symbol)(implicit ctx: Context): Boolean = {
import Types.MethodType
val d = ctx.definitions
val StringType = d.StringType
def isJavaMainMethod(sym: Symbol) = (sym.name == nme.main) && (toDenot(sym).info match {
case r@ MethodType(_, List(d.ArrayType(StringType))) => r.resultType eq d.UnitType
case _ => false
})
// The given class has a main method.
def hasJavaMainMethod(sym: Symbol): Boolean =
(toDenot(sym).info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))

def fail(msg: String, pos: Position = sym.pos) = {
ctx.warning( sym.name +
s" has a main method with parameter type Array[String], but ${toDenot(sym).fullName} will not be a runnable program.\n Reason: $msg",
sourcePos(sym.pos)
// TODO: make this next claim true, if possible
// by generating valid main methods as static in module classes
// not sure what the jvm allows here
// + " You can still run the program by calling it as " + javaName(sym) + " instead."
)
false
}
def failNoForwarder(msg: String) = {
fail(s"$msg, which means no static forwarder can be generated.\n")
}
val possibles = if (sym.flags is Flags.Module) (toDenot(sym).info nonPrivateMember nme.main).alternatives else Nil
val hasApproximate = possibles exists { m =>
m.info match {
case MethodType(_, p :: Nil) =>
p.typeSymbol == defn.ArrayClass
case _ => false
}
}
// At this point it's a module with a main-looking method, so either succeed or warn that it isn't.
hasApproximate && {
// Before erasure so we can identify generic mains.
{
// implicit val c = ctx.withPhase(ctx.erasurePhase)

val companion = sym.asClass.moduleClass

if (hasJavaMainMethod(companion))
failNoForwarder("companion contains its own main method")
else if (toDenot(companion).info.member(nme.main) != NoDenotation)
// this is only because forwarders aren't smart enough yet
failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
else if (companion.flags is Flags.Trait)
failNoForwarder("companion is a trait")
// Now either succeeed, or issue some additional warnings for things which look like
// attempts to be java main methods.
else (possibles exists(x=> isJavaMainMethod(x.symbol))) || {
possibles exists { m =>
toDenot(m.symbol).info match {
case t:PolyType =>
fail("main methods cannot be generic.")
case t@MethodType(paramNames, paramTypes) =>
if (t.resultType :: paramTypes exists (_.typeSymbol.isAbstractType))
fail("main methods cannot refer to type parameters or abstract types.", m.symbol.pos)
else
isJavaMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.pos)
case tp =>
fail(s"don't know what this is: $tp", m.symbol.pos)
}
}
}
}
}
}
}
Loading