Skip to content

Commit dfd800d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dotr-classpath
2 parents 87db7f2 + b95e71a commit dfd800d

File tree

195 files changed

+4212
-3261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+4212
-3261
lines changed

.drone.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# We override the default clone step to workaround a bug with GitHub (see #3415)
2+
clone:
3+
clone:
4+
image: plugins/git
5+
commands:
6+
- sleep 5s
7+
- git init
8+
- git remote add origin $DRONE_REMOTE_URL
9+
- git fetch --no-tags origin $DRONE_COMMIT_REF
10+
- if [ $DRONE_BUILD_EVENT = "push" ]; then git reset --hard -q $DRONE_COMMIT_SHA; else git checkout -qf FETCH_HEAD; fi
11+
- git submodule update --init --recursive
12+
113
pipeline:
214
# TESTS:
315
# We run tests in parallel. Tests run in a copy of the working directory to avoid conflict
@@ -13,16 +25,16 @@ pipeline:
1325
image: lampepfl/dotty:2017-10-20
1426
commands:
1527
- cp -R . /tmp/1/ && cd /tmp/1/
16-
- ./project/scripts/sbt testAll
17-
- ./project/scripts/sbt ";dotty-bench/jmh:run 1 1 tests/run/arrays.scala"
28+
- ./project/scripts/sbt ";compile ;testAll"
29+
- ./project/scripts/sbtTests
1830

1931
test_bootstrapped:
2032
group: test
2133
image: lampepfl/dotty:2017-10-20
2234
commands:
2335
- cp -R . /tmp/2/ && cd /tmp/2/
24-
- ./project/scripts/sbt dotty-bootstrapped/testAll
25-
- ./project/scripts/sbt ";dotty-bench-bootstrapped/jmh:run 1 1 tests/run/arrays.scala"
36+
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/testAll"
37+
- ./project/scripts/sbtBootstrappedTests
2638

2739
test_optimised:
2840
group: test

