Skip to content

Drop AndTypeTree and OrTypeTree #5935

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 14 commits into from
Feb 18, 2019
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ object desugar {
def collect(tree: Tree): Unit = tree match {
case Bind(nme.WILDCARD, tree1) =>
collect(tree1)
case tree @ Bind(_, Typed(tree1, tpt)) if !mayBeTypePat(tpt) =>
case tree @ Bind(_, Typed(tree1, tpt)) =>
add(tree, tpt)
collect(tree1)
case tree @ Bind(_, tree1) =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ object DesugarEnums {
parentTypes.head match {
case parent: RefTree if parent.name == enumClass.name =>
// need a widen method to compute correct type parameters for enum base class
val widenParamType = (appliedEnumRef /: parentTypes.tail)(AndTypeTree)
val widenParamType = (appliedEnumRef /: parentTypes.tail)(makeAndType)
val widenParam = makeSyntheticParameter(tpt = widenParamType)
val widenDef = DefDef(
name = s"${cdef.name}$$to$$${enumClass.name}".toTermName,
Expand All @@ -164,7 +164,7 @@ object DesugarEnums {
rhs = Ident(widenParam.name))
(TypeTree(), widenDef :: Nil)
case _ =>
(parentTypes.reduceLeft(AndTypeTree), Nil)
(parentTypes.reduceLeft(makeAndType), Nil)
}
}

Expand Down
11 changes: 0 additions & 11 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,6 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
/** Is name a left-associative operator? */
def isLeftAssoc(operator: Name): Boolean = !operator.isEmpty && (operator.toSimpleName.last != ':')

/** can this type be a type pattern? */
def mayBeTypePat(tree: Tree): Boolean = unsplice(tree) match {
case AndTypeTree(tpt1, tpt2) => mayBeTypePat(tpt1) || mayBeTypePat(tpt2)
case OrTypeTree(tpt1, tpt2) => mayBeTypePat(tpt1) || mayBeTypePat(tpt2)
case RefinedTypeTree(tpt, refinements) => mayBeTypePat(tpt) || refinements.exists(_.isInstanceOf[Bind])
case AppliedTypeTree(tpt, args) => mayBeTypePat(tpt) || args.exists(_.isInstanceOf[Bind])
case Select(tpt, _) => mayBeTypePat(tpt)
case Annotated(tpt, _) => mayBeTypePat(tpt)
case _ => false
}

/** Is this argument node of the form <expr> : _*, or is it a reference to
* such an argument ? The latter case can happen when an argument is lifted.
*/
Expand Down
30 changes: 0 additions & 30 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -626,18 +626,6 @@ object Trees {
type ThisTree[-T >: Untyped] = SingletonTypeTree[T]
}

/** left & right */
case class AndTypeTree[-T >: Untyped] private[ast] (left: Tree[T], right: Tree[T])(implicit @constructorOnly src: SourceFile)
extends TypTree[T] {
type ThisTree[-T >: Untyped] = AndTypeTree[T]
}

/** left | right */
case class OrTypeTree[-T >: Untyped] private[ast] (left: Tree[T], right: Tree[T])(implicit @constructorOnly src: SourceFile)
extends TypTree[T] {
type ThisTree[-T >: Untyped] = OrTypeTree[T]
}

/** tpt { refinements } */
case class RefinedTypeTree[-T >: Untyped] private[ast] (tpt: Tree[T], refinements: List[Tree[T]])(implicit @constructorOnly src: SourceFile)
extends ProxyTree[T] with TypTree[T] {
Expand Down Expand Up @@ -934,8 +922,6 @@ object Trees {
type Inlined = Trees.Inlined[T]
type TypeTree = Trees.TypeTree[T]
type SingletonTypeTree = Trees.SingletonTypeTree[T]
type AndTypeTree = Trees.AndTypeTree[T]
type OrTypeTree = Trees.OrTypeTree[T]
type RefinedTypeTree = Trees.RefinedTypeTree[T]
type AppliedTypeTree = Trees.AppliedTypeTree[T]
type LambdaTypeTree = Trees.LambdaTypeTree[T]
Expand Down Expand Up @@ -1102,14 +1088,6 @@ object Trees {
case tree: SingletonTypeTree if (ref eq tree.ref) => tree
case _ => finalize(tree, untpd.SingletonTypeTree(ref)(sourceFile(tree)))
}
def AndTypeTree(tree: Tree)(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = tree match {
case tree: AndTypeTree if (left eq tree.left) && (right eq tree.right) => tree
case _ => finalize(tree, untpd.AndTypeTree(left, right)(sourceFile(tree)))
}
def OrTypeTree(tree: Tree)(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = tree match {
case tree: OrTypeTree if (left eq tree.left) && (right eq tree.right) => tree
case _ => finalize(tree, untpd.OrTypeTree(left, right)(sourceFile(tree)))
}
def RefinedTypeTree(tree: Tree)(tpt: Tree, refinements: List[Tree])(implicit ctx: Context): RefinedTypeTree = tree match {
case tree: RefinedTypeTree if (tpt eq tree.tpt) && (refinements eq tree.refinements) => tree
case _ => finalize(tree, untpd.RefinedTypeTree(tpt, refinements)(sourceFile(tree)))
Expand Down Expand Up @@ -1271,10 +1249,6 @@ object Trees {
tree
case SingletonTypeTree(ref) =>
cpy.SingletonTypeTree(tree)(transform(ref))
case AndTypeTree(left, right) =>
cpy.AndTypeTree(tree)(transform(left), transform(right))
case OrTypeTree(left, right) =>
cpy.OrTypeTree(tree)(transform(left), transform(right))
case RefinedTypeTree(tpt, refinements) =>
cpy.RefinedTypeTree(tree)(transform(tpt), transformSub(refinements))
case AppliedTypeTree(tpt, args) =>
Expand Down Expand Up @@ -1399,10 +1373,6 @@ object Trees {
x
case SingletonTypeTree(ref) =>
this(x, ref)
case AndTypeTree(left, right) =>
this(this(x, left), right)
case OrTypeTree(left, right) =>
this(this(x, left), right)
case RefinedTypeTree(tpt, refinements) =>
this(this(x, tpt), refinements)
case AppliedTypeTree(tpt, args) =>
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree =
ta.assignType(untpd.SingletonTypeTree(ref), ref)

def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree =
ta.assignType(untpd.AndTypeTree(left, right), left, right)

def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree =
ta.assignType(untpd.OrTypeTree(left, right), left, right)

def RefinedTypeTree(parent: Tree, refinements: List[Tree], refineCls: ClassSymbol)(implicit ctx: Context): Tree =
ta.assignType(untpd.RefinedTypeTree(parent, refinements), parent, refinements, refineCls)

Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def Inlined(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(implicit src: SourceFile): Inlined = new Inlined(call, bindings, expansion)
def TypeTree()(implicit src: SourceFile): TypeTree = new TypeTree()
def SingletonTypeTree(ref: Tree)(implicit src: SourceFile): SingletonTypeTree = new SingletonTypeTree(ref)
def AndTypeTree(left: Tree, right: Tree)(implicit src: SourceFile): AndTypeTree = new AndTypeTree(left, right)
def OrTypeTree(left: Tree, right: Tree)(implicit src: SourceFile): OrTypeTree = new OrTypeTree(left, right)
def RefinedTypeTree(tpt: Tree, refinements: List[Tree])(implicit src: SourceFile): RefinedTypeTree = new RefinedTypeTree(tpt, refinements)
def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit src: SourceFile): AppliedTypeTree = new AppliedTypeTree(tpt, args)
def LambdaTypeTree(tparams: List[TypeDef], body: Tree)(implicit src: SourceFile): LambdaTypeTree = new LambdaTypeTree(tparams, body)
Expand Down Expand Up @@ -403,6 +401,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
case _ => Tuple(ts)
}

def makeAndType(left: Tree, right: Tree)(implicit ctx: Context): AppliedTypeTree =
AppliedTypeTree(ref(defn.andType.typeRef), left :: right :: Nil)

def makeParameter(pname: TermName, tpe: Tree, mods: Modifiers = EmptyModifiers)(implicit ctx: Context): ValDef =
ValDef(pname, tpe, EmptyTree).withMods(mods | Param)

Expand Down
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ class Definitions {
sym
}

private def enterBinaryAlias(name: TypeName, op: (Type, Type) => Type): TypeSymbol =
enterAliasType(name,
HKTypeLambda(TypeBounds.empty :: TypeBounds.empty :: Nil)(
tl => op(tl.paramRefs(0), tl.paramRefs(1))))

private def enterPolyMethod(cls: ClassSymbol, name: TermName, typeParamCount: Int,
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags,
useCompleter: Boolean = false) = {
Expand Down Expand Up @@ -322,6 +327,9 @@ class Definitions {
}
def AnyKindType: TypeRef = AnyKindClass.typeRef

lazy val andType: TypeSymbol = enterBinaryAlias(tpnme.AND, AndType(_, _))
lazy val orType: TypeSymbol = enterBinaryAlias(tpnme.OR, OrType(_, _))

/** Marker method to indicate an argument to a call-by-name parameter.
* Created by byNameClosures and elimByName, eliminated by Erasure,
*/
Expand Down Expand Up @@ -1326,6 +1334,8 @@ class Definitions {
AnyClass,
AnyRefAlias,
AnyKindClass,
andType,
orType,
RepeatedParamClass,
ByNameParamClass2x,
AnyValClass,
Expand Down
10 changes: 1 addition & 9 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ Standard-Section: "ASTs" TopLevelStat*
LAMBDAtpt Length TypeParam* body_Term
TYPEBOUNDStpt Length low_Term high_Term?
ANNOTATEDtpt Length underlying_Term fullAnnotation_Term
ANDtpt Length left_Term right_Term
ORtpt Length left_Term right_Term
MATCHtpt Length bound_Term? sel_Term CaseDef*
BYNAMEtpt underlying_Term
SHAREDterm term_ASTRef
Expand Down Expand Up @@ -246,7 +244,7 @@ Standard Section: "Comments" Comment*
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 12
val MajorVersion: Int = 13
val MinorVersion: Int = 0

/** Tags used to serialize names */
Expand Down Expand Up @@ -419,9 +417,7 @@ object TastyFormat {
final val TYPEBOUNDS = 163
final val TYPEBOUNDStpt = 164
final val ANDtype = 165
final val ANDtpt = 166
final val ORtype = 167
final val ORtpt = 168
final val POLYtype = 169
final val TYPELAMBDAtype = 170
final val LAMBDAtpt = 171
Expand Down Expand Up @@ -517,8 +513,6 @@ object TastyFormat {
| LAMBDAtpt
| TYPEBOUNDStpt
| ANNOTATEDtpt
| ANDtpt
| ORtpt
| BYNAMEtpt
| MATCHtpt
| BIND => true
Expand Down Expand Up @@ -647,9 +641,7 @@ object TastyFormat {
case TYPEBOUNDStpt => "TYPEBOUNDStpt"
case TYPEALIAS => "TYPEALIAS"
case ANDtype => "ANDtype"
case ANDtpt => "ANDtpt"
case ORtype => "ORtype"
case ORtpt => "ORtpt"
case BYNAMEtype => "BYNAMEtype"
case BYNAMEtpt => "BYNAMEtpt"
case POLYtype => "POLYtype"
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,6 @@ class TreePickler(pickler: TastyPickler) {
case AppliedTypeTree(tycon, args) =>
writeByte(APPLIEDtpt)
withLength { pickleTree(tycon); args.foreach(pickleTree) }
case AndTypeTree(tp1, tp2) =>
writeByte(ANDtpt)
withLength { pickleTree(tp1); pickleTree(tp2) }
case OrTypeTree(tp1, tp2) =>
writeByte(ORtpt)
withLength { pickleTree(tp1); pickleTree(tp2) }
case MatchTypeTree(bound, selector, cases) =>
writeByte(MATCHtpt)
withLength {
Expand Down
13 changes: 5 additions & 8 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1175,14 +1175,11 @@ class TreeUnpickler(reader: TastyReader,
// types. This came up in #137 of collection strawman.
val tycon = readTpt()
val args = until(end)(readTpt())
untpd.AppliedTypeTree(tycon, args).withType(tycon.tpe.safeAppliedTo(args.tpes))
case ANDtpt =>
val tpt1 = readTpt()
val tpt2 = readTpt()
// FIXME: We need to do this instead of "AndType(tpt1, tpt2)" to avoid self-type cyclic reference in tasty_tools
untpd.AndTypeTree(tpt1, tpt2).withType(AndType(tpt1.tpe, tpt2.tpe))
case ORtpt =>
OrTypeTree(readTpt(), readTpt())
val ownType =
if (tycon.symbol == defn.andType) AndType(args(0).tpe, args(1).tpe)
else if (tycon.symbol == defn.orType) OrType(args(0).tpe, args(1).tpe)
else tycon.tpe.safeAppliedTo(args.tpes)
untpd.AppliedTypeTree(tycon, args).withType(ownType)
case ANNOTATEDtpt =>
Annotated(readTpt(), readTerm())
case LAMBDAtpt =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ object JavaParsers {
}
val ts = buf.toList
if (ts.tail.isEmpty) ts.head
else ts.reduce(AndTypeTree(_,_))
else ts.reduce(makeAndType(_,_))
}

def formalParams(): List[ValDef] = {
Expand Down
Loading