Port all Scala code to Java

Open
#4,030 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Stale
Tech stack
java, scala
Domain
compilers

Research direction

Start with the roadmap and inspect the listed Scala files, including Rich.scala, LabelInfoFromModule.scala, Location.scala, POSet.scala, and Att.scala. First determine which files are not involved in matching and can be scoped independently. The overall work is done when the Scala code is ported to Java, remaining Scala is made Java-esque, and Java 21 is adopted.

Written by the indexing model from the issue text.

Description

refactor

While Scala is a nice language, the consensus of the frontend team is that maintaining a mixture of Scala and Java causes more friction than it is worth:

  • IntelliJ struggles to reason about the Scala code and reports false errors (#3867)
  • We have to frequently convert between Java and Scala types (see the usages of collections.scala) and write boilerplate code to offer two versions of the same methods (e.g. getOption and getOptional in Att.scala).
  • As a company, my impression is that more of us are familiar with the intricacies of Java than of Scala.

As a result, we have decided that

  • All new code should be written in Java
  • In the longterm, all existing Scala code should be ported to Java as well

The largest blocker will be the matching library in the LLVM backend, which makes heavy usage of pattern matching and likely can't be ported until we update to Java 21 (#3499).

However, searching the frontend, there are only 47 Scala files, and many of them can be straightforwardly ported even without pattern matching support in Java.

A high level roadmap:

  • Port Scala case classes not involved in pattern matching to Java record classes inheriting from a sealed interface
  • Port Scala classes/algorithms not making use of pattern matching
  • Make remaining Scala classes as Java-esque as possible
    • Port any trait to an interface
    • Use Java types for all members that are not pattern matched on
      • We already have pcollections as a dependency, which provides immutable functional data structures
  • Update to Java 21
  • Port remaining Scala code
Dominant language
Python
Stars
591
Forks
163
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from runtimeverification/k

All issues in runtimeverification/k

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.