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

Members on Atom and Type include inherited methods from Any #12099

Merged
merged 39 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
87cece0
Test members on Atom and Type include inherited methods from Any
Akirathan Jan 21, 2025
bd458d0
Add test for consistency between Meta.get_type_methods and interop me…
Akirathan Jan 21, 2025
58b825b
Type has methods from Any as members
Akirathan Jan 22, 2025
8aa5131
Atom has instance methods from Any as members
Akirathan Jan 22, 2025
ede07e2
Update AtomInteropTest
Akirathan Jan 22, 2025
34bd4e2
Update TypeMembersTest
Akirathan Jan 22, 2025
d8ebddf
Member names are not qualified
Akirathan Jan 22, 2025
8ced357
GetTypeMethodsNode delegates to Type.getMethods
Akirathan Jan 22, 2025
d2c0d2d
Update Meta_Spec test
Akirathan Jan 22, 2025
5bb54a4
Fix Locale.predefined_locale_fields
Akirathan Jan 22, 2025
3ec63bc
Update Array_Spec test
Akirathan Jan 22, 2025
6ed4a20
Fix constants in RuntimeTypesTest
Akirathan Jan 22, 2025
3c6050d
Remove member key size test from ExecCompilerTest
Akirathan Jan 22, 2025
049dd6d
Remove prop size test from DebuggingEnsoTest
Akirathan Jan 22, 2025
d5d7d05
Fix constants in RuntimeErrorsTest
Akirathan Jan 22, 2025
f94e7c1
Merge branch 'develop' into wip/akirathan/12045-type-get-members
Akirathan Jan 22, 2025
cae43f7
Update engine/runtime-integration-tests/src/test/java/org/enso/interp…
Akirathan Jan 23, 2025
9b98189
Add test for members from Number hierarchy
Akirathan Jan 23, 2025
106b35d
Include methods from the whole type hierarchy
Akirathan Jan 23, 2025
2edaa22
Collect expected methods
Akirathan Jan 23, 2025
80e80e4
Keep overriden methods.
Akirathan Jan 23, 2025
e69ce1c
Type.Invoke member uses InvokeCallableNode
Akirathan Jan 24, 2025
07c403c
Don't replace instance methods with static methods from eigen type
Akirathan Jan 24, 2025
8a4d67e
Add minimal reproducer for failing RUntimeErrorsTest
Akirathan Jan 24, 2025
9d99e37
Add tests for MethodResolverNode
Akirathan Jan 24, 2025
b95e3ea
Add MethodInvocationOnTypeConsistencyTest
Akirathan Jan 27, 2025
d14550b
Merge branch 'develop' into wip/akirathan/12045-type-get-members
Akirathan Jan 28, 2025
af32b43
Merge branch 'develop' into wip/akirathan/12045-type-get-members
Akirathan Feb 7, 2025
def8d62
Add ArgumentMappingTest
Akirathan Feb 7, 2025
63f0df0
Use resolveFunction from InvokeMethodNode
Akirathan Feb 7, 2025
8eddeae
Extract shouldPrependSyntheticSelfArg from InvokeMethodNode
Akirathan Feb 7, 2025
5040b02
Ignore consistency tests
Akirathan Feb 12, 2025
f81d2ed
Merge branch 'develop' into wip/akirathan/12045-type-get-members
Akirathan Feb 25, 2025
be6444d
Methods are found on eigen types
Akirathan Feb 25, 2025
9cb327b
When invoking members on type, the type must be first argument
Akirathan Feb 25, 2025
e274bb9
Add TypeMembersTest.builtinMethodIsPresent
Akirathan Feb 25, 2025
f3c6f3a
Fix slow context access error
Akirathan Feb 25, 2025
7ba1361
When invoking members on type, the type must be first argument
Akirathan Feb 25, 2025
d245a4d
fmt
Akirathan Feb 25, 2025
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
21 changes: 19 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Locale.enso
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,25 @@ type Locale
predefined_locale_fields : Vector Text
predefined_locale_fields =
locale_meta = Meta.meta Locale
remove_us = locale_meta.methods + ["Value", "new", "default", "from_language_tag", "from_java", "predefined_locale_fields", "default_widget", "widget_options"]
Meta.Type.Value (Meta.type_of locale_meta.value) . methods . filter (Filter_Condition.Is_In remove_us ..Remove) . sort
methods_to_remove = Vector.build bldr->
bldr.append "Value"
Copy link
Member

Choose a reason for hiding this comment

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

This one should be private unless something horribly breaks.

bldr.append "new"
bldr.append "default"
bldr.append "from_language_tag"
bldr.append "from_java"
bldr.append "java_locale"
bldr.append "predefined_locale_fields"
bldr.append "default_widget"
bldr.append "widget_options"
bldr.append "display_country"
bldr.append "display_variant"
bldr.append "display_language"
bldr.append "variant"
bldr.append "language"
bldr.append "country"
bldr.append "default"
bldr.append_vector_range <| Meta.meta Any . methods
locale_meta . methods . filter (Filter_Condition.Is_In methods_to_remove ..Remove) . sort

