Skip to content

Commit 42e7488

Browse files
committed
Merge pull request #117 from DarkDimius/tailrec
TailRec phase and tests for it.
2 parents 3750291 + 6ebf6e2 commit 42e7488

31 files changed

+408
-26
lines changed

project/Build.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ object DottyBuild extends Build {
66

77
val TRAVIS_BUILD = "dotty.travis.build"
88

9+
val agentOptions = List(
10+
// "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005",
11+
// "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so"
12+
)
13+
14+
915
val defaults = Defaults.defaultSettings ++ Seq(
1016
// set sources to src/, tests to test/ and resources to resources/
1117
scalaSource in Compile := baseDirectory.value / "src",
@@ -51,12 +57,12 @@ object DottyBuild extends Build {
5157
// System.err.println("BOOTPATH: " + fullpath)
5258

5359
val travis_build = // propagate if this is a travis build
54-
if (sys.props.isDefinedAt(TRAVIS_BUILD))
60+
if (sys.props.isDefinedAt(TRAVIS_BUILD))
5561
List(s"-D$TRAVIS_BUILD=${sys.props(TRAVIS_BUILD)}")
56-
else
62+
else
5763
List()
5864

59-
travis_build ::: fullpath
65+
agentOptions ::: travis_build ::: fullpath
6066
}
6167
)
6268

src/dotty/tools/dotc/Compiler.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class Compiler {
2020
def phases: List[List[Phase]] =
2121
List(
2222
List(new FrontEnd),
23-
List(new LazyValsCreateCompanionObjects, new PatternMatcher), //force separataion between lazyVals and LVCreateCO
24-
List(new LazyValTranformContext().transformer, new Splitter, new TypeTestsCasts, new InterceptedMethods),
23+
List(new LazyValsCreateCompanionObjects, new TailRec), //force separataion between lazyVals and LVCreateCO
24+
List(new PatternMatcher, new LazyValTranformContext().transformer,
25+
new Splitter, new TypeTestsCasts, new InterceptedMethods),
2526
List(new Erasure),
2627
List(new UncurryTreeTransform)
2728
)

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
103103
* where the closure's type is the target type of the expression (FunctionN, unless
104104
* otherwise specified).
105105
*/
106-
def Closure(meth: TermSymbol, rhsFn: List[List[Tree]] => Tree, targetType: Type = NoType)(implicit ctx: Context): Block = {
106+
def Closure(meth: TermSymbol, rhsFn: List[List[Tree]] => Tree, targs: List[Tree] = Nil, targetType: Type = NoType)(implicit ctx: Context): Block = {
107107
val targetTpt = if (targetType.exists) TypeTree(targetType) else EmptyTree
108+
val call =
109+
if (targs.isEmpty) Ident(TermRef(NoPrefix, meth))
110+
else TypeApply(Ident(TermRef(NoPrefix, meth)), targs)
108111
Block(
109112
DefDef(meth, rhsFn) :: Nil,
110-
Closure(Nil, Ident(TermRef(NoPrefix, meth)), targetTpt))
113+
Closure(Nil, call, targetTpt))
111114
}
112115

113116
def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef =

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ class Definitions {
172172

173173
lazy val UnitClass = valueClassSymbol("scala.Unit", BoxedUnitClass, java.lang.Void.TYPE, UnitEnc)
174174
lazy val BooleanClass = valueClassSymbol("scala.Boolean", BoxedBooleanClass, java.lang.Boolean.TYPE, BooleanEnc)
175-
lazy val Boolean_! = BooleanClass.requiredMethod(nme.UNARY_!)
175+
lazy val Boolean_! = BooleanClass.requiredMethod(nme.UNARY_!)
176176
lazy val Boolean_and = BooleanClass.requiredMethod(nme.ZAND)
177+
lazy val Boolean_or = BooleanClass.requiredMethod(nme.ZOR)
177178

178179
lazy val ByteClass = valueClassSymbol("scala.Byte", BoxedByteClass, java.lang.Byte.TYPE, ByteEnc)
179180
lazy val ShortClass = valueClassSymbol("scala.Short", BoxedShortClass, java.lang.Short.TYPE, ShortEnc)
@@ -236,6 +237,7 @@ class Definitions {
236237
lazy val AnnotationClass = ctx.requiredClass("scala.annotation.Annotation")
237238
lazy val ClassfileAnnotationClass = ctx.requiredClass("scala.annotation.ClassfileAnnotation")
238239
lazy val StaticAnnotationClass = ctx.requiredClass("scala.annotation.StaticAnnotation")
240+
lazy val TailrecAnnotationClass = ctx.requiredClass("scala.annotation.tailrec")
239241

240242
// Annotation classes
241243
lazy val AliasAnnot = ctx.requiredClass("dotty.annotation.internal.Alias")

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ object Flags {
470470
/** Labeled `private` or `protected[local]` */
471471
final val PrivateOrLocal = Private | Local
472472

473+
/** Either a module or a final class */
474+
final val ModuleOrFinal = ModuleClass | Final
475+
476+
/** Either mutable or lazy */
477+
final val MutableOrLazy = Mutable | Lazy
478+
479+
/** Labeled `private` or `final` */
480+
final val PrivateOrFinal = Private | Final
481+
473482
/** A type parameter with synthesized name */
474483
final val ExpandedTypeParam = allOf(ExpandedName, TypeParam)
475484

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ object SymDenotations {
586586
final def enclosingClass(implicit ctx: Context): Symbol =
587587
if (isClass || !exists) symbol else owner.enclosingClass
588588

589+
final def isEffectivelyFinal(implicit ctx: Context): Boolean = {
590+
(this.flags is Flags.PrivateOrFinal) || (!this.owner.isClass) ||
591+
((this.owner.flags is (Flags.ModuleOrFinal)) && (!this.flags.is(Flags.MutableOrLazy))) ||
592+
(this.owner.isAnonymousClass)
593+
}
594+
589595
/** The class containing this denotation which has the given effective name.
590596
*/
591597
final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = {

src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ trait Symbols { this: Context =>
245245
for (name <- names) {
246246
val tparam = newNakedSymbol[TypeName](NoCoord)
247247
tparamBuf += tparam
248-
trefBuf += TypeRef(owner.thisType, name).withSym(tparam, Signature.NotAMethod)
248+
trefBuf += TypeRef.withSymAndName(owner.thisType, tparam, name)
249249
}
250250
val tparams = tparamBuf.toList
251251
val bounds = boundsFn(trefBuf.toList)
@@ -319,7 +319,7 @@ object Symbols {
319319
type ThisName <: Name
320320

321321
private[this] var _id: Int = nextId
322-
//assert(_id != 12325)
322+
//assert(_id != 5859)
323323

324324
/** The unique id of this symbol */
325325
def id = _id

0 commit comments

Comments
 (0)