-
Notifications
You must be signed in to change notification settings - Fork 8
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
Remove explicitness information #171
Conversation
Always extend the preserve set with FTVs in assertions and opaques
701e8a4
to
7ad1001
Compare
def !:[T <: Expr](e: ToBeTyped[T]): ToBeTyped[Expr] = { | ||
val preserve = infer.getFTVs(t).map(_.name) | ||
e >>= (e => { | ||
val env = infer.collectFreeEnv(e) | ||
infer(TypeAnnotation(e, t), env, preserve) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the preserve
set should either be:
- global to a rewritten expression:
val s = rewrite1 `;` rewrite2
val typed = start.toExpr
implicit val preserve = collectFreeEnv(typed)
s(typed) // uses 'preserve'
- taken from the left-hand-side of each rewrite rule
def s: Strategy = lhs => infer(rhs :: lhs.t, collectFreeEnv(lhs), getFTVs(lhs))
Solution 2. requires less global code changes and is more similar to the solution I used in the equality saturation side:
shine/src/main/scala/rise/eqsat/NamedRewrite.scala
Lines 15 to 23 in 91a3d2a
val (lhs, rhs) = rule | |
val untypedFreeV = collectFreeEnv(lhs).map { case (name, t) => | |
assert(t == rct.TypePlaceholder) | |
name -> rct.TypeIdentifier("t" + name) | |
} | |
val typedLhs = preservingWithEnv(lhs, untypedFreeV, Set()) | |
val freeV = collectFreeEnv(typedLhs) | |
val (_, freeT) = rise.core.IsClosedForm.freeVars(typedLhs) | |
val typedRhs = preservingWithEnv(rc.TypeAnnotation(rhs, typedLhs.t), freeV, freeT) |
In the future we can also consider having a common syntax for both equality saturation and Elevate rewrite rules:
def etaAbstraction = f : (a -> b) --> λx. (f x)
def etaReduction = λx. (f x) --> f
when f ∌ x // x not in freeVars(f)
def mapFusion = map f (map g in) --> map λx. (f (g x)) in
def mapFission = {dt: data} -> map λx. (f (gx : dt)))) --> λin. map f (map λx. gx in)
when f ∌ x
This would also enable type-checking Elevate rewrite rules ahead of match like I do for eqsat rewrite rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed something along this lines, thanks!
@@ -75,9 +72,9 @@ object Constraint { | |||
} | |||
|
|||
// scalastyle:off method.length | |||
def solveOne(c: Constraint, preserve : Set[Kind.Identifier], trace: Seq[Constraint]) (implicit explDep: Flags.ExplicitDependence): Solution = { | |||
def solveOne(c: Constraint, preserve: Set[String], trace: Seq[Constraint]) (implicit explDep: Flags.ExplicitDependence): Solution = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this results in DataTypeIdentifier("s") == NatIdentifier("s")
?
@@ -192,7 +160,7 @@ final case class DepArrayType(size: Nat, fdt: NatToData) extends DataType { | |||
|
|||
object DepArrayType { | |||
def apply(size: Nat, f: Nat => DataType): DepArrayType = { | |||
val n = NatIdentifier(freshName("n"), RangeAdd(0, size, 1), isExplicit = true) | |||
val n = NatIdentifier(freshName("n"), RangeAdd(0, size, 1)) | |||
DepArrayType(size, NatToDataLambda(n, f(n))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we properly deal with such dependent types when collecting free variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, IsClosedForm
deals with NatToDataLambda
s
Making a more self-contained PR in #174 |
Removes
Kind.Explicitness
, instead type variables are understood to be globally free, implicit, and for type inference to solve if they are not bound, and explicit otherwise. Type assertions are also removed, they are substituted with type annotations where the FTVs of the asserted type are preserved.Plenty of tests don't pass, I need to figure out why.