## PRIVATE
widget_options : Vector Option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public void redefinedArgument() throws Exception {
var run = module.invokeMember("eval_expression", "My_Type.Value");
var atom = run.newInstance(1, 2, 3, 4);
assertFalse("In spite of error we get an instance back: " + atom, atom.isException());
assertEquals("Just three keys", 3, atom.getMemberKeys().size());
assertTrue("Check a: " + atom.getMemberKeys(), atom.getMemberKeys().contains("a"));
assertTrue("Check b: " + atom.getMemberKeys(), atom.getMemberKeys().contains("b"));
assertTrue("Check c: " + atom.getMemberKeys(), atom.getMemberKeys().contains("c"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public static void closeCtx() throws Exception {
}

private static Value getRef(Value ref) {
return refType.invokeMember("get", ref);
return refType.invokeMember("get", refType, ref);
}

private static Value newRef(Object object) {
return refType.invokeMember("new", object);
return refType.invokeMember("new", refType, object);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,18 +643,10 @@ public void testAtomFieldsAreReadable() {
assertThat(objValue.isInternal(), is(false));
assertThat(objValue.hasReadSideEffects(), is(false));

var field1Prop = objValue.getProperty("field_1");
assertThat(field1Prop.isReadable(), is(true));
assertThat(field1Prop.isNumber(), is(true));
assertThat(field1Prop.asInt(), is(1));

assertThat(objValue.getProperties().size(), is(2));
for (var prop : objValue.getProperties()) {
assertThat(
"Property '" + prop.getName() + "' should be readable",
prop.isReadable(),
is(true));
assertThat(prop.isNumber(), is(true));
for (var propName : List.of("field_1", "field_2")) {
var fieldProp = objValue.getProperty(propName);
assertThat(fieldProp.isReadable(), is(true));
assertThat(fieldProp.isNumber(), is(true));
}
}
}
Expand Down Expand Up @@ -690,13 +682,10 @@ public void testAtomFieldAreReadable_MultipleConstructors() {
assertThat(objValue.isInternal(), is(false));
assertThat(objValue.hasReadSideEffects(), is(false));

assertThat("Has fields f1 and f2", objValue.getProperties().size(), is(2));
for (var prop : objValue.getProperties()) {
assertThat(
"Property '" + prop.getName() + "' should be readable",
prop.isReadable(),
is(true));
assertThat(prop.isNumber(), is(true));
for (var propName : List.of("f1", "f2")) {
var fieldProp = objValue.getProperty(propName);
assertThat(fieldProp.isReadable(), is(true));
assertThat(fieldProp.isNumber(), is(true));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package org.enso.interpreter.test;

import static org.enso.test.utils.ContextUtils.createDefaultContext;
import static org.enso.test.utils.ContextUtils.evalModule;
import static org.enso.test.utils.ContextUtils.executeInContext;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import org.enso.interpreter.Constants.Names;
import org.enso.interpreter.node.callable.resolver.MethodResolverNode;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.data.Type;
import org.enso.test.utils.ContextUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public final class MethodResolutionTest {
private static MethodResolverNode methodResolverNode;
private static Context ctx;

@BeforeClass
public static void initCtx() {
ctx = createDefaultContext();
executeInContext(
ctx,
() -> {
methodResolverNode = MethodResolverNode.getUncached();
return null;
});
}

@AfterClass
public static void disposeCtx() {
ctx.close();
ctx = null;
}

@Test
public void resolveStaticMethodFromAny() {
var myTypeVal =
evalModule(
ctx,
"""
from Standard.Base import all

type My_Type
method self = 42

main = My_Type
""");
executeInContext(
ctx,
() -> {
var myType = unwrapType(myTypeVal);
var symbol = UnresolvedSymbol.build("to_display_text", myType.getDefinitionScope());
var func = methodResolverNode.executeResolution(myType, symbol);
assertThat("to_display_text method is found", func, is(notNullValue()));
assertSingleSelfArgument(func);
return null;
});
}

@Test
public void resolveInstanceMethodFromMyType() {
var myTypeVal =
evalModule(
ctx,
"""
type My_Type
method self = 42

main = My_Type
""",
"Module",
"main");
executeInContext(
ctx,
() -> {
var myType = unwrapType(myTypeVal);
var symbol = UnresolvedSymbol.build("method", myType.getDefinitionScope());
var func = methodResolverNode.executeResolution(myType, symbol);
assertThat("method is found", func, is(notNullValue()));
assertSingleSelfArgument(func);
return null;
});
}

@Test
public void resolveStaticMethodFromMyType() {
var myTypeVal =
evalModule(
ctx,
"""
type My_Type
method = 42

main = My_Type
""",
"Module",
"main");
executeInContext(
ctx,
() -> {
var myType = unwrapType(myTypeVal);
var symbol = UnresolvedSymbol.build("method", myType.getDefinitionScope());
var func = methodResolverNode.executeResolution(myType, symbol);
assertThat("method is found", func, is(notNullValue()));
assertSingleSelfArgument(func);
return null;
});
}

@Test
public void resolveExtensionMethodFromMyType() {
var myTypeVal =
evalModule(
ctx,
"""
type My_Type
My_Type.method = 42

main = My_Type
""",
"Module",
"main");
executeInContext(
ctx,
() -> {
var myType = unwrapType(myTypeVal);
var symbol = UnresolvedSymbol.build("method", myType.getDefinitionScope());
var func = methodResolverNode.executeResolution(myType, symbol);
assertThat("method is found", func, is(notNullValue()));
assertSingleSelfArgument(func);
return null;
});
}

private void assertSingleSelfArgument(Function func) {
assertThat("Has single self argument", func.getSchema().getArgumentsCount(), is(1));
assertThat(
"Has single self argument",
func.getSchema().getArgumentInfos()[0].getName(),
is(Names.SELF_ARGUMENT));
}

private Type unwrapType(Value val) {
var unwrapped = ContextUtils.unwrapValue(ctx, val);
return (Type) unwrapped;
}
}
Loading
Loading