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

New approach to rewriting rules #899

Closed
wants to merge 5 commits into from
Closed

New approach to rewriting rules #899

wants to merge 5 commits into from

Conversation

Kukovec
Copy link
Collaborator

@Kukovec Kukovec commented Jul 1, 2021

  • Tests added for any new code
  • Ran make fmt-fix (or had formatting run automatically on all files edited)
  • Documentation added for any new functionality
  • Entry added to UNRELEASED.md for any new functionality

This 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.

@Kukovec Kukovec added the experimental Experimental code label Jul 1, 2021
Copy link
Contributor

@shonfeder shonfeder left a 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.

Comment on lines 14 to 16
private def safeBind(key: String, value: ArenaCell): RewritingComputation[Unit] = modify { s =>
s.copy(binding = Binding(s.binding.toMap + (key -> value)))
}
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@shonfeder shonfeder changed the title WIP: New approach to rewriting rules New approach to rewriting rules Nov 3, 2021
Copy link
Contributor

@shonfeder shonfeder left a 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]
Copy link
Contributor

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:

Suggested change
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.

Comment on lines +40 to +42
// Shorthand for State[SymbStateInternal, T] { fn }
def cmp[T](fn: RewritingState => (RewritingState, T)): RewritingComputation[T] =
State[RewritingState, T] { fn }
Copy link
Contributor

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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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)
Copy link
Contributor

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).

@thpani thpani marked this pull request as draft March 24, 2022 08:05
@shonfeder shonfeder changed the base branch from unstable to main July 21, 2022 21:24
@shonfeder shonfeder closed this Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental Experimental code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants