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

Array methods panic on polyglot arrays like ArrayList #6609

Closed
radeusgd opened this issue May 8, 2023 · 3 comments · Fixed by #6642
Closed

Array methods panic on polyglot arrays like ArrayList #6609

radeusgd opened this issue May 8, 2023 · 3 comments · Fixed by #6642
Assignees
Labels

Comments

@radeusgd
Copy link
Member

radeusgd commented May 8, 2023

The Java ArrayList is treated by Enso like an Array and Array Enso methods do resolve on it. However some of them panic. Apparently, the slice related ones mostly.

See this repro:

from Standard.Base import all
import Standard.Base.Runtime.Debug

polyglot java import java.util.ArrayList

main =
    al = ArrayList.new
    IO.println al
    IO.println (al.is_a Array)
    case al of
        _ : Array -> IO.println "Array"
        _ -> IO.println "not array"
    IO.println (al.take 3)

Expected

[]
True
Array
[]

Actual

[]
True
Array
Execution finished with an error: java.lang.ClassCastException: class com.oracle.truffle.host.HostObject cannot be cast to class org.enso.interpreter.runtime.data.Array (com.oracle.truffle.host.HostObject is in module org.graalvm.truffle of loader 'app'; org.enso.interpreter.runtime.data.Array is in unnamed module of loader com.oracle.graalvm.locator.GraalVMLocator$GuestLangToolsLoader @1c93f6e1)
        at <java> org.enso.interpreter.runtime.type.TypesGen.asArray(TypesGen.java:233)
        at <java> org.enso.interpreter.node.expression.builtin.mutable.SliceArrayMethodGen.handleExecute(SliceArrayMethodGen.java:112)
        at <java> org.enso.interpreter.node.expression.builtin.mutable.SliceArrayMethodGen$1Inlineable.call(SliceArrayMethodGen.java:80)
        at <java> org.enso.interpreter.node.callable.ExecuteCallNode.callInlineable(ExecuteCallNode.java:63)
        at <java> org.enso.interpreter.node.callable.ExecuteCallNodeGen.executeAndSpecialize(ExecuteCallNodeGen.java:106)
        at <java> org.enso.interpreter.node.callable.ExecuteCallNodeGen.executeCall(ExecuteCallNodeGen.java:64)
        at <java> org.enso.interpreter.node.callable.dispatch.CurryNode.doCall(CurryNode.java:155)
        at <java> org.enso.interpreter.node.callable.dispatch.CurryNode.execute(CurryNode.java:108)
        at <java> org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode.invokeCached(InvokeFunctionNode.java:92)
        at <java> org.enso.interpreter.node.callable.dispatch.InvokeFunctionNodeGen.executeAndSpecialize(InvokeFunctionNodeGen.java:102)
        at <java> org.enso.interpreter.node.callable.dispatch.InvokeFunctionNodeGen.execute(InvokeFunctionNodeGen.java:58)
        at <java> org.enso.interpreter.node.callable.InvokeCallableNode.invokeFunction(InvokeCallableNode.java:166)
        at <java> org.enso.interpreter.node.callable.InvokeCallableNodeGen.executeAndSpecialize(InvokeCallableNodeGen.java:117)
        at <java> org.enso.interpreter.node.callable.InvokeCallableNodeGen.execute(InvokeCallableNodeGen.java:101)
        at <java> org.enso.interpreter.node.callable.ApplicationNode.executeGeneric(ApplicationNode.java:97)
        at <java> org.enso.interpreter.node.callable.function.BlockNode.executeGeneric(BlockNode.java:56)
        at <java> org.enso.interpreter.node.ClosureRootNode.execute(ClosureRootNode.java:85)
        at <enso> case_branch(Internal)
        at <enso> Index_Sub_Range.take_helper(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Index_Sub_Range.enso:172-195)
        at <enso> case_branch(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Index_Sub_Range.enso:173:24-100)
        at <enso> Index_Sub_Range.take_helper(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Index_Sub_Range.enso:172-195)
        at <enso> case_branch(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Vector.enso:763:13-84)
        at <enso> Vector.type.take(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Vector.enso:754-763)
        at <enso> Array.take(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Array.enso:245:49-70)
        at <enso> array.main<arg-1>(array.enso:13:17-25)
        at <enso> array.main(array.enso:13:5-26)
@radeusgd
Copy link
Member Author

radeusgd commented May 8, 2023

The same behaviour can be triggered if we get a hold of an ArraySlice (simply by extracting the to_array from the insides of a sliced Vector/Array):

from Standard.Base import all
import Standard.Base.Runtime.Debug

main =
    a = [1,2,3,4].to_array
    IO.println a
    IO.println (Meta.get_qualified_type_name a)
    IO.println (a.is_a Array)
    b = a.take 3 . to_array
    IO.println b
    IO.println (Meta.get_qualified_type_name b)
    IO.println (b.is_a Array)
    IO.println (b.drop 1)

yielding

[1, 2, 3, 4]
Standard.Base.Data.Array.Array
True
[1, 2, 3]
Nothing
True
Execution finished with an error: java.lang.ClassCastException: class org.enso.interpreter.runtime.data.ArraySlice cannot be cast to class org.enso.interpreter.runtime.data.Array (org.enso.interpreter.runtime.data.ArraySlice and org.enso.interpreter.runtime.data.Array are in unnamed module of loader com.oracle.graalvm.locator.GraalVMLocator$GuestLangToolsLoader @1c93f6e1)
        at <java> org.enso.interpreter.runtime.type.TypesGen.asArray(TypesGen.java:233)
        at <java> org.enso.interpreter.node.expression.builtin.mutable.SliceArrayMethodGen.handleExecute(SliceArrayMethodGen.java:112)
        at <java> org.enso.interpreter.node.expression.builtin.mutable.SliceArrayMethodGen$1Inlineable.call(SliceArrayMethodGen.java:80)
        at <java> org.enso.interpreter.node.callable.ExecuteCallNode.callInlineable(ExecuteCallNode.java:63)
        at <java> org.enso.interpreter.node.callable.ExecuteCallNodeGen.executeAndSpecialize(ExecuteCallNodeGen.java:106)
        at <java> org.enso.interpreter.node.callable.ExecuteCallNodeGen.executeCall(ExecuteCallNodeGen.java:64)
        at <java> org.enso.interpreter.node.callable.dispatch.CurryNode.doCall(CurryNode.java:155)
        at <java> org.enso.interpreter.node.callable.dispatch.CurryNode.execute(CurryNode.java:108)
        at <java> org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode.invokeCached(InvokeFunctionNode.java:92)
        at <java> org.enso.interpreter.node.callable.dispatch.InvokeFunctionNodeGen.executeAndSpecialize(InvokeFunctionNodeGen.java:102)
        at <java> org.enso.interpreter.node.callable.dispatch.InvokeFunctionNodeGen.execute(InvokeFunctionNodeGen.java:58)
        at <java> org.enso.interpreter.node.callable.InvokeCallableNode.invokeFunction(InvokeCallableNode.java:166)
        at <java> org.enso.interpreter.node.callable.InvokeCallableNodeGen.executeAndSpecialize(InvokeCallableNodeGen.java:117)
        at <java> org.enso.interpreter.node.callable.InvokeCallableNodeGen.execute(InvokeCallableNodeGen.java:101)
        at <java> org.enso.interpreter.node.callable.ApplicationNode.executeGeneric(ApplicationNode.java:97)
        at <java> org.enso.interpreter.node.callable.function.BlockNode.executeGeneric(BlockNode.java:56)
        at <java> org.enso.interpreter.node.ClosureRootNode.execute(ClosureRootNode.java:85)
        at <enso> case_branch(Internal)
        at <enso> Index_Sub_Range.drop_helper(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Index_Sub_Range.enso:222-247)
        at <enso> Vector.type.drop(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Vector.enso:774:9-80)
        at <enso> Array.drop(C:\NBO\enso\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Base\0.0.0-dev\src\Data\Array.enso:255:49-70)
        at <enso> array2.main<arg-1>(array2.enso:13:17-24)
        at <enso> array2.main(array2.enso:13:5-25)

radeusgd added a commit that referenced this issue May 8, 2023
@radeusgd
Copy link
Member Author

radeusgd commented May 8, 2023

In f927d28 I disabled one of the tests that has started failing once I changed Vector/Array to_display_text to rely on short_display_text. Once this bug is fixed, that test needs to be re-enabled.

@jdunkerley jdunkerley moved this from ❓New to 📤 Backlog in Issues Board May 9, 2023
@jdunkerley jdunkerley added this to the Design Partners milestone May 9, 2023
radeusgd added a commit that referenced this issue May 9, 2023
radeusgd added a commit that referenced this issue May 9, 2023
@hubertp hubertp removed the triage label May 11, 2023
@mergify mergify bot closed this as completed in #6642 May 11, 2023
mergify bot pushed a commit that referenced this issue May 11, 2023
Fixes #6609 by
- e380e64 - running whole `Vector_Spec` on `java.util.ArrayList`
- 9b1229f - introducing a node to handle interop values

# Important Notes
Contains additional DSL processor fix:
- 415623d - to not crash the compiler, but to properly report compiler error
@github-project-automation github-project-automation bot moved this from 📤 Backlog to 🟢 Accepted in Issues Board May 11, 2023
@enso-bot
Copy link

enso-bot bot commented May 12, 2023

Jaroslav Tulach reports a new STANDUP for yesterday (2023-05-11):

Progress: - Implemented polyglot Array.slice: #6642
- BindingsMap is still broken, but less: 7f6c0d8
- bookclub: https://discord.com/channels/401396655599124480/1105841836670591050/1106145205985480804
- today's bookclub: https://discord.com/channels/401396655599124480/1106160191524839494/1106196705495498793
- standup & discussion about rounding & nodes It should be finished by 2023-05-11.

Next Day: Continue fighting with BindingsMap.

Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants