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 back-edge dependency on the K frontend #999

Closed
Baltoli opened this issue Feb 29, 2024 · 2 comments · Fixed by #1007
Closed

Remove back-edge dependency on the K frontend #999

Baltoli opened this issue Feb 29, 2024 · 2 comments · Fixed by #1007

Comments

@Baltoli
Copy link
Collaborator

Baltoli commented Feb 29, 2024

Currently, the pattern-matching compiler depends on Scala code in the K frontend to parse KORE. This induces a backwards edge in the K ecosystem dependency graph that's previously been painful to deal with.1 As part of our general work to simplify and reorganise the K ecosystem code, we want to remove this backwards edge in the graph: runtimeverification/k#4063 (comment)

Some thoughts on how we might achieve this:

  • Pull the offending code out of the frontend and into the backend directly; the frontend will then need to depend on the backend to get the parser etc.
  • Extract the KORE parser Scala code as a standalone library that lives in its own repository and can be consumed as a regular Maven dependency.
  • much more work, longer term do a rewrite of the matching compiler to no longer use Scala.

Footnotes

  1. It doesn't happen often because the KORE language is pretty stable, but when we last made changes (related to \left-assoc and \right-assoc) it was extremely painful for a number of reasons: getting PRs merged in lockstep with each other, people's maven caches getting stale and producing confusing errors, etc.

@Baltoli
Copy link
Collaborator Author

Baltoli commented Mar 1, 2024

The packages that are backwards dependencies from the LLVM backend into the frontend:

org.kframework.attributes.HasLocation
org.kframework.attributes.Location
org.kframework.attributes.Source
org.kframework.kore.K
org.kframework.kore.KORE.KApply
org.kframework.kore.KORE.KList
org.kframework.mpfr._
org.kframework.parser.kore
org.kframework.parser.kore.CompoundSort
org.kframework.parser.kore.Sort
org.kframework.parser.kore.SymbolOrAlias
org.kframework.parser.kore.Variable
org.kframework.parser.kore._
org.kframework.parser.kore.implementation.{
org.kframework.parser.kore.parser.KoreToK
org.kframework.parser.kore.parser.TextToKore
org.kframework.unparser.ToKast
org.kframework.utils.errorsystem.KEMException
org.kframework.utils.errorsystem.KException

My thoughts on the various components here and what we should do with them to resolve the back edge:

  • Attribute usages: we should wean the library off these data structures and just define internal ones; they're only being used as PODs as far as I can tell.
  • KORE data structures and parser: we should pull this whole subsystem out into a separate library except KoreToK which logically needs to remain a part of the frontend. As best I can tell, the features in that package are only being used to do pretty-printing for error-handling purposes; see below.
  • MPFR: this is actually an external dependency; not relevant here
  • Error handling subsystem: the matching compiler should define its own error types; the frontend can then be updated to translate between the kinds of exceptions the matching compiler throws, and to plug them into the KEM infrastructure.
  • Unparser / KoreToK: for code that does pretty-printing of any kind (e.g. in the exhaustiveness checker), we will need to use the new KORE-only error handling mechanism to throw an exception upwards to K such that the frontend can then translate it to KEM, and do the appropriate pretty-printing.

This is all a pretty viable set of changes to make, I think - on a first look at the set of changes required I thought it might be a trickier job than anticipated, but on a bit more inspection we can pretty easily cut the backwards edge.

@Baltoli
Copy link
Collaborator Author

Baltoli commented Mar 1, 2024

I think the first step to take here is to migrate the error-handling code out of the pattern matcher, and have the frontend do translation on the errors and warnings it sees.

  • In places where we're passing KExceptions into handlers, we should instead define an analogous MatchingException and pass those instead.
  • In places where we throw an unrecoverable exception, we should still throw, but have the frontend catch those exception types and translate them.

rv-jenkins pushed a commit that referenced this issue Mar 1, 2024
Part of: #999

We are currently working on removing the reverse dependency that the
LLVM backend has on the K frontend's data structures; this PR takes a
first step towards that goal by removing the backend's use of the K
exception infrastructure for throwing errors.

The K infrastructure is replaced with a simple exception class that the
frontend will be able to catch and reinterpret as appropriate.

This PR needs a matching change to the K frontend to work, along with
appropriate lockstep merging.

---------

Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
rv-jenkins pushed a commit that referenced this issue Mar 1, 2024
Part of: #999

We are currently working on removing the reverse dependency that the
LLVM backend has on the K frontend's data structures; this PR takes a
step towards that goal by removing the backend's use of the K Source and
Location classes. These classes are only ever used in the matching
compiler as simple PODs that carry around data, so they can be replaced
trivially with Java classes here.

This PR needs a matching change to the K frontend to work, along with
appropriate lockstep merging.

Also contains a minor fix in
4b644b0
for an edge case in the exhaustiveness checker for rules with no
location; we want to propagate an empty optional here rather than
`null`.
rv-jenkins added a commit that referenced this issue Mar 6, 2024
This PR finalises the removal of the LLVM backend's dependence on the K
frontend, now that we have the shared data structures extracted out to
the [`scala-kore`
repository](https://github.com/runtimeverification/scala-kore). There
are a few smaller changes that make up this PR, but the commit history
is clean and can be reviewed commit-by-commit.

Once this is merged, the LLVM backend will no longer depend on the K
Frontend and we will have eliminated the backwards edge in the K
dependency graph!

Fixes: #999

---------

Co-authored-by: Samuel Balco <goodlyrottenapple@gmail.com>
Co-authored-by: rv-jenkins <admin@runtimeverification.com>
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 a pull request may close this issue.

1 participant