147
147
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyUnicodeFromString ;
148
148
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyUnicodeFromWchar ;
149
149
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .ReturnType ;
150
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodes .HPyAttachFunctionTypeNode ;
150
151
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodes .PCallHPyFunction ;
151
152
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyAsPythonObjectNodeGen ;
152
153
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyGetNativeSpacePointerNodeGen ;
153
154
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyRaiseNodeGen ;
154
155
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyTransformExceptionToNativeNodeGen ;
155
156
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .PCallHPyFunctionNodeGen ;
156
157
import com .oracle .graal .python .builtins .objects .cext .hpy .HPyExternalFunctionNodes .HPyCheckFunctionResultNode ;
157
- import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodes .HPyAttachFunctionTypeNode ;
158
158
import com .oracle .graal .python .builtins .objects .common .EmptyStorage ;
159
159
import com .oracle .graal .python .builtins .objects .common .HashMapStorage ;
160
160
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
@@ -1704,12 +1704,17 @@ final Object getMembers(@SuppressWarnings("unused") boolean includeInternal) {
1704
1704
@ ExportMessage
1705
1705
@ ImportStatic (HPyContextMember .class )
1706
1706
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 ) {
1711
1711
return cachedIdx != -1 ;
1712
1712
}
1713
+
1714
+ @ Specialization (replaces = "isMemberReadableCached" )
1715
+ static boolean isMemberReadable (@ SuppressWarnings ("unused" ) GraalHPyContext context , String key ) {
1716
+ return HPyContextMember .getIndex (key ) != -1 ;
1717
+ }
1713
1718
}
1714
1719
1715
1720
@ ExportMessage
@@ -1735,10 +1740,10 @@ abstract static class GraalHPyReadMemberNode extends Node {
1735
1740
1736
1741
public abstract Object execute (GraalHPyContext hpyContext , String key );
1737
1742
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 ) {
1742
1747
// TODO(fa) once everything is implemented, remove this check
1743
1748
if (cachedIdx != -1 ) {
1744
1749
Object value = hpyContext .hpyContextMembers [cachedIdx ];
@@ -1749,6 +1754,12 @@ static Object doMember(GraalHPyContext hpyContext, String key,
1749
1754
CompilerDirectives .transferToInterpreterAndInvalidate ();
1750
1755
throw CompilerDirectives .shouldNotReachHere (String .format ("context function %s not yet implemented: " , key ));
1751
1756
}
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
+ }
1752
1763
}
1753
1764
1754
1765
@ ExportMessage
0 commit comments