Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'dotty/master' into call-graph-wip-1
  • Loading branch information
nicolasstucki committed May 31, 2017
2 parents a0c5350 + 99a314f commit 0fff181
Show file tree
Hide file tree
Showing 274 changed files with 4,216 additions and 857 deletions.
13 changes: 12 additions & 1 deletion .drone.yml
Expand Up @@ -22,13 +22,24 @@ pipeline:
commands:
- ./project/scripts/sbt ";clean ;publishLocal" "${CI_PUBLISH}"
- ./project/scripts/sbt "sbt-dotty/scripted source-dependencies/*" "${CI_PUBLISH}"
- ./project/scripts/sbtPublish ${CI_PUBLISH} $SONATYPE_USER $SONATYPE_PW $PGP_PW
- NIGHTLYBUILD="yes" ./project/scripts/sbtPublish ${CI_PUBLISH} $SONATYPE_USER $SONATYPE_PW $PGP_PW
volumes:
- /home/drone/keys:/keys
when:
event: deployment
environment: nightly

publish_release:
image: lampepfl/dotty:24-04-2017
pull: true
commands:
- RELEASEBUILD="yes" ./project/scripts/sbtPublish ${CI_PUBLISH} $SONATYPE_USER $SONATYPE_PW $PGP_PW
volumes:
- /home/drone/keys:/keys
when:
event: deployment
environment: release

