Missing conversion of hash key in EqualsNode (#6803)

This commit is contained in:
Jaroslav Tulach 2023-05-23 10:10:22 +02:00 committed by GitHub
parent 7471e38ff6
commit a49743f00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 22 deletions

View File

@ -1,5 +1,22 @@
package org.enso.interpreter.node.expression.builtin.meta;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import org.enso.interpreter.dsl.AcceptsError;
import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode;
import org.enso.interpreter.node.expression.builtin.ordering.CustomComparatorNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.Module;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.atom.Atom;
import org.enso.interpreter.runtime.data.EnsoFile;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.error.WarningsLibrary;
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
import org.enso.interpreter.runtime.scope.ModuleScope;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateUncached;
@ -14,21 +31,6 @@ 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 java.time.LocalDateTime;
import java.time.ZonedDateTime;
import org.enso.interpreter.dsl.AcceptsError;
import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode;
import org.enso.interpreter.node.expression.builtin.ordering.CustomComparatorNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.Module;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.atom.Atom;
import org.enso.interpreter.runtime.data.EnsoFile;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.error.WarningsLibrary;
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
import org.enso.interpreter.runtime.scope.ModuleScope;
@GenerateUncached
public abstract class EqualsComplexNode extends Node {
@ -316,6 +318,7 @@ public abstract class EqualsComplexNode extends Node {
@CachedLibrary("otherHashMap") InteropLibrary otherInterop,
@CachedLibrary(limit = "5") InteropLibrary entriesInterop,
@Cached EqualsNode equalsNode,
@Cached HostValueToEnsoNode keyToEnsoNode,
@Cached HostValueToEnsoNode valueToEnsoNode) {
try {
int selfHashSize = (int) selfInterop.getHashSize(selfHashMap);
@ -326,7 +329,7 @@ public abstract class EqualsComplexNode extends Node {
Object selfEntriesIter = selfInterop.getHashEntriesIterator(selfHashMap);
while (entriesInterop.hasIteratorNextElement(selfEntriesIter)) {
Object selfKeyValue = entriesInterop.getIteratorNextElement(selfEntriesIter);
Object key = entriesInterop.readArrayElement(selfKeyValue, 0);
Object key = keyToEnsoNode.execute(entriesInterop.readArrayElement(selfKeyValue, 0));
Object selfValue =
valueToEnsoNode.execute(entriesInterop.readArrayElement(selfKeyValue, 1));
if (otherInterop.isHashEntryExisting(otherHashMap, key)

View File

@ -1,13 +1,9 @@
package org.enso.interpreter.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.oracle.truffle.api.interop.InteropLibrary;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode;
import org.enso.interpreter.node.expression.builtin.meta.EqualsNode;
import org.enso.interpreter.node.expression.builtin.meta.HashCodeNode;
@ -16,13 +12,16 @@ import org.enso.interpreter.runtime.EnsoContext;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.junit.AfterClass;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import com.oracle.truffle.api.interop.InteropLibrary;
@RunWith(Theories.class)
public class HashCodeTest extends TestBase {
private static Context context;

View File

@ -13,6 +13,7 @@ import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
@ -577,6 +578,15 @@ class ValuesGenerator {
collect.add(v("maps-" + expr, imports, expr, "Map").type());
}
}
if (languages.contains(Language.JAVA)) {
collect.add(ctx.asValue(Collections.emptyMap()));
collect.add(ctx.asValue(Collections.singletonMap("A", 1)));
var map = new HashMap<String,Integer>();
map.put("A", 1);
map.put("B", 2);
map.put("C", 3);
collect.add(ctx.asValue(map));
}
return collect;
}