Skip to content

Harmonize PolyType and TypeLambda #1560

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 10 commits into from
Oct 12, 2016
2 changes: 1 addition & 1 deletion docs/syntax-summary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ grammar.
ClassQualifier ::= `[' id `]'

Type ::= FunArgTypes `=>' Type Function(ts, t)
| HkTypeParamClause `->' Type TypeLambda(ps, t)
| HkTypeParamClause `=>' Type TypeLambda(ps, t)
| InfixType
FunArgTypes ::= InfixType
| `(' [ FunArgType {`,' FunArgType } ] `)'
Expand Down
2 changes: 1 addition & 1 deletion dottydoc/src/dotty/tools/dottydoc/model/factories.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object factories {
}

def expandTpe(t: Type, params: List[Reference] = Nil): Reference = t match {
case tl: TypeLambda =>
case tl: PolyType =>
//FIXME: should be handled correctly
// example, in `Option`:
//
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/backend/jvm/CollectEntryPoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object CollectEntryPoints{
else (possibles exists(x=> isJavaMainMethod(x.symbol))) || {
possibles exists { m =>
toDenot(m.symbol).info match {
case t:PolyType =>
case t: PolyType =>
fail("main methods cannot be generic.")
case t@MethodType(paramNames, paramTypes) =>
if (t.resultType :: paramTypes exists (_.typeSymbol.isAbstractType))
Expand Down
18 changes: 9 additions & 9 deletions src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ object Trees {
}

/** [typeparams] -> tpt */
case class TypeLambdaTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
case class PolyTypeTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
extends TypTree[T] {
type ThisTree[-T >: Untyped] = TypeLambdaTree[T]
type ThisTree[-T >: Untyped] = PolyTypeTree[T]
}

/** => T */
Expand Down Expand Up @@ -820,7 +820,7 @@ object Trees {
type OrTypeTree = Trees.OrTypeTree[T]
type RefinedTypeTree = Trees.RefinedTypeTree[T]
type AppliedTypeTree = Trees.AppliedTypeTree[T]
type TypeLambdaTree = Trees.TypeLambdaTree[T]
type PolyTypeTree = Trees.PolyTypeTree[T]
type ByNameTypeTree = Trees.ByNameTypeTree[T]
type TypeBoundsTree = Trees.TypeBoundsTree[T]
type Bind = Trees.Bind[T]
Expand Down Expand Up @@ -984,9 +984,9 @@ object Trees {
case tree: AppliedTypeTree if (tpt eq tree.tpt) && (args eq tree.args) => tree
case _ => finalize(tree, untpd.AppliedTypeTree(tpt, args))
}
def TypeLambdaTree(tree: Tree)(tparams: List[TypeDef], body: Tree): TypeLambdaTree = tree match {
case tree: TypeLambdaTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
case _ => finalize(tree, untpd.TypeLambdaTree(tparams, body))
def PolyTypeTree(tree: Tree)(tparams: List[TypeDef], body: Tree): PolyTypeTree = tree match {
case tree: PolyTypeTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
case _ => finalize(tree, untpd.PolyTypeTree(tparams, body))
}
def ByNameTypeTree(tree: Tree)(result: Tree): ByNameTypeTree = tree match {
case tree: ByNameTypeTree if result eq tree.result => tree
Expand Down Expand Up @@ -1118,8 +1118,8 @@ object Trees {
cpy.RefinedTypeTree(tree)(transform(tpt), transformSub(refinements))
case AppliedTypeTree(tpt, args) =>
cpy.AppliedTypeTree(tree)(transform(tpt), transform(args))
case TypeLambdaTree(tparams, body) =>
cpy.TypeLambdaTree(tree)(transformSub(tparams), transform(body))
case PolyTypeTree(tparams, body) =>
cpy.PolyTypeTree(tree)(transformSub(tparams), transform(body))
case ByNameTypeTree(result) =>
cpy.ByNameTypeTree(tree)(transform(result))
case TypeBoundsTree(lo, hi) =>
Expand Down Expand Up @@ -1222,7 +1222,7 @@ object Trees {
this(this(x, tpt), refinements)
case AppliedTypeTree(tpt, args) =>
this(this(x, tpt), args)
case TypeLambdaTree(tparams, body) =>
case PolyTypeTree(tparams, body) =>
implicit val ctx: Context = localCtx
this(this(x, tparams), body)
case ByNameTypeTree(result) =>
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def OrTypeTree(left: Tree, right: Tree): OrTypeTree = new OrTypeTree(left, right)
def RefinedTypeTree(tpt: Tree, refinements: List[Tree]): RefinedTypeTree = new RefinedTypeTree(tpt, refinements)
def AppliedTypeTree(tpt: Tree, args: List[Tree]): AppliedTypeTree = new AppliedTypeTree(tpt, args)
def TypeLambdaTree(tparams: List[TypeDef], body: Tree): TypeLambdaTree = new TypeLambdaTree(tparams, body)
def PolyTypeTree(tparams: List[TypeDef], body: Tree): PolyTypeTree = new PolyTypeTree(tparams, body)
def ByNameTypeTree(result: Tree): ByNameTypeTree = new ByNameTypeTree(result)
def TypeBoundsTree(lo: Tree, hi: Tree): TypeBoundsTree = new TypeBoundsTree(lo, hi)
def Bind(name: Name, body: Tree): Bind = new Bind(name, body)
Expand Down
10 changes: 5 additions & 5 deletions src/dotty/tools/dotc/core/Constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class Constraint extends Showable {
type This <: Constraint

/** Does the constraint's domain contain the type parameters of `pt`? */
def contains(pt: GenericType): Boolean
def contains(pt: PolyType): Boolean

/** Does the constraint's domain contain the type parameter `param`? */
def contains(param: PolyParam): Boolean
Expand Down Expand Up @@ -79,7 +79,7 @@ abstract class Constraint extends Showable {
* satisfiability but will solved to give instances of
* type variables.
*/
def add(poly: GenericType, tvars: List[TypeVar])(implicit ctx: Context): This
def add(poly: PolyType, tvars: List[TypeVar])(implicit ctx: Context): This

/** A new constraint which is derived from this constraint by updating
* the entry for parameter `param` to `tp`.
Expand Down Expand Up @@ -121,13 +121,13 @@ abstract class Constraint extends Showable {
* all type parameters of the entry are associated with type variables
* which have their `inst` fields set.
*/
def isRemovable(pt: GenericType): Boolean
def isRemovable(pt: PolyType): Boolean

/** A new constraint with all entries coming from `pt` removed. */
def remove(pt: GenericType)(implicit ctx: Context): This
def remove(pt: PolyType)(implicit ctx: Context): This

/** The polytypes constrained by this constraint */
def domainPolys: List[GenericType]
def domainPolys: List[PolyType]

/** The polytype parameters constrained by this constraint */
def domainParams: List[PolyParam]
Expand Down
10 changes: 5 additions & 5 deletions src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ trait ConstraintHandling {
try op finally alwaysFluid = saved
}

/** We are currently comparing lambdas. Used as a flag for
/** We are currently comparing polytypes. Used as a flag for
* optimization: when `false`, no need to do an expensive `pruneLambdaParams`
*/
protected var comparingLambdas = false
protected var comparedPolyTypes: Set[PolyType] = Set.empty

private def addOneBound(param: PolyParam, bound: Type, isUpper: Boolean): Boolean =
!constraint.contains(param) || {
Expand Down Expand Up @@ -316,12 +316,12 @@ trait ConstraintHandling {
* missing.
*/
def pruneLambdaParams(tp: Type) =
if (comparingLambdas && param.binder.isInstanceOf[PolyType]) {
if (comparedPolyTypes.nonEmpty) {
val approx = new ApproximatingTypeMap {
def apply(t: Type): Type = t match {
case t @ PolyParam(tl: TypeLambda, n) =>
case t @ PolyParam(pt: PolyType, n) if comparedPolyTypes contains pt =>
val effectiveVariance = if (fromBelow) -variance else variance
val bounds = tl.paramBounds(n)
val bounds = pt.paramBounds(n)
if (effectiveVariance > 0) bounds.lo
else if (effectiveVariance < 0) bounds.hi
else NoType
Expand Down
6 changes: 3 additions & 3 deletions src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ class Definitions {
}

private def newPolyMethod(cls: ClassSymbol, name: TermName, typeParamCount: Int,
resultTypeFn: GenericType => Type, flags: FlagSet = EmptyFlags) = {
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags) = {
val tparamNames = tpnme.syntheticTypeParamNames(typeParamCount)
val tparamBounds = tparamNames map (_ => TypeBounds.empty)
val ptype = PolyType(tparamNames)(_ => tparamBounds, resultTypeFn)
newMethod(cls, name, ptype, flags)
}

private def newT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: GenericType => Type, flags: FlagSet) =
private def newT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
newPolyMethod(cls, name, 1, resultTypeFn, flags)

private def newT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: GenericType => Type, flags: FlagSet) =
private def newT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
newPolyMethod(cls, name, 1, pt => MethodType(Nil, resultTypeFn(pt)), flags)

private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[TypeRef] = {
Expand Down
Loading