-
Notifications
You must be signed in to change notification settings - Fork 328
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
Conversation
to_text
on _intersection types_to_text
on intersection types
…s via StructsLibrary
91597b5
to
3196767
Compare
@@ -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); |
There was a problem hiding this comment.
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
.
Now, when dispatch of an instance method allows To do so we have to change the "builtin prelude code" - e.g. the way we prepare the values before invoking the |
Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-04): Progress: .
|
Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-05): Progress: .
|
Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-06): Progress: .
|
Jaroslav Tulach reports a new STANDUP for today (2025-02-07): Progress: .
|
#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
Jaroslav Tulach reports a new STANDUP for yesterday (2025-02-10): Progress: .
|
(tripple) -> { | ||
var texts = tripple.as(new TypeLiteral<List<String>>() {}); | ||
assertEquals(3, texts.size()); | ||
assertStartsWith("(A_Ctor", texts.get(0)); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
to_text
on intersection typesto_text
, is_a
& co. on intersection types
to_text
, is_a
& co. on intersection typesto_text
, is_a
& co. on intersection types
@@ -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" <| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Description
Fixes #11827 by keeping
EnsoMultiValue
asself
when dispatching methods likeAny.to_text
orAny.is_a
. The major changes shall be visible in tests:to_text
forEnsoMultiValue
IntegerNode
had to be updated - the whole package to be ready forEnsoMultiValue
beingself
case of
support updated to handleEnsoMultiValue
execute
method extended to superclassesChecklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,