Frontend code cleanup + audits
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 18/100
- Issue type
- Refactor
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- build-system, compilers, devtools, documentation
Research direction
Start by reading the listed entry points: KoreBackend.java, ParseInModule.java, ModuleToKORE.java, HaskellRewriter.java, the frontend unparser, and k-distribution scripts. This is a broad audit rather than a single task, so first narrow it to one subsystem, identify its tests and dependencies, and agree on a concrete scope. Done should include the selected cleanup and documented audit findings.
Written by the indexing model from the issue text.
Description
Introduction
As discussed in our year-end review, we want to be making a push towards simplicity and removal of un-needed code across the various K projects in 2024.
The biggest offender in this respect is the K Frontend; this project has been maintained continuously for the best part of 15 years at this point and so presents the greatest opportunity to remove code that is no longer needed. Actionable steps that we identified in the review meeting were to:
- Run some kind of Java code coverage tool over the set of large semantics & regression tests that we maintain; this will give us an idea if there are non-statically dead code paths that never get run in practice.
- Schedule a review meeting with relevant parties to comb through the code tree together in a meeting.
- Important to make sure that we record the outcome of this as documentation.
- I have invited @dwightguth and @Scott-Guest initially; we can grow this group if desirable.
Other bits of knowledge transfer that we might want to do as part of this process:
- https://github.com/runtimeverification/k/issues/1278
- https://github.com/runtimeverification/k/issues/1415 (@Scott-Guest has tidied up and codified a lot of this as part of type inferencing)
- https://github.com/runtimeverification/k/issues/1443
K Frontend Deep Dive (17 Jan 24)
We went through the K Frontend in some detail in a meeting; a brief summary of the main points that we identified there were:
- The kore module is poorly named as a consequence of history; it should be renamed now that KORE refers to an actual language.
- We may be able to fully remove this module in the near future; the main reason that it exists is to hive away the Scala code in the frontend.
- Once we can https://github.com/runtimeverification/k/issues/3699, it should be possible to remove the Scala code entirely by using the new Java pattern matching features.
- This is blocked only on updating our build and release infrastructure to Ubuntu Noble (due April 2024), so I think we can wait for that update to go through before taking a further look at the Scala code.
- There are a number of different data structures defined in the frontend across several different locations:
- The "kore" ADT, which is actually a representation of K's inner syntax[^1]. The compiler pipeline that lowers a K definition is implemented over this representation.
- The
TreeNodesstructure that is generated by the parser; this is the parse tree precursor to the "kore" structure's AST. - A representation of what we refer to today as KORE (i.e. the language understood by the various backends). This representation is used in a few code paths (
kastconversions from KORE, the LLVM backend's pattern matching compiler[^2]). - A largely-legacy format called
KILthat today is only really used as an intermediate step between the parser and our inner syntax representation.
- There may be some code left over from the legacy (pre
kprovex) Java prover that can be removed. - Can we make some progress on https://github.com/runtimeverification/k/issues/1989? The main blockers there are:
- Conditional compilation steps depending on the backend; these should be factored out and any remaining differences in behaviour somehow pushed into the KORE.
- Tools understanding new directory layouts.
- There are duplicated implementations of the K unparser in the frontend and LLVM backend. We can perhaps try to unify these two implementations; this will need a bit of an audit to see where the Java path can be used without the LLVM backend being present.
- We have a binary format that serializes inner syntax. Does anything ever actually use this?
- There are a couple of JavaCC parsers that we might be able to deprecate as well (for an outdated representation of K inner syntax - confusingly referred to here as
KAST- and for output from Z3). - One place that complexity gets hidden inside the compiler is in the various compilation pipelines. It's not very clear from reading these what the ordering / dependencies between phases are, or how the intermediate code looks after each one. We should do a focused cleanup and documentation effort on these:
- The compilation pipeline that lowers a K definition into something that can be used to emit KORE.
- The type inference and disambiguation pipeline that is responsible for parsing a term, then applying semantics-specific disambiguations to turn that term into a single canonical piece of inner syntax.
- The
ModuleToKOREmonolith. This code can probably be improved in Java 21 with string templates.
K Distribution Deep Dive (24 Jan 24)
A summary of the main points covered when doing our deep dive into the broader K distribution beyond the core Java code:
- Mechanisms for loading backends; dynamic / reflection based registration and lookup for these to allow them to be developed semi-separately to the rest of the K repository.
- Logic for discarding modules relevant should we begin to look at coupled compilation.
- Possible locations of dead code and other cruft:
- We should document the compiler <> standard library glue in
kast.mdbetter - Document the Makefile infrastructure that runs the test suite
- Document the packaging work that we do
- Down the line, we might consider separate sessions for Nix and CI setup if there's interest
LLVM Backend Deep Dive (31 Jan 24)
upcoming
[^1]: An interesting question would be to compare this inner syntax representation to Pyk's. What representations / decisions did we do differently in each place? Did we learn any lessons representing K inner syntax in Pyk that could be backported to the frontend?
[^2]: Maybe this code could be pulled out into a separate library? The deployment of these data structures caused us some weirdnesses when we needed to change them during the change to make \and and \or n-ary.
- Dominant language
- Python
- Stars
- 591
- Forks
- 163
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from runtimeverification/k
-
runtimeverification/k#4939 · 1 assignee ·
-
Concolic Explorer Open
Difficulty 5/5 Over a week Newbie friendliness 32/100
runtimeverification/k#4937 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
runtimeverification/k#4936 ·
-
type:epic
runtimeverification/k#4934 · 4 comments · 1 assignee ·
-
runtimeverification/k#4924 · 1 assignee ·
All issues in runtimeverification/k
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100