-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
New approach to rewriting rules #899
Conversation
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 approach looks great to me. I think there'll be lots of gains by moving the rewriting into pure computations. 👍
I left two incidental suggestions, but they are just superficial.
private def safeBind(key: String, value: ArenaCell): RewritingComputation[Unit] = modify { s => | ||
s.copy(binding = Binding(s.binding.toMap + (key -> value))) | ||
} |
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 wonder if the body of this method might be situated as a method on the RewritingState
object like
def bind(key: String, value: ArenaCell): RewritingState
or perhaps inlined. As is, seems like this method is "thin" and cases cases needless redirection when reading the code. I think I feel the same about the other safe
helper methods. Perhaps this is just a matter of taste.
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.
Fair enough, the idea here was mostly to demonstrate the difference (and the relative ease of lifting to a "computation with possible exceptions"), but I agree that the "safe" methods don't add much.
tla-bmcmt/src/main/scala/at/forsyte/apalache/tla/bmcmt/rewriter2/NegationRule.scala
Show resolved
Hide resolved
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 all looks good to me, with just a few minor change suggestion. I wonder if you should get input from Rodrigo or Igor before starting to migrate over the other rewriting stuff?
My principle question on this is what is the plan for integration? Do we have work scheduled to start porting over the rewriter into this new approach?
|
||
type RewritingComputation[T] = State[RewritingState, T] | ||
|
||
type StateCompWithExceptions[T] = EitherT[Exception, RewritingComputation, T] |
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.
How about something like this:
type StateCompWithExceptions[T] = EitherT[Exception, RewritingComputation, T] | |
type RewritingComputationExn[T] = EitherT[Exception, RewritingComputation, T] |
Otherwise its not clear from the name that this pertains to the RewritingComputation
or that Comp
is short for Computation
rather than Comparison
.
// Shorthand for State[SymbStateInternal, T] { fn } | ||
def cmp[T](fn: RewritingState => (RewritingState, T)): RewritingComputation[T] = | ||
State[RewritingState, T] { fn } |
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.
If cmp
is short for Computation
than maybe use Comp
since that's already appearing in the StateComptWithException
type alias?
} | ||
} | ||
|
||
// Shorthand for State[SymbStateInternal, T] { fn } |
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.
// Shorthand for State[SymbStateInternal, T] { fn } | |
// Shorthand for State[RewritingState, T] { fn } |
|
||
/** | ||
* A rule in the new rewriting system. It can be tested, or applied. In the latter case, it either returns | ||
* a TlaEx (rewritten expression) or throws a RewritingException (represented by computation) |
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 don't understand this part: throws a RewritingException (represented by computation)
.
make fmt-fix
(or had formatting run automatically on all files edited)Documentation added for any new functionalityEntry added to UNRELEASED.md for any new functionalityThis PR outlines a proof-of-concept alternative implementation of rewriting rules, using
scalaz.State
. It should facilitate discussion regarding the new approach to rewriting, and is not intended to be integrated (in its current form) in the near future.