-
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
Do not extend NamedVar
with Kind.Identifier
in DPIA
#190
Conversation
@Bastacyclop @michel-steuwer This PR:
|
def renaming[X <: PhraseType](p: Phrase[X]): Phrase[X] = { | ||
case class Renaming(idMap: Map[String, String]) extends VisitAndRebuild.Visitor { | ||
override def phrase[T <: PhraseType](p: Phrase[T]): Result[Phrase[T]] = p match { | ||
case Identifier(name, t) => Stop( | ||
Identifier(idMap.getOrElse(name, name), | ||
VisitAndRebuild.visitPhraseTypeAndRebuild(t, this)).asInstanceOf[Phrase[T]]) | ||
case l @ Lambda(x, _) => | ||
val newMap = idMap + (x.name -> freshName(x.name.takeWhile(_.isLetter))) | ||
Continue(l, Renaming(newMap)) | ||
case dl @ DepLambda(_, x, _) => | ||
val newMap = idMap + (x.name -> freshName(x.name.takeWhile(_.isLetter))) | ||
Continue(dl, Renaming(newMap)) | ||
case _ => Continue(p, this) | ||
} | ||
|
||
override def nat[N <: Nat](n: N): N = n.visitAndRebuild({ | ||
case i: NatIdentifier => | ||
NatIdentifier(idMap.getOrElse(i.name, i.name)) | ||
case ae => ae | ||
}).asInstanceOf[N] | ||
|
||
override def data[T <: DataType](dt: T): T = (dt match { | ||
case i: DataTypeIdentifier => | ||
DataTypeIdentifier(idMap.getOrElse(i.name, i.name)) | ||
case dt => dt | ||
}).asInstanceOf[T] | ||
} | ||
VisitAndRebuild(p, Renaming(Map())) | ||
} |
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 if we don't try to enforce unique names anymore, we should use proper capture-avoiding substitution here?
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.
@Bastacyclop can you create an issue for that, please?
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.
case pf@ParForNat(level, dim, _, name) if (eliminateVars(pf.body.asInstanceOf[DepLambda[_, _ <: Kind.Identifier, _]].x.name)) => | ||
case pf@ParForNat(level, dim, _, name) if (eliminateVars(Kind.idName( | ||
pf.body.asInstanceOf[DepLambda[_, _, _ <: Kind.Identifier, _]].kind, | ||
pf.body.asInstanceOf[DepLambda[_, _, _ <: Kind.Identifier, _]].x))) => |
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.
Maybe there is a better way to write this to avoid triple casting.
This way
NamedVar
s are uniform across RISE, DPIA, and arithexpr. This accomplishes two things:DPIA -> arithexpr -> DPIA
translations irrelevant.