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

Dispatch of to_text, is_a & co. on intersection types #12192

Merged
merged 16 commits into from
Feb 12, 2025

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Jan 30, 2025

Pull Request Description

Fixes #11827 by keeping EnsoMultiValue as self when dispatching methods like Any.to_text or Any.is_a. The major changes shall be visible in tests:

Checklist

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

  • All code follows the
    Scala,
    Java,
  • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label Jan 30, 2025
@JaroslavTulach JaroslavTulach self-assigned this Jan 30, 2025
@JaroslavTulach JaroslavTulach marked this pull request as draft January 30, 2025 11:50
@JaroslavTulach JaroslavTulach changed the title Polish to_text on _intersection types_ Polish to_text on intersection types Jan 30, 2025
@JaroslavTulach JaroslavTulach force-pushed the wip/jtulach/MultiValueToText11827 branch from 91597b5 to 3196767 Compare January 30, 2025 14:41
@@ -302,7 +302,7 @@ Object doMultiValue(
if (fnAndType != null) {
var ctx = EnsoContext.get(this);
if (ctx.getBuiltins().any() != fnAndType.getRight()) {
var unwrapSelf = castTo.findTypeOrNull(fnAndType.getRight(), self, false, false);
var unwrapSelf = castTo.findTypeOrNull(fnAndType.getRight(), self, true, false);
Copy link
Member Author

Choose a reason for hiding this comment

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

Reorders the intersection types to make sure the value of the type we dispatch the method to is at EnsoMultiValue.firstDispatch.

@JaroslavTulach
Copy link
Member Author

Now, when dispatch of an instance method allows self to be an EnsoMultiValue we have problems with builtins! They don't want multi value, but they need the right type to be extracted from the multivalue:

To do so we have to change the "builtin prelude code" - e.g. the way we prepare the values before invoking the @BuiltinMethod. The work is blocking progress on this PR, but it should rather be implemented as a separate PR #12201 to make sure compatibility is fully guaranteed.

@enso-bot
Copy link

enso-bot bot commented Feb 5, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-04):

Progress: .

GitHub
Enso Analytics is a self-service data prep and analysis platform designed for data teams. - Benchmark Engine · 3579139
GitHub
We wanted to provide additional context for the work of moving our build system to Bazel, answer common questions, provide some expectations, and explain our long-term goals. So here it is. Goals W...

@enso-bot
Copy link

enso-bot bot commented Feb 6, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-05):

Progress: .

GitHub
Pull Request Description Fixes #7117 by removing State from method signatures and moving it into EnsoContext thread context local variable. Checklist Please ensure that the following checklist has ...

@enso-bot
Copy link

enso-bot bot commented Feb 7, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-06):

Progress: .

Discord
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.

@enso-bot
Copy link

enso-bot bot commented Feb 7, 2025

Jaroslav Tulach reports a new STANDUP for today (2025-02-07):

Progress: .

Discord
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.

mergify bot pushed a commit that referenced this pull request Feb 8, 2025
#12201)

- as #12192 (comment) states:
- there is a need to extract values from `EnsoMultiValue` in the _"builtin method prelude code"_
- to enable _specializations based on type of arguments_, we need to wrap such _prelude_ by a `Node`
- hence introducing `ArgNode` & co.
- it kinda replaces the _"static code emitted"_ by annotation processor
- with Truffle `@Specialization`s done inside of `ArgNode`
- making this all more Truffle-like
@enso-bot
Copy link

enso-bot bot commented Feb 11, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-10):

Progress: .

@JaroslavTulach JaroslavTulach added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Feb 11, 2025
@unfurl-links unfurl-links bot mentioned this pull request Feb 11, 2025
5 tasks
(tripple) -> {
var texts = tripple.as(new TypeLiteral<List<String>>() {});
assertEquals(3, texts.size());
assertStartsWith("(A_Ctor", texts.get(0));
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 no special handling of EnsoMultiValue.to_text anymore. v.to_text dispatches the same as (v:A).to_text.

ab = make_a_and_b

# Checked variant can hide the B part
ab.a_id . is_a A . should_be_true
ab.a_id . is_a B . should_be_false
ab.a_id . is_a B . should_be_true # B is a hidden 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.

Any.is_a uses EnsoMultiValue as self and thus the B remains hidden type

var textType = leak.getBuiltins().text();
var both = new Type[] {intType, textType};
var twentyTwoHello = nn.newValue(both, 2, 0, new Object[] {22L, "Hello"});
assertEquals(23L, addNode.execute(twentyTwoHello, 1L));
Copy link
Member Author

Choose a reason for hiding this comment

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

Verified IntegerNode.Binary accepts EnsoMultiValue

ContextUtils.executeInContext(
ctx,
() -> {
assertEquals(23.1, addNode.execute(22.1, 1L), 0.01);
Copy link
Member Author

Choose a reason for hiding this comment

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

AddNode for Float handles both long as well as double as second argument.

new Type[] {leak.getBuiltins().bool().getType(), leak.getBuiltins().number().getInteger()};
var t = n.newValue(bAndT, 2, 0, new Object[] {true, 300});
var f = n.newValue(bAndT, 2, 0, new Object[] {false, 200});
doCaseOfBoolean(t, f);
Copy link
Member Author

Choose a reason for hiding this comment

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

case bool of needs to handle both Boolean as well as EnsoMultiValue.

MethodDefinition def = new MethodDefinition(pkgName, element, executeMethod, needsFrame);
if (!def.validate(processingEnv)) {
return;
private Element findExecuteMethod(TypeElement e) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Searches for execute method also in super classes, so it finds one provided by Integer.BinaryNode.

@JaroslavTulach JaroslavTulach marked this pull request as ready for review February 11, 2025 16:33
@JaroslavTulach JaroslavTulach requested a review from 4e6 February 11, 2025 16:33
@JaroslavTulach JaroslavTulach changed the title Polish to_text on intersection types Classical dispatch of to_text, is_a & co. on intersection types Feb 11, 2025
@JaroslavTulach JaroslavTulach changed the title Classical dispatch of to_text, is_a & co. on intersection types Dispatch of to_text, is_a & co. on intersection types Feb 12, 2025
@JaroslavTulach JaroslavTulach merged commit 595e0a8 into develop Feb 12, 2025
53 checks passed
@JaroslavTulach JaroslavTulach deleted the wip/jtulach/MultiValueToText11827 branch February 12, 2025 14:35
@@ -165,7 +165,7 @@ add_specs suite_builder =
(c:A&B&C).b_method . should_equal "B method"
(c:A&B&C).c_method . should_equal "C method"

group_builder.specify "default to_text should delegate to one of values" pending="TODO: https://github.com/enso-org/enso/issues/11827" <|
group_builder.specify "default to_text should delegate to one of values" pending="To text doesn't dispatch properly #11827" <|
Copy link
Member

Choose a reason for hiding this comment

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

If this PR fixes #11827 then why is this test still marked as pending?

Does that mean that #11827 is not resolved and shouldn't be closed? Or should we unmark this test and start running it?

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let EnsoMultiValue.to_text delegate to first type to_text
5 participants