39
39
package com .oracle .graal .python .nodes .attributes ;
40
40
41
41
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
42
+ import com .oracle .graal .python .builtins .objects .str .PString ;
42
43
import com .oracle .graal .python .nodes .PNode ;
43
44
import com .oracle .truffle .api .Assumption ;
44
45
import com .oracle .truffle .api .CompilerDirectives ;
@@ -65,6 +66,14 @@ protected Location getLocationOrNull(Property prop) {
65
66
return prop == null ? null : prop .getLocation ();
66
67
}
67
68
69
+ protected Object attrKey (Object key ) {
70
+ if (key instanceof PString ) {
71
+ return ((PString ) key ).getValue ();
72
+ } else {
73
+ return key ;
74
+ }
75
+ }
76
+
68
77
@ SuppressWarnings ("unused" )
69
78
@ Specialization (guards = {
70
79
"object.getStorage().getShape() == cachedShape" ,
@@ -82,7 +91,7 @@ protected Object updateShapeAndWrite(PythonObject object, Object key, Object val
82
91
@ Specialization (limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)" , //
83
92
guards = {
84
93
"object.getStorage().getShape() == cachedShape" ,
85
- "cachedKey.equals( key) " ,
94
+ "cachedKey == key" ,
86
95
"loc != null" ,
87
96
"loc.canSet(value)"
88
97
}, //
@@ -92,9 +101,10 @@ protected Object updateShapeAndWrite(PythonObject object, Object key, Object val
92
101
})
93
102
protected boolean doDirect (PythonObject object , Object key , Object value ,
94
103
@ Cached ("key" ) Object cachedKey ,
104
+ @ Cached ("attrKey(cachedKey)" ) Object attrKey ,
95
105
@ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
96
106
@ Cached ("cachedShape.getValidAssumption()" ) Assumption layoutAssumption ,
97
- @ Cached ("getLocationOrNull(cachedShape.getProperty(key ))" ) Location loc ) {
107
+ @ Cached ("getLocationOrNull(cachedShape.getProperty(attrKey ))" ) Location loc ) {
98
108
try {
99
109
loc .set (object .getStorage (), value );
100
110
} catch (IncompatibleLocationException | FinalLocationException e ) {
@@ -109,7 +119,7 @@ protected boolean doDirect(PythonObject object, Object key, Object value,
109
119
@ Specialization (limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)" , //
110
120
guards = {
111
121
"object.getStorage().getShape() == cachedShape" ,
112
- "cachedKey.equals( key) " ,
122
+ "cachedKey == key" ,
113
123
"loc == null || !loc.canSet(value)" ,
114
124
"newLoc.canSet(value)"
115
125
}, //
@@ -119,12 +129,13 @@ protected boolean doDirect(PythonObject object, Object key, Object value,
119
129
})
120
130
protected boolean defineDirect (PythonObject object , Object key , Object value ,
121
131
@ Cached ("key" ) Object cachedKey ,
132
+ @ Cached ("attrKey(key)" ) Object attrKey ,
122
133
@ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
123
134
@ Cached ("cachedShape.getValidAssumption()" ) Assumption layoutAssumption ,
124
- @ Cached ("getLocationOrNull(cachedShape.getProperty(key ))" ) Location loc ,
125
- @ Cached ("cachedShape.defineProperty(key , value, 0)" ) Shape newShape ,
135
+ @ Cached ("getLocationOrNull(cachedShape.getProperty(attrKey ))" ) Location loc ,
136
+ @ Cached ("cachedShape.defineProperty(attrKey , value, 0)" ) Shape newShape ,
126
137
@ Cached ("newShape.getValidAssumption()" ) Assumption newLayoutAssumption ,
127
- @ Cached ("getLocationOrNull(newShape.getProperty(key ))" ) Location newLoc ) {
138
+ @ Cached ("getLocationOrNull(newShape.getProperty(attrKey ))" ) Location newLoc ) {
128
139
try {
129
140
newLoc .set (object .getStorage (), value , cachedShape , newShape );
130
141
} catch (IncompatibleLocationException e ) {
@@ -138,7 +149,7 @@ protected boolean defineDirect(PythonObject object, Object key, Object value,
138
149
@ TruffleBoundary
139
150
@ Specialization (replaces = {"doDirect" , "defineDirect" }, guards = {"object.getStorage().getShape().isValid()" })
140
151
protected boolean doIndirect (PythonObject object , Object key , Object value ) {
141
- object .setAttribute (key , value );
152
+ object .setAttribute (attrKey ( key ) , value );
142
153
return true ;
143
154
}
144
155
0 commit comments