147147import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyUnicodeFromString ;
148148import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyUnicodeFromWchar ;
149149import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .ReturnType ;
150+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodes .HPyAttachFunctionTypeNode ;
150151import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodes .PCallHPyFunction ;
151152import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyAsPythonObjectNodeGen ;
152153import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyGetNativeSpacePointerNodeGen ;
153154import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyRaiseNodeGen ;
154155import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyTransformExceptionToNativeNodeGen ;
155156import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .PCallHPyFunctionNodeGen ;
156157import com .oracle .graal .python .builtins .objects .cext .hpy .HPyExternalFunctionNodes .HPyCheckFunctionResultNode ;
157- import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodes .HPyAttachFunctionTypeNode ;
158158import com .oracle .graal .python .builtins .objects .common .EmptyStorage ;
159159import com .oracle .graal .python .builtins .objects .common .HashMapStorage ;
160160import 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
0 commit comments