Skip to content
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

Closed
wants to merge 13 commits into from
Closed

Conversation

umazalakain
Copy link
Contributor

@umazalakain umazalakain commented May 7, 2021

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.

@umazalakain umazalakain force-pushed the merge-rise-dpia-types branch from 701e8a4 to 7ad1001 Compare May 7, 2021 16:35
Comment on lines 80 to 86
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)
})
}
Copy link
Member

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:

  1. global to a rewritten expression:
val s = rewrite1 `;` rewrite2
val typed = start.toExpr
implicit val preserve = collectFreeEnv(typed)
s(typed) // uses 'preserve'
  1. 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:

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.

@michel-steuwer

Copy link
Contributor Author

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!

src/main/scala/rise/core/types/AddressSpace.scala Outdated Show resolved Hide resolved
@@ -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 = {
Copy link
Member

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")?

src/main/scala/rise/core/types/NatCollection.scala Outdated Show resolved Hide resolved
src/main/scala/rise/core/types/NatToData.scala Outdated Show resolved Hide resolved
src/main/scala/rise/core/types/Type.scala Outdated Show resolved Hide resolved
src/main/scala/rise/core/types/Type.scala Outdated Show resolved Hide resolved
src/main/scala/rise/core/types/Type.scala Outdated Show resolved Hide resolved
@@ -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)))
Copy link
Member

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?

Copy link
Contributor Author

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 NatToDataLambdas

src/main/scala/shine/DPIA/Types/Kind.scala Outdated Show resolved Hide resolved
@umazalakain
Copy link
Contributor Author

Making a more self-contained PR in #174

@umazalakain umazalakain deleted the merge-rise-dpia-types branch June 19, 2021 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants