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

Refactoring eval to allow for full path configuration via a PathConfig parameter. #1954

Merged
merged 10 commits into from
Jun 4, 2024

Conversation

jurgenvinju
Copy link
Member

@jurgenvinju jurgenvinju commented May 31, 2024

  • this introduces one createRascalRuntime function which configures and captures an Evaluator instance.
  • all the other java methods are now pure Rascal

This also prepares for eval not being implemented by an interpreter anymore but by a compiled run-time.
However the duration parameter for timeouts leans on the interruptability of the interpreter
for which there is no known dual in the compiled runtime.

This implementation/design avoids an internal map or cache for run-time configured for specific PathConfig instances. Not keeping a configured evaluator around can severely harm performance when repeatedly calling eval. Before "configurability" we had only one Evaluator instance to cache, but with the PathConfig parameter there are potentially many. By using closures to capture the Evaluator instance, the control for keeping the reference is with the programmer that wants to call eval, on the Rascal call stack by any chance. If the reference is lost the JVM can quickly GC the footprint of the Evaluator, and if they keep the reference they can keep calling into it as often as required.

This fixes #1445

Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 123 lines in your changes missing coverage. Please review.

Project coverage is 49%. Comparing base (5c2892f) to head (3019583).
Report is 3 commits behind head on main.

Current head 3019583 differs from pull request most recent head be91033

Please upload reports for the commit be91033 to get more accurate results.

Files Patch % Lines
src/org/rascalmpl/library/util/Eval.java 0% 123 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              main   #1954   +/-   ##
=======================================
- Coverage       49%     49%   -1%     
- Complexity    6244    6247    +3     
=======================================
  Files          664     664           
  Lines        59512   59566   +54     
  Branches      8629    8635    +6     
=======================================
+ Hits         29320   29330   +10     
- Misses       27995   28043   +48     
+ Partials      2197    2193    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jurgenvinju jurgenvinju marked this pull request as ready for review June 1, 2024 21:22
@jurgenvinju jurgenvinju requested a review from DavyLandman June 2, 2024 08:24
@jurgenvinju jurgenvinju self-assigned this Jun 2, 2024
@jurgenvinju
Copy link
Member Author

Codecov Report

Attention: Patch coverage is 0% with 123 lines in your changes are missing coverage. Please review.

Project coverage is 49%. Comparing base (5c2892f) to head (3019583).
Report is 3 commits behind head on main.

Files Patch % Lines
src/org/rascalmpl/library/util/Eval.java 0% 123 Missing ⚠️
Additional details and impacted files
☔ View full report in Codecov by Sentry. 📢 Have feedback on the report? Share it here.

This CodeCov report seems to be off. The lines in Eval.java that are reported to not be executed are in fact in use via Rascal test functions, which are executed by the test runners. So there is something strange going on.

@jurgenvinju
Copy link
Member Author

This could be the cause of the weird CodeCov reports:

Annotations

1 warning
tests (buildjet-4vcpu-ubuntu-2204-arm)Codecov: Failed to properly create commit: The process '/home/runner/actions-runner/_work/_actions/codecov/codecov-action/v4/dist/codecov' failed with exit code 2Show less --

Annotations
1 warning
tests (buildjet-4vcpu-ubuntu-2204-arm)
Codecov: Failed to properly create commit: The process '/home/runner/actions-runner/_work/_actions/codecov/codecov-action/v4/dist/codecov' failed with exit code 2

Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

I see no real problem, so if we want to squeeze this in before the release, I'm good.

* its running program.
*/
public static class EvaluatorInterruptTimer extends Thread {
private final Evaluator eval;
private final int timeout;
private int elapsed;
Copy link
Member

Choose a reason for hiding this comment

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

looks like elapsed should not be a field, but a local thing for run method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll have a look. haven't touched this code much.

return duration;
}

private static ISourceLocation inferProjectRoot(ISourceLocation member) {
Copy link
Member

Choose a reason for hiding this comment

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

At some point we're going to have to cleanup all the copies of this logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed

* and then stops while informing the given Evaluator object to interrupt
* its running program.
*/
public static class EvaluatorInterruptTimer extends Thread {
Copy link
Member

Choose a reason for hiding this comment

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

If we just want to run something with a delay, we don't need threads since java 8:

AtomicBoolean running = new AtomicBoolean(true);
CompletableFuture
    .delayedExecutor(timeout, TimeUnit.SECONDS)
    .execute(() -> {
       if (running.get()) {
           eval.interrupt();
       }
});

This schedules a block of code to run on the common thread pool of java futures, and skips us having to allocate threads. The returned future can be cancelled if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is older code that I just kept; so I'll leave a refactoring of this kind to a future PR.


public Timer(int timeout) {
public EvaluatorInterruptTimer(Evaluator eval, int timeout) {
Copy link
Member

Choose a reason for hiding this comment

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

if we keep it like this, lets call setDaemon(true) to make sure they won't keep the jvm alive at close time.

Copy link
Member Author

Choose a reason for hiding this comment

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

check

@DavyLandman
Copy link
Member

DavyLandman commented Jun 3, 2024

This could be the cause of the weird CodeCov reports:

Seems to be an open issue, but only for the arm64 runner: codecov/codecov-action#1335

error - 2024-06-01 21:27:57,678 -- Upload failed: {"detail":"Failed token authentication, please double-check that your repository token matches in the Codecov UI, or review the docs https://docs.codecov.com/docs/adding-the-codecov-token"}

however this looks like an error :)

update: this has been fixed now.

@jurgenvinju
Copy link
Member Author

thanks for the review @DavyLandman

@jurgenvinju jurgenvinju merged commit 0931de4 into main Jun 4, 2024
1 check passed
@jurgenvinju jurgenvinju deleted the rewrite-eval branch June 4, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eval::eval requires PathConfig parameter
2 participants