Skip to content
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

Adding a case for type instantiation #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/main/scala/inox/ast/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ trait TypeOps {
(ts1 zip ts2).foldLeft[Instantiation](Map.empty) {
case (inst, (tp1, tp2)) => unify(inst, rec(tp1, tp2))
}
case (adt1: ADTType, refn: RefinementType) =>
refn.getType match {
case adt2: ADTType =>
// ADT(X1, ..., Xn) -> { vd: ADT(A1, ..., An) | prop }
// ~>
// X1 -> A1, ..., Xn -> An
rec(adt1, adt2)
case _ => throw new Failure
}
Comment on lines +75 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could make it a bit more general with:

case (_, RefinementType(vd, _)) =>
  rec(from, vd.tpe)

Also, we probably need cases for SigmaType and PiType:

case (TupleType(tps), SigmaType(vds, elem)) =>
  val vars = vds.map(_.toVariable).toSet
  (tps zip (vds.map(_.tpe) +: elem)).foldLeft[Instantiation](Map.empty) {
    case (inst, (tp1, tp2)) =>
      unify(inst, rec(tp1, if ((exprOps.variablesOf(tp2) & vars).nonEmpty) tp2.getType else tp2))
  }

(and same for PiType).

Finally, you should probably make sure the from type isn't a dependent type by using from.getType in the call to rec below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestions! I'll go back to this PR afterwards :)

case _ => throw new Failure
}

Expand Down