Skip to content

More tests #1006

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 22 commits into from
Dec 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion docs/SyntaxSummary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ grammar.
| `_'
ExprInParens ::= PostfixExpr `:' Type
| Expr
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) => Block
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) `=>' Block
| Expr1
Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?)
| `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?)
Expand Down
5 changes: 3 additions & 2 deletions src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ object desugar {
// implicit wrapper is typechecked in same scope as constructor, so
// we can reuse the constructor parameters; no derived params are needed.
DefDef(name.toTermName, constrTparams, constrVparamss, classTypeRef, creatorExpr)
.withFlags(Synthetic | Implicit) :: Nil
.withFlags(Synthetic | Implicit)
.withPos(cdef.pos) :: Nil


val self1 = {
Expand Down Expand Up @@ -801,7 +802,7 @@ object desugar {
tree match {
case SymbolLit(str) =>
Apply(
Select(ref(defn.SymbolClass.companionModule.termRef), nme.apply),
ref(defn.SymbolClass.companionModule.termRef),
Literal(Constant(str)) :: Nil)
case InterpolatedString(id, strs, elems) =>
Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems)
Expand Down
9 changes: 5 additions & 4 deletions src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
* parameter, the reference will be a repeated argument.
*/
def refOfDef(tree: MemberDef)(implicit ctx: Context) = tree match {
case ValDef(_, PostfixOp(_, nme.raw.STAR), _) =>
Typed(Ident(tree.name), Ident(tpnme.WILDCARD_STAR))
case _ =>
Ident(tree.name)
case ValDef(_, PostfixOp(_, nme.raw.STAR), _) => repeated(Ident(tree.name))
case _ => Ident(tree.name)
}

/** A repeated argument such as `arg: _*` */
def repeated(arg: Tree)(implicit ctx: Context) = Typed(arg, Ident(tpnme.WILDCARD_STAR))

// ------- Decorators -------------------------------------------------

implicit class UntypedTreeDecorator(val self: Tree) extends AnyVal {
Expand Down
9 changes: 9 additions & 0 deletions src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ object Config {
/** Check that certain types cannot be created in erasedTypes phases */
final val checkUnerased = true

/** In `derivedSelect`, rewrite
*
* (S & T)#A --> S#A & T#A
* (S | T)#A --> S#A | T#A
*
* Not sure whether this is useful. Preliminary measurements show a slowdown of about
* 7% for the build when this option is enabled.
*/
final val splitProjections = false

/** Initial size of superId table */
final val InitialSuperIdsSize = 4096
Expand Down
1 change: 1 addition & 0 deletions src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class ScalaSettings extends Settings.SettingGroup {
val Ypatmatdebug = BooleanSetting("-Ypatmat-debug", "Trace pattern matching translation.")
val Yexplainlowlevel = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
val YnoDoubleBindings = BooleanSetting("-Yno-double-bindings", "Assert no namedtype is bound twice (should be enabled only if program is error-free).")
val YshowVarBounds = BooleanSetting("-YshowVarBounds", "Print type variables with their bounds")

val optimise = BooleanSetting("-optimise", "Generates faster bytecode by applying optimisations to the program") withAbbreviation "-optimize"

Expand Down
5 changes: 1 addition & 4 deletions src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,7 @@ class Definitions {
}

def isBottomClass(cls: Symbol) = cls == NothingClass || cls == NullClass
def isBottomType(tp: Type) = tp match {
case tp: TypeRef => isBottomClass(tp.symbol)
case _ => false
}
def isBottomType(tp: Type) = tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass)

def isFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.Function)
def isAbstractFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.AbstractFunction)
Expand Down
55 changes: 48 additions & 7 deletions src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,45 @@ object TypeApplications {
if (tparams.isEmpty) args
else args.zipWithConserve(tparams)((arg, tparam) => arg.etaExpandIfHK(tparam.infoOrCompleter))

/** The references `<rt>.this.$hk0, ..., <rt>.this.$hk<n-1>`. */
def argRefs(rt: RefinedType, n: Int)(implicit ctx: Context) =
List.range(0, n).map(i => RefinedThis(rt).select(tpnme.hkArg(i)))

/** Merge `tp1` and `tp2` under a common lambda, combining them with `op`.
* @param tparams1 The type parameters of `tp1`
* @param tparams2 The type parameters of `tp2`
* Produces the type lambda
*
* [v1 X1 B1, ..., vn Xn Bn] -> op(tp1[X1, ..., Xn], tp2[X1, ..., Xn])
*
* where
*
* - variances `vi` are the variances of corresponding type parameters for `tp1`
* or `tp2`, or are 0 of the latter disagree.
* - bounds `Bi` are the intersection of the corresponding type parameter bounds
* of `tp1` and `tp2`.
*/
def hkCombine(tp1: Type, tp2: Type,
tparams1: List[TypeSymbol], tparams2: List[TypeSymbol], op: (Type, Type) => Type)
(implicit ctx: Context): Type = {
val variances = (tparams1, tparams2).zipped.map { (tparam1, tparam2) =>
val v1 = tparam1.variance
val v2 = tparam2.variance
if (v1 == v2) v1 else 0
}
val bounds: List[RefinedType => TypeBounds] =
(tparams1, tparams2).zipped.map { (tparam1, tparam2) =>
val b1: RefinedType => TypeBounds =
tp1.memberInfo(tparam1).bounds.internalizeFrom(tparams1)
val b2: RefinedType => TypeBounds =
tp2.memberInfo(tparam2).bounds.internalizeFrom(tparams2)
(rt: RefinedType) => b1(rt) & b2(rt)
}
val app1: RefinedType => Type = rt => tp1.appliedTo(argRefs(rt, tparams1.length))
val app2: RefinedType => Type = rt => tp2.appliedTo(argRefs(rt, tparams2.length))
val body = (rt: RefinedType) => op(app1(rt), app2(rt))
TypeLambda(variances, bounds, body)
}
}

import TypeApplications._
Expand Down Expand Up @@ -273,6 +310,14 @@ class TypeApplications(val self: Type) extends AnyVal {
false
}

/** Replace references to type parameters with references to hk arguments `this.$hk_i`
* Care is needed not to cause cyclic reference errors, hence `SafeSubstMap`.
*/
private[TypeApplications] def internalizeFrom[T <: Type](tparams: List[Symbol])(implicit ctx: Context): RefinedType => T =
(rt: RefinedType) =>
new ctx.SafeSubstMap(tparams , argRefs(rt, tparams.length))
.apply(self).asInstanceOf[T]

/** Lambda abstract `self` with given type parameters. Examples:
*
* type T[X] = U becomes type T = [X] -> U
Expand Down Expand Up @@ -328,14 +373,10 @@ class TypeApplications(val self: Type) extends AnyVal {
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
}

/** Eta expand the prefix in front of any refinements.
* @param tparamsForBottom Type parameters to use if core is a bottom type
*/
def EtaExpandCore(tparamsForBottom: List[TypeSymbol])(implicit ctx: Context): Type = self.stripTypeVar match {
/** Eta expand the prefix in front of any refinements. */
def EtaExpandCore(implicit ctx: Context): Type = self.stripTypeVar match {
case self: RefinedType =>
self.derivedRefinedType(self.parent.EtaExpandCore(tparamsForBottom), self.refinedName, self.refinedInfo)
case tp: TypeRef if defn.isBottomClass(tp.symbol) =>
self.LambdaAbstract(tparamsForBottom)
self.derivedRefinedType(self.parent.EtaExpandCore, self.refinedName, self.refinedInfo)
case _ =>
self.EtaExpand(self.typeParams)
}
Expand Down
Loading