42
42
43
43
import com .oracle .graal .python .builtins .objects .PNone ;
44
44
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
45
+ import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
45
46
import com .oracle .graal .python .nodes .PGuards ;
46
47
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
47
- import com .oracle .graal . python . util . PythonUtils ;
48
+ import com .oracle .truffle . api . dsl . Bind ;
48
49
import com .oracle .truffle .api .dsl .Cached ;
50
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
51
+ import com .oracle .truffle .api .dsl .GenerateCached ;
52
+ import com .oracle .truffle .api .dsl .GenerateInline ;
49
53
import com .oracle .truffle .api .dsl .GenerateUncached ;
50
54
import com .oracle .truffle .api .dsl .ImportStatic ;
51
55
import com .oracle .truffle .api .dsl .Specialization ;
@@ -86,18 +90,26 @@ protected static boolean withAttributes(PBaseException self) {
86
90
return self .getExceptionAttributes () != null ;
87
91
}
88
92
89
- private static Object [] ensureAttrStorage (PBaseException self , StorageFactory factory , SequenceStorageNodes .GetInternalObjectArrayNode getArrayNode , PythonObjectFactory objectFactory ) {
90
- Object [] attributes = self .getExceptionAttributes ();
91
- if (attributes == null ) {
92
- // TODO: cbasca should we raise in case getArgs() is null (due to lazy init of args)?
93
- Object [] args = PythonUtils .EMPTY_OBJECT_ARRAY ;
94
- if (self .getArgs () != null ) {
95
- args = getArrayNode .execute (self .getArgs ().getSequenceStorage ());
93
+ @ GenerateInline
94
+ @ GenerateCached (false )
95
+ @ GenerateUncached
96
+ abstract static class EnsureAttrStorageNode extends Node {
97
+ abstract Object [] execute (Node inliningTarget , PBaseException self , StorageFactory storageFactory );
98
+
99
+ @ Specialization
100
+ static Object [] ensure (Node inliningTarget , PBaseException self , StorageFactory storageFactory ,
101
+ @ Cached ExceptionNodes .GetArgsNode getArgsNode ,
102
+ @ Cached SequenceStorageNodes .GetInternalObjectArrayNode getInternalObjectArrayNode ,
103
+ @ Cached PythonObjectFactory factory ) {
104
+ Object [] attributes = self .getExceptionAttributes ();
105
+ if (attributes == null ) {
106
+ PTuple argsTuple = getArgsNode .execute (inliningTarget , self );
107
+ Object [] args = getInternalObjectArrayNode .execute (argsTuple .getSequenceStorage ());
108
+ attributes = storageFactory .create (args , factory );
109
+ self .setExceptionAttributes (attributes );
96
110
}
97
- attributes = factory .create (args , objectFactory );
98
- self .setExceptionAttributes (attributes );
111
+ return attributes ;
99
112
}
100
- return attributes ;
101
113
}
102
114
103
115
// GET
@@ -111,9 +123,9 @@ public Object getAttrWithStorage(PBaseException self, @SuppressWarnings("unused"
111
123
112
124
@ Specialization (guards = {"isNoValue(none)" , "!withAttributes(self)" })
113
125
public Object getAttrNoStorage (PBaseException self , @ SuppressWarnings ("unused" ) PNone none , int index , StorageFactory factory ,
114
- @ Cached SequenceStorageNodes . GetInternalObjectArrayNode getArrayNode ,
115
- @ Cached PythonObjectFactory objectFactory ) {
116
- Object [] attributes = ensureAttrStorage ( self , factory , getArrayNode , objectFactory );
126
+ @ Bind ( "this" ) Node inliningTarget ,
127
+ @ Shared @ Cached EnsureAttrStorageNode ensureAttrStorageNode ) {
128
+ Object [] attributes = ensureAttrStorageNode . execute ( inliningTarget , self , factory );
117
129
assert attributes != null : "PBaseException attributes field is null" ;
118
130
return getAttrWithStorage (self , none , index , factory );
119
131
}
@@ -129,9 +141,9 @@ public Object setAttrWithStorage(PBaseException self, Object value, int index, @
129
141
130
142
@ Specialization (guards = {"!isNoValue(value)" , "!isDeleteMarker(value)" , "!withAttributes(self)" })
131
143
public Object setAttrNoStorage (PBaseException self , Object value , int index , StorageFactory factory ,
132
- @ Cached SequenceStorageNodes . GetInternalObjectArrayNode getArrayNode ,
133
- @ Cached PythonObjectFactory objectFactory ) {
134
- Object [] attributes = ensureAttrStorage ( self , factory , getArrayNode , objectFactory );
144
+ @ Bind ( "this" ) Node inliningTarget ,
145
+ @ Shared @ Cached EnsureAttrStorageNode ensureAttrStorageNode ) {
146
+ Object [] attributes = ensureAttrStorageNode . execute ( inliningTarget , self , factory );
135
147
assert attributes != null : "PBaseException attributes field is null" ;
136
148
return setAttrWithStorage (self , value , index , factory );
137
149
}
@@ -147,9 +159,9 @@ public Object delAttrWithStorage(PBaseException self, @SuppressWarnings("unused"
147
159
148
160
@ Specialization (guards = {"!isNoValue(value)" , "isDeleteMarker(value)" , "!withAttributes(self)" })
149
161
public Object delAttrNoStorage (PBaseException self , Object value , int index , StorageFactory factory ,
150
- @ Cached SequenceStorageNodes . GetInternalObjectArrayNode getArrayNode ,
151
- @ Cached PythonObjectFactory objectFactory ) {
152
- Object [] attributes = ensureAttrStorage ( self , factory , getArrayNode , objectFactory );
162
+ @ Bind ( "this" ) Node inliningTarget ,
163
+ @ Shared @ Cached EnsureAttrStorageNode ensureAttrStorageNode ) {
164
+ Object [] attributes = ensureAttrStorageNode . execute ( inliningTarget , self , factory );
153
165
assert attributes != null : "PBaseException attributes field is null" ;
154
166
return delAttrWithStorage (self , value , index , factory );
155
167
}
0 commit comments