Skip to content

Commit

Permalink
Use tuple caching logic in declareDatatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-hamza committed May 11, 2021
1 parent 108cfef commit 68f571b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/scala/inox/tip/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ class Printer(val program: InoxProgram, val context: Context, writer: Writer) ex
case _ => super.computeSort(t)
}

private def getGenericTupleType(n: Int): TupleType = {
tuples.getOrElse(n, {
val res = TupleType(List.range(0, n).map(i => TypeParameter.fresh("A" + i)))
tuples(n) = res
res
})
}

override protected def declareStructuralSort(t: Type): Sort = t match {
case adt: ADTType =>
val tpe = liftADTType(adt)
Expand All @@ -127,11 +135,7 @@ class Printer(val program: InoxProgram, val context: Context, writer: Writer) ex
Sort(id, tpSorts)

case TupleType(ts) =>
val tpe = tuples.getOrElse(ts.size, {
val res = TupleType(List.range(0, ts.size).map(i => TypeParameter.fresh("A" + i)))
tuples(ts.size) = res
res
})
val tpe = getGenericTupleType(ts.size)
adtManager.declareADTs(tpe, declareDatatypes)
val tpSorts = ts.map(declareSort)
Sort(sorts.toB(tpe).id, tpSorts)
Expand Down Expand Up @@ -161,7 +165,7 @@ class Printer(val program: InoxProgram, val context: Context, writer: Writer) ex
}))

case (TupleType(tps), DataType(sym, Seq(Constructor(id, TupleCons(_), fields)))) =>
val TupleType(tparams) = tuples(tps.size)
val TupleType(tparams) = getGenericTupleType(tps.size)
(TupleType(tparams), DataType(sym, Seq(Constructor(id, TupleCons(tparams),
(fields zip tparams).map { case ((id, _), tpe) => (id, tpe) }))))

Expand Down

0 comments on commit 68f571b

Please sign in to comment.