CONTRIBUTING renamed to CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This is the process for committing code to the Scala project. There are of cours
99
1. Make sure you have signed the [Scala CLA](http://typesafe.com/contribute/cla/scala), if not, sign it.
1010
2. Before starting to work on a feature or a fix, it's good practice to ensure that:
1111
1. There is a ticket for your work in the project's [issue tracker](https://github.com/lampepfl/dotty/issues);
12-
2. If not, create it first (perhaps given a thumbs up from the dotty-internals mailing list first);
1312
2. The ticket has been discussed and prioritized by the team.
1413
3. You should always perform your work in its own Git branch. The branch should be given a descriptive name that explains its intent. Some teams also like adding the ticket number and/or the [GitHub](http://github.com) user ID to the branch name, these details is up to each of the individual teams. (See below for more details on branch naming.)
1514
4. When the feature or fix is completed you should open a [Pull Request](https://help.github.com/articles/using-pull-requests) on GitHub.

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Community build: [![Community Build Status](https://travis-ci.org/lampepfl/dotty
77

88
* [Homepage](http://dotty.epfl.ch)
99
* [Documentation](http://dotty.epfl.ch/docs)
10-
* [FAQ](http://dotty.epfl.ch/#why-dotty)
11-
* [Mailing list](https://groups.google.com/forum/#!forum/dotty-internals)
1210

1311
Try it out
1412
==========
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
find collection-strawman/src/main/ -type f \( -name "*.scala" -or -name "*.java" \) -exec echo "dotty-bench-bootstrapped/jmh:run 0 1 10" {} + | sbt
2+
find collection-strawman/collections/src/main/ -type f \( -name "*.scala" -or -name "*.java" \) -exec echo "dotty-bench-bootstrapped/jmh:run 0 1 10" {} + | sbt

bench/scripts/collection-strawman.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
find collection-strawman/src/main/ -type f \( -name "*.scala" -or -name "*.java" \) -exec echo "dotty-bench-bootstrapped/jmh:run" {} + | sbt
2+
find collection-strawman/collections/src/main/ -type f \( -name "*.scala" -or -name "*.java" \) -exec echo "dotty-bench-bootstrapped/jmh:run" {} + | sbt

bot/src/dotty/tools/bot/PullRequestService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ trait PullRequestService {
267267
|> 1. Limit the subject line to 72 characters
268268
|> 1. Capitalize the subject line
269269
|> 1. Do not end the subject line with a period
270-
|> 1. Use the imperative mood in the subject line ("Added" instead of "Add")
270+
|> 1. Use the imperative mood in the subject line ("Add" instead of "Added")
271271
|> 1. Wrap the body at 80 characters
272272
|> 1. Use the body to explain what and why vs. how
273273
|>

collection-strawman

Submodule collection-strawman updated 231 files

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import dotty.tools.dotc.ast.Trees
55
import dotty.tools.dotc
66
import dotty.tools.dotc.backend.jvm.DottyPrimitives
77
import dotty.tools.dotc.core.Flags.FlagSet
8-
import dotty.tools.dotc.transform.Erasure
8+
import dotty.tools.dotc.transform.{Erasure, GenericSignatures}
99
import dotty.tools.dotc.transform.SymUtils._
1010
import java.io.{File => JFile}
1111

@@ -489,10 +489,97 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
489489

490490
def getSingleOutput: Option[AbstractFile] = None // todo: implement
491491

492+
// @M don't generate java generics sigs for (members of) implementation
493+
// classes, as they are monomorphic (TODO: ok?)
494+
private final def needsGenericSignature(sym: Symbol): Boolean = !(
495+
// pp: this condition used to include sym.hasexpandedname, but this leads
496+
// to the total loss of generic information if a private member is
497+
// accessed from a closure: both the field and the accessor were generated
498+
// without it. This is particularly bad because the availability of
499+
// generic information could disappear as a consequence of a seemingly
500+
// unrelated change.
501+
ctx.base.settings.YnoGenericSig.value
502+
|| sym.is(Flags.Artifact)
503+
|| sym.is(Flags.allOf(Flags.Method, Flags.Lifted))
504+
|| sym.is(Flags.Bridge)
505+
)
506+
507+
private def verifySignature(sym: Symbol, sig: String)(implicit ctx: Context): Unit = {
508+
import scala.tools.asm.util.CheckClassAdapter
509+
def wrap(body: => Unit): Boolean =
510+
try { body; true }
511+
catch { case ex: Throwable => println(ex.getMessage); false }
512+
513+
val valid = wrap {
514+
if (sym.is(Flags.Method)) {
515+
CheckClassAdapter.checkMethodSignature(sig)
516+
}
517+
else if (sym.isTerm) {
518+
CheckClassAdapter.checkFieldSignature(sig)
519+
}
520+
else {
521+
CheckClassAdapter.checkClassSignature(sig)
522+
}
523+
}
524+
525+
if(!valid) {
526+
ctx.warning(
527+
i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
528+
|signature: $sig
529+
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
530+
""".trim, sym.pos)
531+
}
532+
}
533+
534+
/**
535+
* Generates the generic signature for `sym` before erasure.
536+
*
537+
* @param sym The symbol for which to generate a signature.
538+
* @param owner The owner of `sym`.
539+
* @return The generic signature of `sym` before erasure, as specified in the Java Virtual
540+
* Machine Specification, §4.3.4, or `null` if `sym` doesn't need a generic signature.
541+
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
542+
*/
543+
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
544+
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
545+
val memberTpe =
546+
if (sym.is(Flags.Method)) sym.denot.info
547+
else owner.denot.thisType.memberInfo(sym)
548+
getGenericSignature(sym, owner, memberTpe).orNull
549+
}
550+
}
492551

493-
def getGenericSignature(sym: Symbol, owner: Symbol): String = null // todo: implement
552+
def getStaticForwarderGenericSignature(sym: Symbol, moduleClass: Symbol): String = {
553+
// scala/bug#3452 Static forwarder generation uses the same erased signature as the method if forwards to.
554+
// By rights, it should use the signature as-seen-from the module class, and add suitable
555+
// primitive and value-class boxing/unboxing.
556+
// But for now, just like we did in mixin, we just avoid writing a wrong generic signature
557+
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.
558+
559+
val memberTpe = ctx.atPhase(ctx.erasurePhase) { implicit ctx => moduleClass.denot.thisType.memberInfo(sym) }
560+
val erasedMemberType = TypeErasure.erasure(memberTpe)
561+
if (erasedMemberType =:= sym.denot.info)
562+
getGenericSignature(sym, moduleClass, memberTpe).orNull
563+
else null
564+
}
565+
566+
private def getGenericSignature(sym: Symbol, owner: Symbol, memberTpe: Type)(implicit ctx: Context): Option[String] =
567+
if (needsGenericSignature(sym)) {
568+
val erasedTypeSym = sym.denot.info.typeSymbol
569+
if (erasedTypeSym.isPrimitiveValueClass) {
570+
None
571+
} else {
572+
val jsOpt = GenericSignatures.javaSig(sym, memberTpe)
573+
if (ctx.settings.XverifySignatures.value) {
574+
jsOpt.foreach(verifySignature(sym, _))
575+
}
576+
577+
jsOpt
578+
}
579+
} else {
580+
None
581+
}
494582

495-
def getStaticForwarderGenericSignature(sym: Symbol, moduleClass: Symbol): String = null // todo: implement
496583

497584

498585
def sourceFileFor(cu: CompilationUnit): String = cu.source.file.name

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dotty.tools.dotc.core.Phases.Phase
77
import dotty.tools.dotc.core.Names.TypeName
88

99
import scala.collection.mutable
10+
import scala.collection.JavaConverters._
1011
import scala.tools.asm.{ClassVisitor, CustomAttr, FieldVisitor, MethodVisitor}
1112
import scala.tools.nsc.backend.jvm._
1213
import dotty.tools.dotc
@@ -26,14 +27,16 @@ import Denotations._
2627
import Phases._
2728
import java.lang.AssertionError
2829
import java.io.{DataOutputStream, File => JFile}
30+
import java.nio.file.{Files, FileSystem, FileSystems, Path => JPath}
31+
32+
import dotty.tools.io.{Directory, File, Jar}
2933

3034
import scala.tools.asm
3135
import scala.tools.asm.tree._
3236
import dotty.tools.dotc.util.{DotClass, Positions}
3337
import tpd._
3438
import StdNames._
35-
36-
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory}
39+
import dotty.tools.io._
3740

3841
class GenBCode extends Phase {
3942
def phaseName: String = "genBCode"
@@ -46,17 +49,35 @@ class GenBCode extends Phase {
4649
superCallsMap.put(sym, old + calls)
4750
}
4851

49-
def outputDir(implicit ctx: Context): AbstractFile =
50-
new PlainDirectory(ctx.settings.outputDir.value)
52+
private[this] var myOutput: AbstractFile = _
53+
54+
protected def outputDir(implicit ctx: Context): AbstractFile = {
55+
if (myOutput eq null) {
56+
val path = Directory(ctx.settings.outputDir.value)
57+
myOutput =
58+
if (path.extension == "jar") JarArchive.create(path)
59+
else new PlainDirectory(path)
60+
}
61+
myOutput
62+
}
5163

5264
def run(implicit ctx: Context): Unit = {
5365
new GenBCodePipeline(entryPoints.toList,
5466
new DottyBackendInterface(outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
5567
entryPoints.clear()
5668
}
69+
70+
override def runOn(units: List[CompilationUnit])(implicit ctx: Context) = {
71+
try super.runOn(units)
72+
finally myOutput match {
73+
case jar: JarArchive =>
74+
jar.close()
75+
case _ =>
76+
}
77+
}
5778
}
5879

59-
class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry{
80+
class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {
6081

6182
var tree: Tree = _
6283

Lines changed: 27 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
11
package dotty.tools.backend.jvm
22

3-
import dotty.tools.dotc.ast.Trees.Thicket
4-
import dotty.tools.dotc.ast.{Trees, tpd}
3+
import dotty.tools.dotc.ast.tpd
54
import dotty.tools.dotc.core.Contexts.Context
6-
import dotty.tools.dotc.core.Types
5+
import dotty.tools.dotc.core.Flags._
6+
import dotty.tools.dotc.core.Symbols._
77
import dotty.tools.dotc.transform.MegaPhase._
8-
import dotty.tools.dotc
9-
import dotty.tools.dotc.backend.jvm.DottyPrimitives
10-
import dotty.tools.dotc.core.Flags.FlagSet
11-
import dotty.tools.dotc.transform.Erasure
12-
import dotty.tools.dotc.transform.SymUtils._
13-
import java.io.{File => JFile}
148

15-
import scala.collection.generic.Clearable
169
import scala.collection.mutable
17-
import scala.collection.mutable.{ListBuffer, ArrayBuffer}
18-
import scala.reflect.ClassTag
19-
import dotty.tools.io.{Directory, PlainDirectory, AbstractFile}
20-
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
21-
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
22-
import dotty.tools.dotc.core._
23-
import Periods._
24-
import SymDenotations._
25-
import Contexts._
26-
import Types._
27-
import Symbols._
28-
import Denotations._
29-
import Phases._
30-
import java.lang.AssertionError
31-
import dotty.tools.dotc.util.Positions.Position
32-
import Decorators._
33-
import tpd._
34-
import Flags._
35-
import StdNames.nme
3610

3711
/**
3812
* Verifies that each Label DefDef has only a single address to jump back and
@@ -82,68 +56,48 @@ import StdNames.nme
8256
* @author Dmitry Petrashko
8357
*/
8458
class LabelDefs extends MiniPhase {
85-
def phaseName: String = "labelDef"
59+
import tpd._
8660

87-
val queue = new ArrayBuffer[Tree]()
88-
val beingAppended = new mutable.HashSet[Symbol]()
89-
var labelLevel = 0
61+
def phaseName: String = "labelDef"
9062

91-
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context): tpd.Tree = {
92-
if (tree.symbol is Flags.Label) tree
63+
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = {
64+
if (tree.symbol is Label) tree
9365
else {
94-
collectLabelDefs.clear
95-
val newRhs = collectLabelDefs.transform(tree.rhs)
96-
var labelDefs = collectLabelDefs.labelDefs
66+
val labelDefs = collectLabelDefs(tree.rhs)
9767

9868
def putLabelDefsNearCallees = new TreeMap() {
99-
100-
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = {
69+
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
10170
tree match {
10271
case t: Apply if labelDefs.contains(t.symbol) =>
10372
val labelDef = labelDefs(t.symbol)
10473
labelDefs -= t.symbol
105-
106-
val labelDef2 = transform(labelDef)
74+
val labelDef2 = cpy.DefDef(labelDef)(rhs = transform(labelDef.rhs))
10775
Block(labelDef2:: Nil, t)
108-
76+
case t: DefDef =>
77+
assert(t.symbol is Label)
78+
EmptyTree
10979
case _ => if (labelDefs.nonEmpty) super.transform(tree) else tree
11080
}
11181
}
11282
}
11383

114-
val res = cpy.DefDef(tree)(rhs = putLabelDefsNearCallees.transform(newRhs))
115-
116-
res
84+
if (labelDefs.isEmpty) tree
85+
else cpy.DefDef(tree)(rhs = putLabelDefsNearCallees.transform(tree.rhs))
11786
}
11887
}
11988

120-
object collectLabelDefs extends TreeMap() {
121-
89+
private def collectLabelDefs(tree: Tree)(implicit ctx: Context): mutable.HashMap[Symbol, DefDef] = {
12290
// labelSymbol -> Defining tree
123-
val labelDefs = new mutable.HashMap[Symbol, Tree]()
124-
125-
def clear = {
126-
labelDefs.clear()
127-
}
128-
129-
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
130-
case t: Template => t
131-
case t: Block =>
132-
val r = super.transform(t)
133-
r match {
134-
case t: Block if t.stats.isEmpty => t.expr
135-
case _ => r
136-
}
137-
case t: DefDef =>
138-
assert(t.symbol is Flags.Label)
139-
val r = super.transform(tree)
140-
labelDefs(r.symbol) = r
141-
EmptyTree
142-
case t: Apply if t.symbol is Flags.Label =>
143-
val sym = t.symbol
144-
super.transform(tree)
145-
case _ =>
146-
super.transform(tree)
147-
}
91+
val labelDefs = new mutable.HashMap[Symbol, DefDef]()
92+
new TreeTraverser {
93+
override def traverse(tree: Tree)(implicit ctx: Context): Unit = tree match {
94+
case t: DefDef =>
95+
assert(t.symbol is Label)
96+
labelDefs(t.symbol) = t
97+
traverseChildren(t)
98+
case _ => traverseChildren(tree)
99+
}
100+
}.traverse(tree)
101+
labelDefs
148102
}
149103
}

0 commit comments

Comments
 (0)