-
Notifications
You must be signed in to change notification settings - Fork 323
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
StackOverflowError in sort called on numpy array. #7677
Labels
--bug
Type: bug
--data corruption or loss
Important: data corruption or loss
--low-performance
-compiler
Comments
JaroslavTulach
added
--bug
Type: bug
-compiler
--low-performance
--data corruption or loss
Important: data corruption or loss
labels
Aug 28, 2023
Reported to GraalVM guys as bug. |
Brutal workaround that converts diff --git engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java
index 25d58ecd0b..9e6e74b6df 100644
--- engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java
+++ engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/interop/syntax/HostValueToEnsoNode.java
@@ -8,13 +8,17 @@ import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
+import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
+import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
import org.enso.interpreter.node.expression.foreign.CoerceNothing;
+import org.enso.interpreter.runtime.data.EnsoObject;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.error.WarningsLibrary;
@@ -92,6 +96,37 @@ public abstract class HostValueToEnsoNode extends Node {
return coerceNothing.execute(o);
}
+ @Specialization(guards = "isNumpyFloat(iop, o)")
+ Object doNumpyFloat(
+ TruffleObject o, @Shared("iop") @CachedLibrary(limit = "3") InteropLibrary iop) {
+ try {
+ var n = iop.invokeMember(o, "__float__");
+ if (iop.fitsInDouble(n)) {
+ return iop.asDouble(n);
+ }
+ } catch (UnsupportedMessageException
+ | ArityException
+ | UnknownIdentifierException
+ | UnsupportedTypeException ex) {
+ }
+ return o;
+ }
+
+ static boolean isNumpyFloat(InteropLibrary iop, Object o) {
+ if (o instanceof EnsoObject) {
+ return false;
+ }
+ try {
+ if (iop.hasMetaObject(o)) {
+ var meta = iop.getMetaObject(o);
+ var fqn = iop.asString(iop.getMetaQualifiedName(meta));
+ return fqn.startsWith("numpy.float");
+ }
+ } catch (UnsupportedMessageException ex) {
+ }
+ return false;
+ }
+
@Fallback
Object doOther(Object o) {
return o;
|
2 tasks
mergify bot
pushed a commit
that referenced
this issue
Sep 19, 2023
Closes #7677 by eliminating the _stackoverflow execption_. In general it seems _too adventurous_ to walk members of random foreign objects. There can be anything including cycles. Rather than trying to be too smart in these cases, let's just rely on `InteropLibrary.isIdentical` message. # Important Notes Calling `sort` on the `numpy` array no longer yields an error, but the array isn't sorted - that needs a fix on the Python side: oracle/graalpython#354 - once it is in, the elements will be treated as numbers and the sorting happens automatically (without any changes in Enso code).
github-project-automation
bot
moved this from 👁️ Code review
to 🟢 Accepted
in Issues Board
Sep 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
--bug
Type: bug
--data corruption or loss
Important: data corruption or loss
--low-performance
-compiler
The numpy example can be extended to invoke
arr.sort
- then it gets into endless loop inEqualscomplexNode.equalsInteropObjectWithMembers
wheree.g. comparing
PythonAbstractNativeObject
is repeated many, many times.The text was updated successfully, but these errors were encountered: