-
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
Giving TypeOfNode richer query API #11618
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
abf68c0
Giving TypeOfNode richer query API
JaroslavTulach 87e738b
Use TypeOfNode.findAllTypes to get all types associated with a value
JaroslavTulach 9de6986
Test checking behavior of Enso multi value with respect to their types
JaroslavTulach 12ed8a3
Type of a value with warning shouldn't be wrapped in a warning
JaroslavTulach a85e64d
Testing consistency between various TypeOfNode.find methods
JaroslavTulach 39ebae8
Renaming to findAllTypesOrNull to explicitly spell out null being a p…
JaroslavTulach 6ca47ac
Type shall be TruffleObject
JaroslavTulach 89d57ba
TypeOfNode.findTypeOrError never returns null
JaroslavTulach b7eb7ae
Merge remote-tracking branch 'origin/develop' into wip/jtulach/TypeOf…
JaroslavTulach fde1757
Assertion panic on UnsupportedMessageException
JaroslavTulach 55bea9b
Share single instance of CallTarget among all the parametrized tests
JaroslavTulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
...test/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNodeMultiValueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package org.enso.interpreter.node.expression.builtin.meta; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.oracle.truffle.api.RootCallTarget; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import org.enso.interpreter.runtime.data.EnsoMultiValue; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.interpreter.runtime.error.DataflowError; | ||
import org.enso.interpreter.runtime.library.dispatch.TypeOfNode; | ||
import org.enso.interpreter.test.ValuesGenerator; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.enso.test.utils.TestRootNode; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Value; | ||
import org.junit.AfterClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class TypeOfNodeMultiValueTest { | ||
|
||
private static RootCallTarget testTypesCall; | ||
|
||
@Parameterized.Parameter(0) | ||
public Object value; | ||
|
||
@Parameterized.Parameter(1) | ||
public String type; | ||
|
||
@Parameterized.Parameter(2) | ||
public int typeIndex; | ||
|
||
private static Context ctx; | ||
|
||
private static Context ctx() { | ||
if (ctx == null) { | ||
ctx = ContextUtils.defaultContextBuilder().build(); | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
var node = TypeOfNode.create(); | ||
var root = | ||
new TestRootNode( | ||
(frame) -> { | ||
var arg = frame.getArguments()[0]; | ||
var t = node.findTypeOrError(arg); | ||
var all = node.findAllTypesOrNull(arg); | ||
return new Object[] {t, all}; | ||
}); | ||
root.insertChildren(node); | ||
testTypesCall = root.getCallTarget(); | ||
return null; | ||
}); | ||
} | ||
assertNotNull("Test types call initialized", testTypesCall); | ||
return ctx; | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Object[][] allPossibleEnsoInterpreterValues() throws Exception { | ||
var g = ValuesGenerator.create(ctx()); | ||
var typeOf = | ||
ContextUtils.evalModule( | ||
ctx(), | ||
""" | ||
from Standard.Base import all | ||
|
||
typ obj = Meta.type_of obj | ||
main = typ | ||
"""); | ||
var data = new ArrayList<Object[]>(); | ||
for (var polyValue : g.allValues()) { | ||
registerValue(g, typeOf, polyValue, data); | ||
} | ||
return data.toArray(new Object[0][]); | ||
} | ||
|
||
private static void registerValue( | ||
ValuesGenerator g, Value typeOf, Value polyValue, ArrayList<Object[]> data) { | ||
var t = typeOf.execute(polyValue); | ||
if (!polyValue.isNull()) { | ||
assertTrue("Type of " + polyValue + " is " + t, t.isMetaObject()); | ||
var rawValue = ContextUtils.unwrapValue(ctx(), polyValue); | ||
var rawType = ContextUtils.unwrapValue(ctx(), t); | ||
if (rawType instanceof Type type) { | ||
var singleMultiValue = EnsoMultiValue.create(new Type[] {type}, new Object[] {rawValue}); | ||
var n = t.getMetaSimpleName(); | ||
data.add(new Object[] {singleMultiValue, n, 0}); | ||
var rawInt = (Type) ContextUtils.unwrapValue(ctx(), g.typeInteger()); | ||
var secondMultiValue = | ||
EnsoMultiValue.create(new Type[] {rawInt, type}, new Object[] {5L, rawValue}); | ||
data.add(new Object[] {secondMultiValue, n, 1}); | ||
var firstMultiValue = | ||
EnsoMultiValue.create(new Type[] {type, rawInt}, new Object[] {rawValue, 6L}); | ||
data.add(new Object[] {firstMultiValue, n, 0}); | ||
} else { | ||
if (!t.isHostObject()) { | ||
data.add(new Object[] {rawValue, null, -1}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void disposeCtx() throws Exception { | ||
if (ctx != null) { | ||
ctx.close(); | ||
ctx = null; | ||
} | ||
} | ||
|
||
@Test | ||
public void typeOfCheck() { | ||
assertType(value, type, typeIndex); | ||
} | ||
|
||
private static void assertType(Object value, String expectedTypeName, int typeIndex) { | ||
assertNotNull("Value " + value + " should have a type", expectedTypeName); | ||
ContextUtils.executeInContext( | ||
ctx(), | ||
() -> { | ||
var pairResult = (Object[]) testTypesCall.call(value); | ||
var t = pairResult[0]; | ||
var all = (Object[]) pairResult[1]; | ||
|
||
Object symbolType; | ||
if (t instanceof DataflowError) { | ||
assertNull("No types for errors", all); | ||
symbolType = t; | ||
} else { | ||
assertNotNull("All types found for " + value, all); | ||
assertTrue( | ||
"Size is at least " + typeIndex + " but was: " + Arrays.toString(all), | ||
all.length >= typeIndex); | ||
assertEquals("Major type is the same with first of allTypes for" + value, t, all[0]); | ||
symbolType = all[typeIndex]; | ||
} | ||
|
||
var symbolTypeValue = ctx.asValue(symbolType); | ||
assertTrue("It is meta object: " + symbolTypeValue, symbolTypeValue.isMetaObject()); | ||
assertEquals(expectedTypeName, symbolTypeValue.getMetaSimpleName()); | ||
return null; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.
This might make a difference in initialization time for example in
testOnly
command - e.g. when the class is loaded, but no test is executed, right?