Skip to content

Commit

Permalink
Fix change tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Sep 26, 2023
1 parent a21ef20 commit 9401958
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
9 changes: 0 additions & 9 deletions core/src/main/scala/org/bykn/bosatsu/TypedExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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)) =>
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
22 changes: 7 additions & 15 deletions core/src/main/scala/org/bykn/bosatsu/TypedExprNormalization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down Expand Up @@ -199,13 +185,15 @@ 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
val fn1 = AnnotatedLambda(args1, body, ftag)
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
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 17 additions & 1 deletion core/src/test/scala/org/bykn/bosatsu/TypedExprTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -527,7 +543,7 @@ res = _ -> 1
""") { te2 =>
assert(te1.void == te2.void, s"${te1.repr} != ${te2.repr}")
}
}
} */
}

test("lift let above lambda") {
Expand Down

0 comments on commit 9401958

Please sign in to comment.