@@ -94,37 +94,38 @@ static Object noRegisteredClass(Object foreignObject,
94
94
95
95
// Always return ForeignObject for meta objects (classes), because custom behavior should only
96
96
// be added to instances.
97
- @ Specialization (guards = "interopLibrary .isMetaObject(foreignObject) || !interopLibrary .hasMetaObject(foreignObject)" )
97
+ @ Specialization (guards = "objectLibrary .isMetaObject(foreignObject) || !objectLibrary .hasMetaObject(foreignObject)" )
98
98
static Object getClassLookup (Object foreignObject ,
99
- @ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) @ Exclusive InteropLibrary interopLibrary ,
99
+ @ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) @ Exclusive InteropLibrary objectLibrary ,
100
100
@ Shared @ Cached GetForeignObjectClassNode getForeignObjectClassNode ) {
101
101
return getForeignObjectClassNode .execute (foreignObject );
102
102
}
103
103
104
104
@ Specialization (guards = {"isSingleContext()" ,
105
105
"!objectLibrary.isMetaObject(foreignObject)" ,
106
106
"objectLibrary.hasMetaObject(foreignObject)" ,
107
- "objectLibrary .isIdentical(metaClass, cachedMetaClass, metaClassLibrary )" }, limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "getContext().interopTypeRegistryCacheValidAssumption.getAssumption()" )
107
+ "metaObjectLibrary .isIdentical(metaObject, cachedMetaObject, cachedMetaObjectLibrary )" }, limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "getContext().interopTypeRegistryCacheValidAssumption.getAssumption()" )
108
108
static Object getCachedClassLookup (@ SuppressWarnings ("unused" ) Object foreignObject ,
109
109
@ SuppressWarnings ("unused" ) @ CachedLibrary ("foreignObject" ) InteropLibrary objectLibrary ,
110
- @ SuppressWarnings ("unused" ) @ Bind ("getMetaObject(objectLibrary, foreignObject)" ) Object metaClass ,
111
- @ SuppressWarnings ("unused" ) @ Cached (value = "metaClass" ) Object cachedMetaClass ,
112
- @ SuppressWarnings ("unused" ) @ CachedLibrary ("cachedMetaClass" ) InteropLibrary metaClassLibrary ,
113
- @ Cached (value = "lookupUncached($node, foreignObject, cachedMetaClass, metaClassLibrary)" ) Object pythonClass ) {
110
+ @ SuppressWarnings ("unused" ) @ Bind ("getMetaObject(objectLibrary, foreignObject)" ) Object metaObject ,
111
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("metaObject" ) InteropLibrary metaObjectLibrary ,
112
+ @ SuppressWarnings ("unused" ) @ Cached ("metaObject" ) Object cachedMetaObject ,
113
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("cachedMetaObject" ) InteropLibrary cachedMetaObjectLibrary ,
114
+ @ Cached (value = "lookupUncached($node, foreignObject, cachedMetaObject)" ) Object pythonClass ) {
114
115
return pythonClass ;
115
116
}
116
117
117
118
// used to catch the exception
118
- static Object getMetaObject (InteropLibrary interopLibrary , Object foreignObject ) {
119
+ static Object getMetaObject (InteropLibrary objectLibrary , Object foreignObject ) {
119
120
try {
120
- return interopLibrary .getMetaObject (foreignObject );
121
+ return objectLibrary .getMetaObject (foreignObject );
121
122
} catch (UnsupportedMessageException e ) {
122
123
throw CompilerDirectives .shouldNotReachHere (e );
123
124
}
124
125
}
125
126
126
- static Object lookupUncached (Node inliningTarget , Object foreignObject , Object metaObject , InteropLibrary metaClassLibrary ) {
127
- return lookup (inliningTarget , InlinedConditionProfile .getUncached (), foreignObject , metaObject , metaClassLibrary , ObjectHashMapFactory .GetNodeGen .getUncached ());
127
+ static Object lookupUncached (Node inliningTarget , Object foreignObject , Object metaObject ) {
128
+ return lookup (inliningTarget , InlinedConditionProfile .getUncached (), foreignObject , metaObject , InteropLibrary . getUncached () , ObjectHashMapFactory .GetNodeGen .getUncached ());
128
129
}
129
130
130
131
@ Specialization (replaces = "getCachedClassLookup" , guards = {"!objectLibrary.isMetaObject(foreignObject)" , "objectLibrary.hasMetaObject(foreignObject)" })
@@ -140,8 +141,8 @@ static Object getFullLookupNode(Object foreignObject,
140
141
static Object lookup (Node inliningTarget ,
141
142
InlinedConditionProfile builtClassFoundProfile ,
142
143
Object foreignObject ,
143
- Object foreignMetaObject ,
144
- InteropLibrary interopLibrary ,
144
+ Object metaObject ,
145
+ InteropLibrary metaObjectLibrary ,
145
146
GetNode getNode ) {
146
147
try {
147
148
// lookup generated classes
@@ -151,27 +152,27 @@ static Object lookup(Node inliningTarget,
151
152
var possiblePythonClass = getNode .execute (null ,
152
153
inliningTarget ,
153
154
PythonContext .get (inliningTarget ).interopGeneratedClassCache ,
154
- foreignMetaObject ,
155
- interopLibrary .identityHashCode (foreignMetaObject ));
155
+ metaObject ,
156
+ metaObjectLibrary .identityHashCode (metaObject ));
156
157
157
158
return builtClassFoundProfile .profile (inliningTarget , possiblePythonClass != null )
158
159
? possiblePythonClass
159
- : lookupWithInheritance (inliningTarget , foreignObject , foreignMetaObject , interopLibrary );
160
+ : lookupWithInheritance (inliningTarget , foreignObject , metaObject );
160
161
} catch (UnsupportedMessageException e ) {
161
162
throw CompilerDirectives .shouldNotReachHere (e );
162
163
}
163
164
}
164
165
165
166
private static PythonClass buildClassAndRegister (Object foreignObject ,
166
- Object foreignMetaObject ,
167
+ Object metaObject ,
167
168
Object [] bases ,
168
169
Node inliningTarget ,
169
- PutNode putNode ,
170
- InteropLibrary interopLibrary ) throws UnsupportedMessageException {
170
+ PutNode putNode ) throws UnsupportedMessageException {
171
+ InteropLibrary interopLibrary = InteropLibrary . getUncached ();
171
172
var context = PythonContext .get (inliningTarget );
172
173
String languageName ;
173
174
try {
174
- languageName = context .getEnv ().getLanguageInfo (interopLibrary .getLanguage (foreignMetaObject )).getName ();
175
+ languageName = context .getEnv ().getLanguageInfo (interopLibrary .getLanguage (metaObject )).getName ();
175
176
} catch (UnsupportedMessageException e ) {
176
177
// some objects might not expose a language. Use "Foreign" as default
177
178
languageName = "Foreign" ;
@@ -180,7 +181,7 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
180
181
var className = PythonUtils .toTruffleStringUncached (String .format (
181
182
"%s_%s_generated" ,
182
183
languageName ,
183
- interopLibrary .getMetaQualifiedName (foreignMetaObject )));
184
+ interopLibrary .getMetaQualifiedName (metaObject )));
184
185
185
186
// use length + 1 to make space for the foreign class
186
187
var basesWithForeign = Arrays .copyOf (bases , bases .length + 1 , PythonAbstractClass [].class );
@@ -193,19 +194,20 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
193
194
// Catch the error to additionally print the collected classes and specify the error
194
195
// occurred during class creation
195
196
throw PRaiseNode .getUncached ().raiseWithCause (PythonBuiltinClassType .TypeError , e , ErrorMessages .INTEROP_CLASS_CREATION_NOT_POSSIBLE ,
196
- interopLibrary .getMetaQualifiedName (foreignMetaObject ),
197
+ interopLibrary .getMetaQualifiedName (metaObject ),
197
198
Arrays .toString (basesWithForeign ));
198
199
}
199
200
var module = context .lookupBuiltinModule (BuiltinNames .T_POLYGLOT );
200
201
// set module attribute for nicer debug print, but don't add it to the module to prevent
201
202
// access to the class
202
203
pythonClass .setAttribute (SpecialAttributeNames .T___MODULE__ , module .getAttribute (SpecialAttributeNames .T___NAME__ ));
203
- putNode .put (null , inliningTarget , context .interopGeneratedClassCache , foreignMetaObject , InteropLibrary .getUncached ().identityHashCode (foreignMetaObject ), pythonClass );
204
+ putNode .put (null , inliningTarget , context .interopGeneratedClassCache , metaObject , InteropLibrary .getUncached ().identityHashCode (metaObject ), pythonClass );
204
205
return pythonClass ;
205
206
}
206
207
207
208
@ TruffleBoundary
208
- private static Object lookupWithInheritance (Node inliningTarget , Object foreignObject , Object foreignMetaObject , InteropLibrary interopLibrary ) {
209
+ private static Object lookupWithInheritance (Node inliningTarget , Object foreignObject , Object metaObject ) {
210
+ InteropLibrary interopLibrary = InteropLibrary .getUncached ();
209
211
// Try the full and expensive lookup
210
212
try {
211
213
var registry = PythonContext .get (inliningTarget ).interopTypeRegistry ;
@@ -216,23 +218,22 @@ private static Object lookupWithInheritance(Node inliningTarget, Object foreignO
216
218
var possiblePythonClasses = (Object []) getNode .execute (null ,
217
219
inliningTarget ,
218
220
registry ,
219
- foreignMetaObject ,
220
- interopLibrary .identityHashCode (foreignMetaObject ));
221
+ metaObject ,
222
+ interopLibrary .identityHashCode (metaObject ));
221
223
if (possiblePythonClasses != null ) {
222
224
Collections .addAll (foundClasses , possiblePythonClasses );
223
225
}
224
226
225
227
// Now search also for parent classes
226
- searchAllParentClassesBfs (new Object []{foreignMetaObject }, foundClasses , registry , getNode , inliningTarget );
228
+ searchAllParentClassesBfs (new Object []{metaObject }, foundClasses , registry , getNode , inliningTarget );
227
229
228
230
return foundClasses .isEmpty ()
229
231
? GetForeignObjectClassNode .getUncached ().execute (foreignObject )
230
232
: buildClassAndRegister (foreignObject ,
231
- foreignMetaObject ,
233
+ metaObject ,
232
234
foundClasses .toArray (),
233
235
inliningTarget ,
234
- ObjectHashMapFactory .PutNodeGen .getUncached (),
235
- interopLibrary );
236
+ ObjectHashMapFactory .PutNodeGen .getUncached ());
236
237
} catch (UnsupportedMessageException | InvalidArrayIndexException e ) {
237
238
throw CompilerDirectives .shouldNotReachHere (e );
238
239
}
0 commit comments