Skip to content

Commit

Permalink
fix: let pretty print types (flix#5991)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanStarup authored May 19, 2023
1 parent 0e41e99 commit 7a02fc1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ object ErasedAstPrinter {
case IfThenElse(exp1, exp2, exp3, _, _) => DocAst.Expression.IfThenElse(print(exp1), print(exp2), print(exp3))
case Branch(exp, branches, _, _) => DocAst.Expression.Branch(print(exp), branches.view.mapValues(print).toMap)
case JumpTo(sym, _, _) => DocAst.Expression.JumpTo(sym)
case Let(sym, exp1, exp2, tpe, _) => DocAst.Expression.Let(printVarSym(sym), Some(MonoTypePrinter.print(tpe)), print(exp1), print(exp2))
case LetRec(varSym, _, _, exp1, exp2, tpe, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(MonoTypePrinter.print(tpe)), print(exp1), print(exp2))
case Let(sym, exp1, exp2, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(MonoTypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case LetRec(varSym, _, _, exp1, exp2, _, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(MonoTypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case Scope(sym, exp, _, _) => DocAst.Expression.Scope(printVarSym(sym), print(exp))
case TryCatch(exp, rules, _, _) => DocAst.Expression.TryCatch(print(exp), rules.map { case ErasedAst.CatchRule(sym, clazz, rexp) =>
(sym, clazz, print(rexp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ object LiftedAstPrinter {
case IfThenElse(exp1, exp2, exp3, _, _, _) => DocAst.Expression.IfThenElse(print(exp1), print(exp2), print(exp3))
case Branch(exp, branches, _, _, _) => DocAst.Expression.Branch(print(exp), branches.view.mapValues(print).toMap)
case JumpTo(sym, _, _, _) => DocAst.Expression.JumpTo(sym)
case Let(sym, exp1, exp2, tpe, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(TypePrinter.print(tpe)), print(exp1), print(exp2))
case LetRec(varSym, _, _, exp1, exp2, tpe, _, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(TypePrinter.print(tpe)), print(exp1), print(exp2))
case Let(sym, exp1, exp2, _, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(TypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case LetRec(varSym, _, _, exp1, exp2, _, _, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(TypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case Region(_, _) => DocAst.Expression.Region
case Scope(sym, exp, _, _, _) => DocAst.Expression.Scope(printVarSym(sym), print(exp))
case ScopeExit(exp1, exp2, _, _, _) => DocAst.Expression.ScopeExit(print(exp1), print(exp2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ object MonoTypedAstPrinter {
case IfThenElse(exp1, exp2, exp3, _, _) => DocAst.Expression.IfThenElse(print(exp1), print(exp2), print(exp3))
case Branch(exp, branches, _, _) => DocAst.Expression.Branch(print(exp), branches.view.mapValues(print).toMap)
case JumpTo(sym, _, _) => DocAst.Expression.JumpTo(sym)
case Let(sym, exp1, exp2, tpe, _) => DocAst.Expression.Let(printVarSym(sym), Some(MonoTypePrinter.print(tpe)), print(exp1), print(exp2))
case LetRec(varSym, _, _, exp1, exp2, tpe, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(MonoTypePrinter.print(tpe)), print(exp1), print(exp2))
case Let(sym, exp1, exp2, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(MonoTypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case LetRec(varSym, _, _, exp1, exp2, _, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(MonoTypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case Scope(sym, exp, _, _) => DocAst.Expression.Scope(printVarSym(sym), print(exp))
case TryCatch(exp, rules, _, _) => DocAst.Expression.TryCatch(print(exp), rules.map {
case MonoTypedAst.CatchRule(sym, clazz, rexp) => (sym, clazz, print(rexp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ object ReducedAstPrinter {
case Expr.IfThenElse(exp1, exp2, exp3, _, _, _) => DocAst.Expression.IfThenElse(print(exp1), print(exp2), print(exp3))
case Expr.Branch(exp, branches, _, _, _) => DocAst.Expression.Branch(print(exp), branches.view.mapValues(print).toMap)
case Expr.JumpTo(sym, _, _, _) => DocAst.Expression.JumpTo(sym)
case Expr.Let(sym, exp1, exp2, tpe, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(TypePrinter.print(tpe)), print(exp1), print(exp2))
case Expr.LetRec(varSym, _, _, exp1, exp2, tpe, _, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(TypePrinter.print(tpe)), print(exp1), print(exp2))
case Expr.Let(sym, exp1, exp2, _, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(TypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case Expr.LetRec(varSym, _, _, exp1, exp2, _, _, _) => DocAst.Expression.LetRec(printVarSym(varSym), Some(TypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case Expr.Scope(sym, exp, _, _, _) => DocAst.Expression.Scope(printVarSym(sym), print(exp))
case Expr.TryCatch(exp, rules, _, _, _) => DocAst.Expression.TryCatch(print(exp), rules.map{
case ReducedAst.CatchRule(sym, clazz, exp) => (sym, clazz, print(exp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ object SimplifiedAstPrinter {
case IfThenElse(exp1, exp2, exp3, _, _, _) => DocAst.Expression.IfThenElse(print(exp1), print(exp2), print(exp3))
case Branch(exp, branches, _, _, _) => DocAst.Expression.Branch(print(exp), branches.view.mapValues(print).toMap)
case JumpTo(sym, _, _, _) => DocAst.Expression.JumpTo(sym)
case Let(sym, exp1, exp2, tpe, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(TypePrinter.print(tpe)), print(exp1), print(exp2))
case LetRec(sym, exp1, exp2, tpe, _, _) => DocAst.Expression.LetRec(printVarSym(sym), Some(TypePrinter.print(tpe)), print(exp1), print(exp2))
case Let(sym, exp1, exp2, _, _, _) => DocAst.Expression.Let(printVarSym(sym), Some(TypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case LetRec(sym, exp1, exp2, _, _, _) => DocAst.Expression.LetRec(printVarSym(sym), Some(TypePrinter.print(exp1.tpe)), print(exp1), print(exp2))
case Region(_, _) => DocAst.Expression.Region
case Scope(sym, exp, _, _, _) => DocAst.Expression.Scope(printVarSym(sym), print(exp))
case ScopeExit(exp1, exp2, _, _, _) => DocAst.Expression.ScopeExit(print(exp1), print(exp2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ object TypePrinter {
// try to unpack one arrow type only for the sake of signatures
tpe.baseType match {
case Type.Cst(TypeConstructor.Arrow(_), _) =>
val targs = tpe.typeArguments
if (targs.nonEmpty) {
val args = targs.dropRight(1)
val res = targs.last
DocAst.Type.Arrow(args.map(printHelper), printHelper(res))
} else
printHelper(tpe)
val args = tpe.arrowArgTypes
val res = tpe.arrowResultType
DocAst.Type.Arrow(args.map(printHelper), printHelper(res))
case _ => printHelper(tpe)
}
}
Expand Down

0 comments on commit 7a02fc1

Please sign in to comment.