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

Rewriting org.enso.runner.Main to Java #9810

Merged
merged 12 commits into from
May 2, 2024
Merged

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Apr 29, 2024

Pull Request Description

As part of changes for #9749, let's rewrite the launcher to Java.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
  • All code has been tested:
    • Unit tests continue to pass.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label Apr 29, 2024
@JaroslavTulach JaroslavTulach self-assigned this Apr 29, 2024
@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented Apr 29, 2024

Bunch of ProjectManagementApiSpec failures. How does one debug them? Do they really run org.enso.runner.Main somewhere?

Fixed in 7189b0c

Copy link
Contributor

@hubertp hubertp left a comment

Choose a reason for hiding this comment

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

Confused by the purpose of MainUtil (apart from printPolyglotException

@JaroslavTulach JaroslavTulach added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Apr 30, 2024
@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented May 1, 2024

The current state of the PR is good enough to give us similar options to other GraalVM language launchers, if that's what we want. I'd like to integrate when the CI gets green.

Copy link
Contributor

@hubertp hubertp left a comment

Choose a reason for hiding this comment

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

Some simplifications could be added, as per comments. But overall this looks OK if we really want to follow this Java path.
I don't like when non-exceptional paths are using exceptions for regular flow (throw exitSuccess()). Makes it hard to grasp how things are being executed.

private RuntimeException doExit(int exitCode) {
RunnerLogging.tearDown();
System.exit(exitCode);
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

That and phantom "throwing" feels like a really weird pattern overall.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is necessary to write throw exitFailure() otherwise Java requires a return value or initialization of a local variable defined sooner, but used after the exit statement.


if (projectMode) {
var result = PackageManager$.MODULE$.Default().loadPackage(file);
if (result.isSuccess()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like just going instanceof woule be easier to read

Copy link
Member Author

Choose a reason for hiding this comment

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

It tried that first. It was a mess. However it might be caused by me writing the switch/case statements incorrectly.

var main = pkg.mainFile();
if (!main.exists()) {
println("Main file does not exist.");
context.context().close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put the whole block in try/finally? It's not obvious if the context is closed in every case that follows.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is

          println("Main file does not exist.");
          context.context().close();
          throw exitFail();

just a few lines above. Try/finally won't help, as exitFail calls System.exit and never returns.

engine/runner/src/main/java/org/enso/runner/Main.java Outdated Show resolved Hide resolved
engine/runner/src/main/java/org/enso/runner/Main.java Outdated Show resolved Hide resolved
engine/runner/src/main/java/org/enso/runner/Main.java Outdated Show resolved Hide resolved
@JaroslavTulach JaroslavTulach changed the title Rewriting CLI launcher to Java Rewriting CLI runner to Java May 2, 2024
@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label May 2, 2024
@JaroslavTulach JaroslavTulach changed the title Rewriting CLI runner to Java Rewriting org.enso.runner.Main to Java May 2, 2024
@mergify mergify bot merged commit 07b720a into develop May 2, 2024
34 of 35 checks passed
@mergify mergify bot deleted the wip/jtulach/EnsoLauncher9749 branch May 2, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants