-
Notifications
You must be signed in to change notification settings - Fork 11
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
change matchless LoopFn node #770
Comments
actually, maybe the better design is to introduce a new node at the case class Loop[A](name: Bindable, binds: NonEmptyList[(Bindable, TypedExpr[A])], body: TypedExpr[A]) extends TypedExpr[A]
// This jumps back out to the nearest enclosing Loop with the matching name
case class Recur[A](name: Bindable, rebind: NonEmptyList[TypedExpr[A]], tpe: Type, tag: A) extends TypedExpr[A] We can actually do this as the first phase of normalization. In this way, we can inline lambdas whose bodies are loops by just inlining the loops. |
This may only work with monomorphic recursion. A loop with polymorphic recursion kind of implies boxing or type-erasure at the underlying level. We are currently cavalier with the types when we do this transformation because |
We currently in matchless have a LoopFn node:
bosatsu/core/src/main/scala/org/bykn/bosatsu/Matchless.scala
Line 41 in f9ef676
this is a tail recursive function. One problem here is that it harms inlining somewhat: it is not solved how to inline tail recursive functions.
Instead we could follow clojure and have
Loop/Recur
which isn't a function but evaluates to a value which is the result of a loop. Here, LoopFn would be a normal function that has a Loop/Recur body. In this way, we could inline such functions normally because Loop/Recur just compiles to a normal while loop, not a function + while loop.There is some subtlety about nested inlines, but I think that can be solved in one of two ways:
The text was updated successfully, but these errors were encountered: