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

Implement hasLanguage interop message for all enso objects #11538

Merged
merged 29 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
02e77fc
EnsoObject is an abstract class, not an interface.
Akirathan Nov 12, 2024
3ab4f73
Implement public getters in BranchResult
Akirathan Nov 12, 2024
5c5b0b7
Fix compilation of EnsoFile
Akirathan Nov 12, 2024
0e48f21
Add test that all enso values must have language
Akirathan Nov 12, 2024
aa419c0
Revert EnsoException - remove
Akirathan Nov 12, 2024
b30f396
DataflowError and PanicException implement hasLanguage and getLanguage
Akirathan Nov 12, 2024
613f380
DataflowError is not EnsoObject - change signatures in some builtins
Akirathan Nov 12, 2024
c5508db
Merge branch 'develop' into wip/akirathan/enso-object-abstract
Akirathan Nov 13, 2024
c682df0
Add more members to Module.isMemberInvocable.
Akirathan Nov 13, 2024
993399a
Revert "DataflowError and PanicException implement hasLanguage and ge…
Akirathan Nov 13, 2024
130180c
Update the test - test only non-primitive and non-exception values
Akirathan Nov 13, 2024
bea21a6
Fix indexes in CodeLocationsTest
Akirathan Nov 13, 2024
a59a72a
Add more members to Function.isMemberInvocable
Akirathan Nov 13, 2024
1140546
EnsoObject.toDisplayString delegates to toString method
Akirathan Nov 14, 2024
7fa2022
EnsoObject.toDisplayString is behind TruffleBoundary
Akirathan Nov 14, 2024
f0dae47
Warning exports InteropLibrary which delegates to value.
Akirathan Nov 14, 2024
5955ff3
WithWarnings needs to explicitly export toDisplayString.
Akirathan Nov 14, 2024
db225ed
EnsoObject.toDisplayString just throws AssertionError
Akirathan Nov 14, 2024
06d1d4c
AssertionError is behind TruffleBoundary
Akirathan Nov 14, 2024
62aefe5
Implement toDisplayString on some truffle objects
Akirathan Nov 15, 2024
a06c672
Warning exports WarningsLibrary
Akirathan Nov 15, 2024
9f33d74
Revert "Warning exports WarningsLibrary"
Akirathan Nov 18, 2024
92722b8
Add some warnings test
Akirathan Nov 18, 2024
adb2d05
Warning.isNull is always false
Akirathan Nov 18, 2024
9a79c84
Add some unnecessary methods to fix the compilation
Akirathan Nov 18, 2024
46ebbd3
EnsoObject.toDisplayString is abstract
Akirathan Nov 18, 2024
1c56a4c
ImportExportScope.toDisplayString is behind TruffleBoundary.
Akirathan Nov 18, 2024
6dd7ac5
Hide some toDisplayString methods behind TruffleBoundary
Akirathan Nov 18, 2024
965f999
Merge branch 'develop' into wip/akirathan/enso-object-abstract
Akirathan Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.oracle.truffle.api.interop.InteropLibrary;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Predicate;
import org.enso.common.MethodNames;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.type.ConstantsGen;
Expand Down Expand Up @@ -272,6 +274,33 @@ public void numbersAreEitherIntegerOrFloat() throws Exception {
}
}

/**
* Primitive values and exceptions currently don't have an associated language.
*
* <p>TODO[PM]: Will be implemented in https://github.com/enso-org/enso/pull/11468
Copy link
Member

Choose a reason for hiding this comment

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

How do you want to associate a language with java.lang.Long or java.lang.Boolean? What language you'd like to associate with such values? JavaScript? Enso?

Language can only be associated with Enso objects - e.g. subtypes of EnsoObject!

Copy link
Member Author

Choose a reason for hiding this comment

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

How do you want to associate a language with java.lang.Long or java.lang.Boolean? What language you'd like to associate with such values? JavaScript? Enso?

Literal 42 in Enso is really not a literal, it is an atom of type Integer. So you can, e.g., call 42.up_to 80 . each .... The same is true for True, which is not the same as java.lang.Boolean. In the comment, I am talking about Enso "primitives" and not Java primitives.

*/
@Test
public void allEnsoNonPrimitiveValuesHaveLanguage() throws Exception {
var gen = ValuesGenerator.create(ctx, Language.ENSO);
Predicate<Value> isPrimitiveOrException =
(val) -> val.fitsInInt() || val.fitsInDouble() || val.isBoolean() || val.isException();
var nonPrimitiveValues =
gen.allValues().stream().filter(isPrimitiveOrException.negate()).toList();
var interop = InteropLibrary.getUncached();
ContextUtils.executeInContext(
ctx,
() -> {
for (var value : nonPrimitiveValues) {
var unwrappedValue = ContextUtils.unwrapValue(ctx, value);
assertThat(
"Value " + unwrappedValue + " should have associated language",
interop.hasLanguage(unwrappedValue),
is(true));
}
return null;
});
}

