Skip to content

Commit 99e23c7

Browse files
committed
Fix: add proper generic case for reading context member
1 parent 1371b5f commit 99e23c7

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@
147147
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.GraalHPyUnicodeFromString;
148148
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.GraalHPyUnicodeFromWchar;
149149
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.ReturnType;
150+
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.HPyAttachFunctionTypeNode;
150151
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.PCallHPyFunction;
151152
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyAsPythonObjectNodeGen;
152153
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyGetNativeSpacePointerNodeGen;
153154
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyRaiseNodeGen;
154155
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyTransformExceptionToNativeNodeGen;
155156
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.PCallHPyFunctionNodeGen;
156157
import com.oracle.graal.python.builtins.objects.cext.hpy.HPyExternalFunctionNodes.HPyCheckFunctionResultNode;
157-
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.HPyAttachFunctionTypeNode;
158158
import com.oracle.graal.python.builtins.objects.common.EmptyStorage;
159159
import com.oracle.graal.python.builtins.objects.common.HashMapStorage;
160160
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
@@ -1704,12 +1704,17 @@ final Object getMembers(@SuppressWarnings("unused") boolean includeInternal) {
17041704
@ExportMessage
17051705
@ImportStatic(HPyContextMember.class)
17061706
static class IsMemberReadable {
1707-
@Specialization(guards = "cachedKey.equals(key)")
1708-
static boolean isMemberReadable(@SuppressWarnings("unused") GraalHPyContext context, @SuppressWarnings("unused") String key,
1709-
@Cached(value = "key", allowUncached = true) @SuppressWarnings("unused") String cachedKey,
1710-
@Cached(value = "getIndex(key)", allowUncached = true) int cachedIdx) {
1707+
@Specialization(guards = "cachedKey.equals(key)", limit = "1")
1708+
static boolean isMemberReadableCached(@SuppressWarnings("unused") GraalHPyContext context, @SuppressWarnings("unused") String key,
1709+
@Cached(value = "key") @SuppressWarnings("unused") String cachedKey,
1710+
@Cached(value = "getIndex(key)") int cachedIdx) {
17111711
return cachedIdx != -1;
17121712
}
1713+
1714+
@Specialization(replaces = "isMemberReadableCached")
1715+
static boolean isMemberReadable(@SuppressWarnings("unused") GraalHPyContext context, String key) {
1716+
return HPyContextMember.getIndex(key) != -1;
1717+
}
17131718
}
17141719

17151720
@ExportMessage
@@ -1735,10 +1740,10 @@ abstract static class GraalHPyReadMemberNode extends Node {
17351740

17361741
public abstract Object execute(GraalHPyContext hpyContext, String key);
17371742

1738-
@Specialization(guards = "cachedKey.equals(key)")
1739-
static Object doMember(GraalHPyContext hpyContext, String key,
1740-
@Cached(value = "key", allowUncached = true) @SuppressWarnings("unused") String cachedKey,
1741-
@Cached(value = "getIndex(key)", allowUncached = true) int cachedIdx) {
1743+
@Specialization(guards = "cachedKey.equals(key)", limit = "1")
1744+
static Object doMemberCached(GraalHPyContext hpyContext, String key,
1745+
@Cached(value = "key") @SuppressWarnings("unused") String cachedKey,
1746+
@Cached(value = "getIndex(key)") int cachedIdx) {
17421747
// TODO(fa) once everything is implemented, remove this check
17431748
if (cachedIdx != -1) {
17441749
Object value = hpyContext.hpyContextMembers[cachedIdx];
@@ -1749,6 +1754,12 @@ static Object doMember(GraalHPyContext hpyContext, String key,
17491754
CompilerDirectives.transferToInterpreterAndInvalidate();
17501755
throw CompilerDirectives.shouldNotReachHere(String.format("context function %s not yet implemented: ", key));
17511756
}
1757+
1758+
@Specialization(replaces = "doMemberCached")
1759+
static Object doMember(GraalHPyContext hpyContext, String key,
1760+
@Cached(value = "key", allowUncached = true) @SuppressWarnings("unused") String cachedKey) {
1761+
return doMemberCached(hpyContext, key, key, HPyContextMember.getIndex(key));
1762+
}
17521763
}
17531764

17541765
@ExportMessage

graalpython/lib-graalpython/modules/hpy/test/test_00_basic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ def test_varargs(self):
203203
""")
204204
assert mod.f(4, 5) == 45
205205

206-
@pytest.mark.skip
207206
def test_builtin_handles(self):
208207
mod = self.make_module("""
209208
HPyDef_METH(f, "f", f_impl, HPyFunc_O)

0 commit comments

Comments
 (0)