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

Refactor common SPI logic, handle SPI registrations with missing Enso library #11722

Merged
merged 18 commits into from
Dec 3, 2024

Conversation

radeusgd
Copy link
Member

@radeusgd radeusgd commented Nov 29, 2024

Pull Request Description

Important Notes

Checklist

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

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@radeusgd radeusgd added CI: No changelog needed Do not require a changelog entry for this PR. x-refactor Changes that should not be visible to the end-user labels Nov 29, 2024
@radeusgd radeusgd self-assigned this Nov 29, 2024
@radeusgd
Copy link
Member Author

radeusgd commented Nov 29, 2024

Cloud tests:

GitHub
Enso Analytics is a self-service data prep and analysis platform designed for data teams. - Extra Nightly Tests · 162231c

@radeusgd radeusgd marked this pull request as ready for review November 29, 2024 17:54
@radeusgd
Copy link
Member Author

When we run the Native Image with the unexpected SPI registrations, we should get 1 warning in the logs per each registration:
image

Base automatically changed from wip/jtulach/Module_Does_Not_Exist to develop November 29, 2024 19:05
@mergify mergify bot requested review from 4e6, hubertp and Akirathan as code owners November 29, 2024 19:05
@radeusgd radeusgd force-pushed the wip/radeusgd/fix-spi-native-image branch from ea7bd86 to 3f41674 Compare November 29, 2024 19:06
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Now, when the whole EnsoServiceLoader infrastructure is being revamped, can we also rename the implementation classes, please?

I'd suggest to more closely mimic the API of ServiceLoader just tailor it to Enso needs. E.g. create EnsoServiceLoader and its nested class Provider.

Few comments and one (hopefully) helpful suggestion left inline.

return getTypeObject() != null;
}

protected static class Loader<T extends AbstractEnsoTypeSPI> {
Copy link
Member

Choose a reason for hiding this comment

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

Missing documentation. I would make this class the entry point for this "SPI infrastructure" - e.g. a top level class.

import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Value;

public abstract class AbstractEnsoTypeSPI {
Copy link
Member

Choose a reason for hiding this comment

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

I belive the proper name of this machinery is EnsoServiceLoader. The top most class should be the "loader". The inner class should represent the item (any reason why not call it Provider just like java.util..ServiceLoader does?).

cachedTypeObject = EnsoMeta.getType(getModuleName(), getTypeName());
} catch (PolyglotException e) {
// Currently I have not found a way to get the type/class of the exception, so we rely on
// the message.
Copy link
Member

Choose a reason for hiding this comment

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

e.getGuestValue().getMetaObject() should give you access to the exception Enso type.

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 was trying it and IIRC getGuestValue was null.

Copy link
Member Author

Choose a reason for hiding this comment

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

At least that was the case in Native Image build, the only place where this error is relevant (it does not happen in JVM mode)

import org.graalvm.polyglot.Value;

/** A base class for an Enso service backed by an Enso type. */
public abstract class EnsoService {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to make this EnsoServiceLoader.Provider inner class, but I can live with outer class as well.

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 don't think this is a provider.

Our Loader scheme omits the provider abstraction as it seems unnecessary in this setup. Note that all the ServiceLoader.Provider does is have a get method that allows to extract the underlying type T (from ServiceLoader<T>). In our case, EnsoService is the base type for "that T" - i.e. it is the bound in EnsoServiceLoader<? extends EnsoService>. So they server a bit different purposes and I don't think the name Provider would be fitting.

@radeusgd radeusgd added the CI: Ready to merge This PR is eligible for automatic merge label Dec 2, 2024
@mergify mergify bot merged commit 498b506 into develop Dec 3, 2024
37 of 38 checks passed
@mergify mergify bot deleted the wip/radeusgd/fix-spi-native-image branch December 3, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge x-refactor Changes that should not be visible to the end-user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native Image run includes SPI for libraries that are not loaded, leading to crashes
4 participants