@Test
public void compareQualifiedAndSimpleTypeName() throws Exception {
var g = generator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.oracle.truffle.api.interop.InteropLibrary;
import java.util.List;
import org.enso.common.LanguageInfo;
import org.enso.common.MethodNames;
import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.data.hash.EnsoHashMap;
import org.enso.interpreter.runtime.data.hash.HashMapGetNode;
import org.enso.interpreter.runtime.data.hash.HashMapInsertNode;
import org.enso.interpreter.runtime.data.hash.HashMapSizeNode;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.data.vector.ArrayLikeHelpers;
import org.enso.interpreter.runtime.warning.AppendWarningNode;
import org.enso.interpreter.runtime.warning.Warning;
import org.enso.interpreter.runtime.warning.WarningsLibrary;
import org.enso.interpreter.runtime.warning.WithWarnings;
import org.enso.test.utils.ContextUtils;
import org.graalvm.polyglot.Context;
Expand Down Expand Up @@ -194,4 +206,92 @@ public void warningOnAnError() throws Exception {
assertEquals(
"Standard.Base.Error.Error", errorWithWarning.getMetaObject().getMetaQualifiedName());
}

@Test
public void warningsArray_readViaInterop_shouldNotRemoveWarnings() {
ContextUtils.executeInContext(
ctx,
() -> {
var warn1 = Warning.create(ensoContext, 1L, null);
var warn2 = Warning.create(ensoContext, 2L, null);
var arr = ArrayLikeHelpers.wrapEnsoObjects(warn1, warn2);
var interop = InteropLibrary.getUncached();
var warn1FromArr = interop.readArrayElement(arr, 0);
assertThat(
"warn1 and warn1FromArr should be the same reference",
warn1,
is(sameInstance(warn1FromArr)));
var warn2FromArr = interop.readArrayElement(arr, 1);
assertThat(
"warn2 and warn2FromArr should be the same reference",
warn2,
is(sameInstance(warn2FromArr)));
return null;
});
}

@Test
public void warningsArray_collectWarningsViaWarningsLibrary() {
ContextUtils.executeInContext(
ctx,
() -> {
var appendWarnNode = AppendWarningNode.getUncached();
var warnsLib = WarningsLibrary.getUncached();
var hashMapSizeNode = HashMapSizeNode.getUncached();
var hashMapGetNode = HashMapGetNode.getUncached();

var warn1 = Warning.create(ensoContext, 1L, null);
var warn2 = Warning.create(ensoContext, 2L, null);
var warnsMap = createWarningsMap(List.of(warn1, warn2));
var text1 = Text.create("1");
var text2 = Text.create("2");
var arr = ArrayLikeHelpers.wrapEnsoObjects(text1, text2);
var arrWithWarns = appendWarnNode.executeAppend(null, arr, warnsMap);
assertThat(warnsLib.hasWarnings(arrWithWarns), is(true));
var gatheredWarns = warnsLib.getWarnings(arrWithWarns, false);
assertThat("Hash size should be 2", hashMapSizeNode.execute(gatheredWarns), is(2L));
var warn1FromMap =
hashMapGetNode.execute(null, null, gatheredWarns, warn1.getSequenceId(), null);
assertThat(
"Original warning and warning gathered via WarningsLibrary should be the same object",
warn1 == warn1FromMap,
is(true));
return null;
});
}

@Test
public void nothingWithWarn_IsNotRemovedByHostValueToEnsoNode() {
ContextUtils.executeInContext(
ctx,
() -> {
var hostValueToEnsoNode = HostValueToEnsoNode.getUncached();
var warn = Warning.create(ensoContext, ensoContext.getNothing(), null);
var converted = hostValueToEnsoNode.execute(warn);
assertThat(converted, is(sameInstance(warn)));
return null;
});
}

@Test
public void nothingWithWarn_FromMapToArray() {
ContextUtils.executeInContext(
ctx,
() -> {
var warn = Warning.create(ensoContext, ensoContext.getNothing(), null);
var warnsMap = createWarningsMap(List.of(warn));
var warns = Warning.fromMapToArray(warnsMap);
assertThat(warns.length, is(1));
return null;
});
}

private EnsoHashMap createWarningsMap(List<Warning> warns) {
var map = EnsoHashMap.empty();
var mapInsertNode = HashMapInsertNode.getUncached();
for (var warn : warns) {
map = mapInsertNode.execute(null, map, warn.getSequenceId(), warn);
}
return map;
}
}
Loading
Loading