Skip to content

Commit fa8b95e

Browse files
committed
Adopt new InteropLibrary messages hasLanguageId and getLanguageId
1 parent 048c69c commit fa8b95e

File tree

7 files changed

+55
-33
lines changed

7 files changed

+55
-33
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ protected Object getLanguageView(PythonContext context, Object value) {
837837
}
838838

839839
@ExportLibrary(value = InteropLibrary.class, delegateTo = "delegate")
840-
static class ForeignLanguageView implements TruffleObject {
840+
static final class ForeignLanguageView implements TruffleObject {
841841
final Object delegate;
842842

843843
ForeignLanguageView(Object delegate) {
@@ -853,13 +853,14 @@ String toDisplayString(boolean allowSideEffects,
853853

854854
@ExportMessage
855855
@SuppressWarnings("static-method")
856-
boolean hasLanguage() {
856+
boolean hasLanguageId() {
857857
return true;
858858
}
859859

860860
@ExportMessage
861-
Class<? extends TruffleLanguage<?>> getLanguage() {
862-
return PythonLanguage.class;
861+
@SuppressWarnings("static-method")
862+
String getLanguageId() {
863+
return PythonLanguage.ID;
863864
}
864865
}
865866

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
import com.oracle.graal.python.util.PythonUtils;
159159
import com.oracle.truffle.api.CompilerDirectives;
160160
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
161-
import com.oracle.truffle.api.TruffleLanguage;
162161
import com.oracle.truffle.api.dsl.Bind;
163162
import com.oracle.truffle.api.dsl.Cached;
164163
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -234,6 +233,18 @@ public void setIndexedSlots(Object[] indexedSlots) {
234233
this.indexedSlots = indexedSlots;
235234
}
236235

236+
@ExportMessage
237+
@SuppressWarnings("static-method")
238+
public final boolean hasLanguageId() {
239+
return true;
240+
}
241+
242+
@ExportMessage
243+
@SuppressWarnings("static-method")
244+
public final String getLanguageId() {
245+
return PythonLanguage.ID;
246+
}
247+
237248
@ExportMessage
238249
public void writeMember(String key, Object value,
239250
@Bind Node inliningTarget,
@@ -1457,16 +1468,6 @@ boolean isArrayElementReadable(long index) {
14571468
}
14581469
}
14591470

1460-
@ExportMessage
1461-
public boolean hasLanguage() {
1462-
return true;
1463-
}
1464-
1465-
@ExportMessage
1466-
public Class<? extends TruffleLanguage<?>> getLanguage() {
1467-
return PythonLanguage.class;
1468-
}
1469-
14701471
@GenerateUncached
14711472
@GenerateInline
14721473
@GenerateCached(false)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ protected Source getSource() {
877877
return section.getSource();
878878
}
879879

880+
@Override
881+
public abstract boolean isCaptureFramesForTrace(boolean compiledFrame);
882+
880883
@TruffleBoundary
881884
public int bciToLine(int bci, BytecodeNode bytecodeNode) {
882885
SourceSection sourceSection = getSourceSectionForLocation(bci, bytecodeNode);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Arrays;
4444
import java.util.Collections;
4545
import java.util.LinkedHashSet;
46+
import java.util.Map;
4647

4748
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4849
import com.oracle.graal.python.builtins.objects.common.ObjectHashMap;
@@ -63,6 +64,7 @@
6364
import com.oracle.graal.python.util.PythonUtils;
6465
import com.oracle.truffle.api.CompilerDirectives;
6566
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
67+
import com.oracle.truffle.api.TruffleLanguage.Env;
6668
import com.oracle.truffle.api.dsl.Bind;
6769
import com.oracle.truffle.api.dsl.Cached;
6870
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -75,6 +77,7 @@
7577
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
7678
import com.oracle.truffle.api.interop.UnsupportedMessageException;
7779
import com.oracle.truffle.api.library.CachedLibrary;
80+
import com.oracle.truffle.api.nodes.LanguageInfo;
7881
import com.oracle.truffle.api.nodes.Node;
7982
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
8083

@@ -170,20 +173,29 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
170173
Object[] bases,
171174
Node inliningTarget,
172175
PutNode putNode) throws UnsupportedMessageException {
173-
InteropLibrary interopLibrary = InteropLibrary.getUncached();
176+
InteropLibrary interopLibrary = InteropLibrary.getUncached(metaObject);
174177
var context = PythonContext.get(inliningTarget);
175178
String languageName;
176179
try {
177-
languageName = context.getEnv().getLanguageInfo(interopLibrary.getLanguage(metaObject)).getName();
180+
Env env = context.getEnv();
181+
String languageId = interopLibrary.getLanguageId(metaObject);
182+
languageName = getLanguageName(env.getPublicLanguages(), languageId);
183+
if (languageName == null) {
184+
languageName = getLanguageName(env.getInternalLanguages(), languageId);
185+
}
186+
if (languageName == null) {
187+
languageName = languageId;
188+
}
178189
} catch (UnsupportedMessageException e) {
179190
// some objects might not expose a language. Use "Foreign" as default
180191
languageName = "Foreign";
181192
}
182-
languageName = languageName.equals("Host") ? "Java" : languageName;
193+
languageName = languageName.equals("host") ? "Java" : languageName;
194+
Object metaObjMetaQualifiedName = interopLibrary.getMetaQualifiedName(metaObject);
183195
var className = PythonUtils.toTruffleStringUncached(String.format(
184196
"%s_%s_generated",
185197
languageName,
186-
interopLibrary.getMetaQualifiedName(metaObject)));
198+
metaObjMetaQualifiedName));
187199

188200
// use length + 1 to make space for the foreign class
189201
var basesWithForeign = Arrays.copyOf(bases, bases.length + 1, PythonAbstractClass[].class);
@@ -196,7 +208,7 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
196208
// Catch the error to additionally print the collected classes and specify the error
197209
// occurred during class creation
198210
throw PRaiseNode.raiseWithCauseStatic(inliningTarget, PythonBuiltinClassType.TypeError, e, ErrorMessages.INTEROP_CLASS_CREATION_NOT_POSSIBLE,
199-
interopLibrary.getMetaQualifiedName(metaObject),
211+
metaObjMetaQualifiedName,
200212
Arrays.toString(basesWithForeign));
201213
}
202214
var module = context.lookupBuiltinModule(BuiltinNames.T_POLYGLOT);
@@ -207,6 +219,14 @@ private static PythonClass buildClassAndRegister(Object foreignObject,
207219
return pythonClass;
208220
}
209221

222+
private static String getLanguageName(Map<String, LanguageInfo> languages, String languageId) {
223+
LanguageInfo languageInfo = languages.get(languageId);
224+
if (languageInfo != null) {
225+
return languageInfo.getName();
226+
}
227+
return null;
228+
}
229+
210230
@TruffleBoundary
211231
private static Object lookupWithInheritance(Node inliningTarget, Object foreignObject, Object metaObject) {
212232
InteropLibrary interopLibrary = InteropLibrary.getUncached();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonLocalScope.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -46,7 +46,6 @@
4646
import com.oracle.graal.python.PythonLanguage;
4747
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
4848
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
49-
import com.oracle.truffle.api.TruffleLanguage;
5049
import com.oracle.truffle.api.frame.Frame;
5150
import com.oracle.truffle.api.frame.FrameDescriptor;
5251
import com.oracle.truffle.api.frame.MaterializedFrame;
@@ -182,14 +181,14 @@ SourceSection getSourceLocation() throws UnsupportedMessageException {
182181

183182
@ExportMessage
184183
@SuppressWarnings("static-method")
185-
boolean hasLanguage() {
184+
boolean hasLanguageId() {
186185
return true;
187186
}
188187

189188
@ExportMessage
190189
@SuppressWarnings("static-method")
191-
Class<? extends TruffleLanguage<?>> getLanguage() {
192-
return PythonLanguage.class;
190+
String getLanguageId() {
191+
return PythonLanguage.ID;
193192
}
194193

195194
@ExportMessage

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonMapScope.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.graal.python.nodes.BuiltinNames;
4545
import com.oracle.graal.python.runtime.PythonContext;
4646
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
47-
import com.oracle.truffle.api.TruffleLanguage;
4847
import com.oracle.truffle.api.dsl.Bind;
4948
import com.oracle.truffle.api.dsl.Cached;
5049
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -284,14 +283,14 @@ void removeMember(String member,
284283

285284
@ExportMessage
286285
@SuppressWarnings("static-method")
287-
boolean hasLanguage() {
286+
boolean hasLanguageId() {
288287
return true;
289288
}
290289

291290
@ExportMessage
292291
@SuppressWarnings("static-method")
293-
Class<? extends TruffleLanguage<?>> getLanguage() {
294-
return PythonLanguage.class;
292+
String getLanguageId() {
293+
return PythonLanguage.ID;
295294
}
296295

297296
@ExportMessage

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonScopes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.oracle.graal.python.builtins.objects.function.PArguments;
4646
import com.oracle.graal.python.builtins.objects.generator.PGenerator;
4747
import com.oracle.graal.python.builtins.objects.object.PythonObject;
48-
import com.oracle.truffle.api.TruffleLanguage;
4948
import com.oracle.truffle.api.dsl.Bind;
5049
import com.oracle.truffle.api.dsl.Cached;
5150
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -149,14 +148,14 @@ public SourceSection getSourceLocation(
149148

150149
@ExportMessage
151150
@SuppressWarnings("static-method")
152-
boolean hasLanguage() {
151+
boolean hasLanguageId() {
153152
return true;
154153
}
155154

156155
@ExportMessage
157156
@SuppressWarnings("static-method")
158-
Class<? extends TruffleLanguage<?>> getLanguage() {
159-
return PythonLanguage.class;
157+
String getLanguageId() {
158+
return PythonLanguage.ID;
160159
}
161160

162161
@ExportMessage

0 commit comments

Comments
 (0)