From 9401958d5ecbf41216b687edf1bf3f7c96460c4f Mon Sep 17 00:00:00 2001 From: Patrick Oscar Boykin Date: Mon, 25 Sep 2023 22:49:40 -0700 Subject: [PATCH] Fix change tests to pass --- .../scala/org/bykn/bosatsu/TypedExpr.scala | 9 -------- .../bykn/bosatsu/TypedExprNormalization.scala | 22 ++++++------------- .../org/bykn/bosatsu/TypedExprTest.scala | 18 ++++++++++++++- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/core/src/main/scala/org/bykn/bosatsu/TypedExpr.scala b/core/src/main/scala/org/bykn/bosatsu/TypedExpr.scala index 8b707f17e..9d4c34538 100644 --- a/core/src/main/scala/org/bykn/bosatsu/TypedExpr.scala +++ b/core/src/main/scala/org/bykn/bosatsu/TypedExpr.scala @@ -673,11 +673,6 @@ object TypedExpr { def instantiateTo[A](gen: Generic[A], instTpe: Type.Rho, kinds: Type => Option[Kind]): TypedExpr[A] = { import Type._ - /* - def show(t: Type): String = - Type.fullyResolvedDocument.document(t).render(80) - */ - def solve(left: Type, right: Type, state: Map[Type.Var, Type], solveSet: Set[Type.Var]): Option[Map[Type.Var, Type]] = (left, right) match { case (TyVar(v), right) if solveSet(v) => @@ -693,8 +688,6 @@ object TypedExpr { // the examples that come up look like un-unified // types, as if coerceRho is called before we have // finished unifying - // - //println(s"could not pushDown: ${show(fa)}") None } case (TyApply(on, arg), TyApply(on2, arg2)) => @@ -727,7 +720,6 @@ object TypedExpr { pushGeneric(newGen) match { case badOpt @ (None | Some(Generic(_, _)))=> // just wrap - //println(s"could not push frees instantiate: ${show(gen.getType)} to ${show(instTpe)}\n\n${badOpt.map(_.repr)}") Annotation(badOpt.getOrElse(newGen), instTpe) case Some(notGen) => notGen } @@ -747,7 +739,6 @@ object TypedExpr { // but those two types aren't the same. It seems like we have to later // learn that ?338 == $k$303, but we don't seem to know that yet - //println(s"could not solve instantiate: ${show(gen.getType)} to ${show(instTpe)}") // just add an annotation: Annotation(gen, instTpe) case Some(res) => res diff --git a/core/src/main/scala/org/bykn/bosatsu/TypedExprNormalization.scala b/core/src/main/scala/org/bykn/bosatsu/TypedExprNormalization.scala index 81c1707d6..96b30bb2b 100644 --- a/core/src/main/scala/org/bykn/bosatsu/TypedExprNormalization.scala +++ b/core/src/main/scala/org/bykn/bosatsu/TypedExprNormalization.scala @@ -49,21 +49,7 @@ object TypedExprNormalization { loop(scope1, tail, (b, r, normTE) :: acc) } - val res = loop(emptyScope, lets, Nil) - if (pack == PackageName.parts("Bosatsu", "List")) { - lets.zip(res).foreach { case ((b, _, in), (_, _, out)) => - val same = in == out - println(s"$b was ${if (same) "not " else ""} changed") - println("=======init========") - println(in.repr) - if (!same) { - println("======final========") - println(out.repr) - } - println("===================") - } - } - res + loop(emptyScope, lets, Nil) } def normalizeProgram[A, V]( @@ -199,6 +185,7 @@ object TypedExprNormalization { case App(fn, aargs, _, _) if matchesArgs(aargs) && doesntUseArgs(fn) => // x -> f(x) == f (eta conversion) normalize1(None, setType(fn, te.getType), scope, typeEnv) + /* case App(ws.ResolveToLambda(Nil, args1, body, ftag), aargs, resT, tag) => // args -> (args1 -> e1)(...) // this is inlining, which we do only when nested directly inside another lambda @@ -206,6 +193,7 @@ object TypedExprNormalization { normalize1(namerec, AnnotatedLambda(lamArgs, App(fn1, aargs, resT, tag), tag), scope, typeEnv) + */ case Let(arg1, ex, in, rec, tag1) if doesntUseArgs(ex) && doesntShadow(arg1) => // x -> // y = z @@ -448,6 +436,8 @@ object TypedExprNormalization { } object ResolveToLambda { + // TODO: don't we need to worry about the type environment for locals? They + // can also capture type references to outer Generics def unapply(te: TypedExpr[A]): Option[(List[(Type.Var.Bound, Kind)], NonEmptyList[(Bindable, Type)], TypedExpr[A], A)] = te match { case Annotation(ResolveToLambda((h :: t), args, ex, tag), rho: Type.Rho) => @@ -627,6 +617,8 @@ object TypedExprNormalization { Some((n :: ns, pats)) case Pattern.PositionalStruct(_, pats) => Some((Nil, pats)) + case Pattern.WildCard => Some((Nil, args.as(Pattern.WildCard))) + case Pattern.Var(n) => Some((n :: Nil, args.as(Pattern.WildCard))) case _ => None } diff --git a/core/src/test/scala/org/bykn/bosatsu/TypedExprTest.scala b/core/src/test/scala/org/bykn/bosatsu/TypedExprTest.scala index d4a387f07..c2dd291eb 100644 --- a/core/src/test/scala/org/bykn/bosatsu/TypedExprTest.scala +++ b/core/src/test/scala/org/bykn/bosatsu/TypedExprTest.scala @@ -514,6 +514,22 @@ x = Foo assert(res == Some(right), s"${res.map(_.repr)} != Some(${right.repr}") + checkLast(""" +res = ( + f = (_, y) -> y + z = 1 + y -> (x -> f(x, z))(y) +) +""") { te1 => + + checkLast(""" +res = _ -> 1 + """) { te2 => + assert(te1.void == te2.void, s"${te1.repr} != ${te2.repr}") + } + } + + /* checkLast(""" f = (_, y) -> y z = 1 @@ -527,7 +543,7 @@ res = _ -> 1 """) { te2 => assert(te1.void == te2.void, s"${te1.repr} != ${te2.repr}") } - } + } */ } test("lift let above lambda") {