documentation:
image: lampepfl/dotty:24-04-2017
pull: true
Expand Down
2 changes: 1 addition & 1 deletion .drone.yml.sig
@@ -1 +1 @@
eyJhbGciOiJIUzI1NiJ9.IyBBZnRlciB1cGRhdGluZyB0aGlzIGZpbGUsIHlvdSBuZWVkIHRvIHJlLXNpZ24gaXQ6CiMKIyAtIEluc3RhbGwgW2Ryb25lLWNsaV0oaHR0cDovL3JlYWRtZS5kcm9uZS5pby91c2FnZS9nZXR0aW5nLXN0YXJ0ZWQtY2xpLykKIyAtIENvcHkgeW91ciB0b2tlbiBmcm9tICBodHRwOi8vZG90dHktY2kuZXBmbC5jaC9hY2NvdW50IChDbGljayBTSE9XIFRPS0VOKQojIC0gKGV4cG9ydCBEUk9ORV9UT0tFTj15b3VyLXRva2VuOyBleHBvcnQgRFJPTkVfU0VSVkVSPWh0dHA6Ly9k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UKICAgIC0gQ0lfVEVTVDogZG90dHktYm9vdHN0cmFwcGVkL3Rlc3QKICAgICAgQ0lfUFVCTElTSDogZmFsc2UK.7RkUdpZM6WNINpEX2-CJuDCD5Gd_EIzMDWe8R9YLO0s
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,5 +1,7 @@
*.DS_Store
*.class
*.tasty
*.hasTasty
*.log
*.swp
*~
Expand Down
3 changes: 2 additions & 1 deletion README.md
@@ -1,9 +1,10 @@
Dotty
=====
[![Build Status](http://dotty-ci.epfl.ch/api/badges/lampepfl/dotty/status.svg)](http://dotty-ci.epfl.ch/lampepfl/dotty)
[![Community Build Status](https://travis-ci.org/lampepfl/dotty-community-build.svg?branch=master)](https://travis-ci.org/lampepfl/dotty-community-build)
[![Join the chat at https://gitter.im/lampepfl/dotty](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/lampepfl/dotty?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Community build: [![Community Build Status](https://travis-ci.org/lampepfl/dotty-community-build.svg?branch=master)](https://travis-ci.org/lampepfl/dotty-community-build)

* [Homepage](http://dotty.epfl.ch)
* [Documentation](http://dotty.epfl.ch/docs)
* [FAQ](http://dotty.epfl.ch/#why-dotty)
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Expand Up @@ -19,6 +19,7 @@ val `scala-compiler` = Build.`scala-compiler`
val `scala-reflect` = Build.`scala-reflect`
val scalap = Build.scalap
val dist = Build.dist
val `dist-bootstrapped` = Build.`dist-bootstrapped`

val `sbt-dotty` = Build.`sbt-dotty`
val `vscode-dotty` = Build.`vscode-dotty`
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Expand Up @@ -206,16 +206,16 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
val dataAttr = new CustomAttr(nme.TASTYATTR.mangledString, binary)
val store = if (mirrorC ne null) mirrorC else plainC
store.visitAttribute(dataAttr)
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
if (ctx.settings.emitTasty.value) {
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)

try outstream.write(binary)
finally outstream.close()
} else if (!outTastyFile.isVirtual) {
} else {
// Create an empty file to signal that a tasty section exist in the corresponding .class
// This is much cheaper and simpler to check than doing classfile parsing
outTastyFile.create()
getFileForClassfile(outF, store.name, ".hasTasty")
}
}

Expand Down
104 changes: 14 additions & 90 deletions compiler/src/dotty/tools/backend/jvm/LabelDefs.scala
Expand Up @@ -75,8 +75,11 @@ import StdNames.nme
* Unreachable jumps will be eliminated by local dead code analysis.
* After JVM is smart enough to remove next-line jumps
*
* Note that Label DefDefs can be only nested in Block, otherwise no one would
* be able to call them Other DefDefs are eliminated
* Note that his phase Ychecking this phase required softening scoping rules
* as it intentionally allowed to break scoping rules inside methods for labels.
* This is modified by setting `labelsReordered` flag in Phases.
*
* @author Dmitry Petrashko
*/
class LabelDefs extends MiniPhaseTransform {
def phaseName: String = "labelDef"
Expand All @@ -90,76 +93,24 @@ class LabelDefs extends MiniPhaseTransform {
else {
collectLabelDefs.clear
val newRhs = collectLabelDefs.transform(tree.rhs)
val labelCalls = collectLabelDefs.labelCalls
var entryPoints = collectLabelDefs.parentLabelCalls
var labelDefs = collectLabelDefs.labelDefs
var callCounts = collectLabelDefs.callCounts

// make sure that for every label there's a single location it should return and single entry point
// if theres already a location that it returns to that's a failure
val disallowed = new mutable.HashMap[Symbol, Tree]()
queue.sizeHint(labelCalls.size + entryPoints.size)

def putLabelDefsNearCallees = new TreeMap() {

override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = {
tree match {
case t: Apply if (entryPoints.contains(t)) =>
entryPoints = entryPoints - t
labelLevel = labelLevel + 1
val r = Block(moveLabels(t), t)
labelLevel = labelLevel - 1
if (labelLevel == 0) beingAppended.clear()
r
case _ => if (entryPoints.nonEmpty && labelDefs.nonEmpty) super.transform(tree) else tree
}
case t: Apply if labelDefs.contains(t.symbol) =>
val labelDef = labelDefs(t.symbol)
labelDefs -= t.symbol

}
}
val labelDef2 = transform(labelDef)
Block(labelDef2:: Nil, t)

def moveLabels(entryPoint: Apply): List[Tree] = {
val entrySym = entryPoint.symbol
if ((entrySym is Flags.Label) && labelDefs.contains(entrySym)) {
val visitedNow = new mutable.HashMap[Symbol, Tree]()
val treesToAppend = new ArrayBuffer[Tree]() // order matters. parents should go first
treesToAppend += labelDefs(entrySym)
queue.clear()

var visited = 0
queue += entryPoint
while (visited < queue.size) {
val owningLabelDefSym = queue(visited).symbol
for (call <- labelCalls(owningLabelDefSym)) {
val callSym = call.symbol
if (!beingAppended.contains(callSym)) {
if (disallowed.contains(callSym)) {
val oldCall = disallowed(callSym)
ctx.error(s"Multiple return locations for Label $oldCall and $call", callSym.pos)
} else {
if ((!visitedNow.contains(callSym)) && labelDefs.contains(callSym)) {
val defTree = labelDefs(callSym)
visitedNow.put(callSym, defTree)
val callCount = callCounts(callSym)
if (callCount > 1) {
if (!treesToAppend.contains(defTree)) {
treesToAppend += defTree
queue += call

}
} else if (entryPoint.symbol ne callSym) entryPoints += call
}
}
}
}

visited += 1
case _ => if (labelDefs.nonEmpty) super.transform(tree) else tree
}
beingAppended ++= treesToAppend.map(_.symbol)
treesToAppend.toList.map(putLabelDefsNearCallees.transform)
} else Nil
}
}


val res = cpy.DefDef(tree)(rhs = putLabelDefsNearCallees.transform(newRhs))

res
Expand All @@ -168,22 +119,11 @@ class LabelDefs extends MiniPhaseTransform {

object collectLabelDefs extends TreeMap() {

// label calls from this DefDef
var parentLabelCalls: mutable.Set[Tree] = new mutable.HashSet[Tree]()
var callCounts: mutable.Map[Symbol, Int] = new mutable.HashMap[Symbol, Int]().withDefaultValue(0)

def shouldMoveLabel = true

// labelSymbol -> Defining tree
val labelDefs = new mutable.HashMap[Symbol, Tree]()
// owner -> all calls by this owner
val labelCalls = new mutable.HashMap[Symbol, mutable.Set[Tree]]()
var owner: Symbol = null

def clear = {
parentLabelCalls.clear()
labelDefs.clear()
labelCalls.clear()
}

override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
Expand All @@ -196,30 +136,14 @@ class LabelDefs extends MiniPhaseTransform {
}
case t: DefDef =>
assert(t.symbol is Flags.Label)

val st = parentLabelCalls
parentLabelCalls = new mutable.HashSet[Tree]()
val symt = owner
owner = t.symbol

val r = super.transform(tree)

owner = symt
labelCalls(r.symbol) = parentLabelCalls
parentLabelCalls = st

if (shouldMoveLabel) {
labelDefs(r.symbol) = r
EmptyTree
} else r
labelDefs(r.symbol) = r
EmptyTree
case t: Apply if t.symbol is Flags.Label =>
val sym = t.symbol
parentLabelCalls = parentLabelCalls + t
if (owner != sym) callCounts(sym) = callCounts(sym) + 1
super.transform(tree)
case _ =>
super.transform(tree)

}
}
}
11 changes: 8 additions & 3 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Expand Up @@ -18,6 +18,7 @@ import core.DenotTransformers.DenotTransformer
import core.Denotations.SingleDenotation

import dotty.tools.backend.jvm.{LabelDefs, GenBCode, CollectSuperCalls}
import dotty.tools.dotc.transform.linker.Simplify

/** The central class of the dotc compiler. The job of a compiler is to create
* runs, which process given `phases` in a given `rootContext`.
Expand Down Expand Up @@ -80,7 +81,9 @@ class Compiler {
new ElimByName, // Expand by-name parameter references
new AugmentScala2Traits, // Expand traits defined in Scala 2.11 to simulate old-style rewritings
new ResolveSuper, // Implement super accessors and add forwarders to trait methods
new Simplify, // Perform local optimizations, simplified versions of what linker does.
new PrimitiveForwarders, // Add forwarders to trait methods that have a mismatch between generic and primitives
new FunctionXXLForwarders, // Add forwarders for FunctionXXL apply method
new ArrayConstructors), // Intercept creation of (non-generic) arrays and intrinsify.
List(new Erasure), // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
List(new ElimErasedValueType, // Expand erased value types to their underlying implementation types
Expand All @@ -92,17 +95,19 @@ class Compiler {
new NonLocalReturns, // Expand non-local returns
new CapturedVars, // Represent vars captured by closures as heap objects
new Constructors, // Collect initialization code in primary constructors
// Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
// Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
new FunctionalInterfaces, // Rewrites closures to implement @specialized types of Functions.
new GetClass, // Rewrites getClass calls on primitive types.
new CallGraphChecks,
new DeadCodeElimination), // Replaces dead code by a `throw new DeadCodeEliminated`
new DeadCodeElimination, // Replaces dead code by a `throw new DeadCodeEliminated`
new Simplify), // Perform local optimizations, simplified versions of what linker does.
List(new LambdaLift, // Lifts out nested functions to class scope, storing free variables in environments
// Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
new ElimStaticThis, // Replace `this` references to static objects by global identifiers
new Flatten, // Lift all inner classes to package scope
new RestoreScopes), // Repair scopes rendered invalid by moving definitions in prior phases of the group
List(new MoveStatics, // Move static methods to companion classes
List(new TransformWildcards, // Replace wildcards with default values
new MoveStatics, // Move static methods to companion classes
new ExpandPrivate, // Widen private definitions accessed from nested classes
new SelectStatic, // get rid of selects that would be compiled into GetStatic
new CollectEntryPoints, // Find classes with main methods
Expand Down

0 comments on commit 0fff181

Please sign in to comment.