Skip to content

Commit

Permalink
cleanup: no BuiltinType
Browse files Browse the repository at this point in the history
Summary:
- remove the controversial notion of "builtin type" - it doesn't communicate anything and can be considered as an instance of incidental complexity
- it doesn't affect performance

Reviewed By: michalmuskala

Differential Revision: D40177071

fbshipit-source-id: fd2aa767f5c07bcb16d6d493bef597be0982494c
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Oct 11, 2022
1 parent 98204ea commit 98020bb
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TypeTraverse(val listener: TypeListener) {
case bt @ BinaryType =>
listener.enterType(bt)
listener.exitType(bt)
case bt: BuiltinType =>
case bt =>
listener.enterType(bt)
listener.exitType(bt)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ object TypeVars {
case DictMap(kType, vType) => kType :: vType :: Nil
case ListType(ty) => ty :: Nil
case RefinedRecordType(_, fields) => fields.toList.map(_._2)
case _: AtomLitType | AnyFunType | AnyTupleType | NilType | _: VarType | _: RecordType | BinaryType |
_: BuiltinType =>
Nil
case _ => Nil
}

/** For subtyping comparison, make ft1 and ft2 such that their `forall`s quantify over variables with the same
Expand Down Expand Up @@ -134,7 +132,7 @@ object TypeVars {
ShapeMap(props.map(incrInProp(_, toIncr, incr)))
case RefinedRecordType(recType, fields) =>
RefinedRecordType(recType, fields.map(f => f._1 -> r(f._2)))
case _: BuiltinType | _: AtomLitType | NilType | BinaryType | _: RecordType | AnyTupleType | AnyFunType =>
case _ =>
t
}
}
Expand Down
17 changes: 8 additions & 9 deletions eqwalizer/src/main/scala/com/whatsapp/eqwalizer/ast/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ object Types {
case class ReqProp(key: String, tp: Type) extends Prop
case class OptProp(key: String, tp: Type) extends Prop

sealed trait BuiltinType extends Type
case object AnyType extends BuiltinType
case object AtomType extends BuiltinType
case object DynamicType extends BuiltinType
case object NoneType extends BuiltinType
case object PidType extends BuiltinType
case object PortType extends BuiltinType
case object ReferenceType extends BuiltinType
case object NumberType extends BuiltinType
case object AnyType extends Type
case object AtomType extends Type
case object DynamicType extends Type
case object NoneType extends Type
case object PidType extends Type
case object PortType extends Type
case object ReferenceType extends Type
case object NumberType extends Type

private val ioListRid = RemoteId("erlang", "iolist", 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ private class Contractivity(module: String) {
props.map(_.tp).forall(isFoldable(_, history1))
case rt: RefinedRecordType =>
rt.fields.values.forall(isFoldable(_, history1))
case _: AtomLitType | AnyFunType | AnyTupleType | NilType | _: VarType | _: RecordType | BinaryType |
_: BuiltinType =>
true
case RemoteType(rid, argTys) =>
val hasHe = history.exists(HomeomorphicEmbedding.heByCoupling(_, ty))
!hasHe && (getTypeDeclBody(rid, argTys) match {
Expand All @@ -92,6 +89,8 @@ private class Contractivity(module: String) {
case None =>
true
})
case _ =>
true
}
}

Expand All @@ -102,8 +101,7 @@ private class Contractivity(module: String) {
false
case _: UnionType =>
false
case _: AtomLitType | AnyFunType | AnyTupleType | NilType | _: VarType | _: RecordType | BinaryType |
_: BuiltinType =>
case _ =>
// $COVERAGE-OFF$
throw new IllegalStateException("unreachable: this is a leaf node of the graph and can't wind up in `history`")
// $COVERAGE-ON$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ private object HomeomorphicEmbedding {
props.map(_.tp).exists(isHe(s, _))
case RefinedRecordType(_, fields) =>
fields.values.exists(isHe(s, _))
case _: AtomLitType | AnyFunType | AnyTupleType | NilType | _: VarType | _: RecordType | BinaryType |
_: BuiltinType =>
case _ =>
false
}

Expand Down Expand Up @@ -86,11 +85,8 @@ private object HomeomorphicEmbedding {
true
case (_: VarType, _) =>
false
case (_: AtomLitType | AnyFunType | AnyTupleType | NilType | _: RecordType | BinaryType | _: BuiltinType, _)
if s == t =>
true
case _ =>
false
s == t
}

private def heProp(sProp: Prop, tProp: Prop): Boolean = (sProp, tProp) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,6 @@ final class Occurrence(pipelineContext: PipelineContext) {
throw new IllegalStateException(t2.toString)
// $COVERAGE-ON$

case (_: BuiltinType, _: BuiltinType) =>
Some(subtype.subType(t1, t2) || subtype.subType(t2, t1))

case (ListType(_) | NilType, ListType(_) | NilType) =>
Some(true)
case (ListType(_) | NilType, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Subst {
case ShapeMap(props) => ShapeMap(props.map(substInProp(s, _)))
case DictMap(kTy, vTy) => DictMap(sub(kTy), sub(vTy))
case RefinedRecordType(recType, fields) => RefinedRecordType(recType, fields.map(f => f._1 -> sub(f._2)))
case _: BuiltinType | _: AtomLitType | NilType | BinaryType | _: RecordType | AnyTupleType | AnyFunType =>
case _ =>
t
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,7 @@ class Constraints(pipelineContext: PipelineContext) {
t2 = kvs2(prop1.key)
} yield (t1, t2)
constrainSeq(state, uppersAndLowers)
case (
_: AtomLitType | AnyFunType | AnyTupleType | NilType | _: RecordType | BinaryType | _: BuiltinType |
_: TupleType | _: DictMap | _: ShapeMap | _: OpaqueType | _: VarType | _: ListType | _: FunType |
_: RefinedRecordType,
_,
) =>
case _ =>
if (!subtype.subType(lowerBound, upperBound)) fail()
else state
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ object ElimTypeVars {
DictMap(elim(kt), elim(vt))
case ShapeMap(props) =>
ShapeMap(props.map(elimVarsInProp(_, mode, vars)))
case _: BuiltinType | _: AtomLitType | NilType | BinaryType | _: RefinedRecordType | _: RecordType |
AnyTupleType | AnyFunType =>
case _ =>
ty
}
}
Expand Down

0 comments on commit 98020bb

Please sign in to comment.