Skip to content

Commit ba8d12f

Browse files
committed
[GR-33173] Migrate to new context reference API - removing PythonLanguage.getCore()
1 parent 14230e3 commit ba8d12f

File tree

28 files changed

+95
-97
lines changed

28 files changed

+95
-97
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "61fd7e543d7aec3ee0f034e1405fe587056ee001" }
1+
{ "overlay": "352b1bc9f0e8a7806cb2135439f921a30b879d33" }

graalpython/com.oracle.graal.python.benchmarks/java/com/oracle/graal/python/benchmarks/parser/Deserializing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void setup() {
7676
public void execute(Blackhole bh) {
7777
for (int n = 0; n < parsingCycles; n++) {
7878
for (Item serialization : serializations) {
79-
bh.consume(parser.deserialize(serialization.data));
79+
bh.consume(parser.deserialize(core, serialization.data));
8080
}
8181
}
8282
}
@@ -89,7 +89,7 @@ private List<Item> createSerializations() {
8989
PythonSSTNodeFactory sstFactory = new PythonSSTNodeFactory(core, source, parser);
9090
PythonParserImpl.CacheItem item = parser.parseWithANTLR(PythonParser.ParserMode.File, 0, core, sstFactory, source, null, null);
9191
SourceSection section = source.createSection(0, source.getLength());
92-
result.add(new Item(PythonParserImpl.serialize(section, item.getAntlrResult(), item.getGlobalScope(), true)));
92+
result.add(new Item(PythonParserImpl.serialize(core, section, item.getAntlrResult(), item.getGlobalScope(), true)));
9393
} catch (RuntimeException e) {
9494
// do nothing
9595
}

graalpython/com.oracle.graal.python.benchmarks/java/com/oracle/graal/python/benchmarks/parser/Serializing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void execute(Blackhole bh) {
6565
for (int n = 0; n < parsingCycles; n++) {
6666
for (PythonParserImpl.CacheItem item : ssts) {
6767
SourceSection section = item.getSource().createSection(0, item.getSource().getLength());
68-
bh.consume(PythonParserImpl.serialize(section, item.getAntlrResult(), item.getGlobalScope(), true));
68+
bh.consume(PythonParserImpl.serialize(core, section, item.getAntlrResult(), item.getGlobalScope(), true));
6969
}
7070
}
7171
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/SSTSerializationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,10 +1268,10 @@ public void checkSerialization(Source source) throws Exception {
12681268
checkScopeSerialization(parserScope);
12691269
Assert.assertNotNull("Parser result is null", parserResult);
12701270
// serialize the source
1271-
byte[] serializeResult = serializer.serialize(parserResult);
1271+
byte[] serializeResult = serializer.serialize(context.getCore(), parserResult);
12721272
Assert.assertNotNull("Serialized data are null", serializeResult);
12731273
// and get the tree from serialized data
1274-
RootNode deserialize = serializer.deserialize(serializeResult);
1274+
RootNode deserialize = serializer.deserialize(context.getCore(), serializeResult);
12751275

12761276
Assert.assertNotNull("Deserialized result is null", parserResult);
12771277
// compare the tree from parser with the tree from serializer
@@ -1535,7 +1535,7 @@ public long[] getTimes(File file) throws Exception {
15351535

15361536
PythonCodeSerializer serializer = context.getCore().getSerializer();
15371537
startFile = System.nanoTime();
1538-
byte[] serializeResult = serializer.serialize(parserResult);
1538+
byte[] serializeResult = serializer.serialize(context.getCore(), parserResult);
15391539
end = System.nanoTime();
15401540
result[1] = end - startFile;
15411541
TruffleFile serFile = context.getEnv().getInternalTruffleFile(file.getAbsolutePath() + ".pyc");
@@ -1550,7 +1550,7 @@ public long[] getTimes(File file) throws Exception {
15501550
TruffleFile tFile = context.getEnv().getInternalTruffleFile(file.getAbsolutePath() + ".pyc");
15511551
byte[] desbytes = tFile.readAllBytes();
15521552
startMemory = System.nanoTime();
1553-
serializer.deserialize(desbytes);
1553+
serializer.deserialize(context.getCore(), desbytes);
15541554
end = System.nanoTime();
15551555
result[2] = end - startMemory;
15561556
result[5] = end - startFile;

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/StringUtilsTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
import org.junit.Assert;
4444
import org.junit.Test;
4545

46-
import com.oracle.graal.python.PythonLanguage;
4746
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4847
import com.oracle.graal.python.parser.sst.StringUtils;
48+
import com.oracle.graal.python.runtime.PythonContext;
4949
import com.oracle.graal.python.runtime.PythonParser.ErrorType;
5050
import com.oracle.graal.python.runtime.PythonParser.ParserErrorCallback;
5151
import com.oracle.truffle.api.nodes.Node;
@@ -78,8 +78,8 @@ public void warn(PythonBuiltinClassType type, String format, Object... args) {
7878
}
7979

8080
@Override
81-
public PythonLanguage getLanguage() {
82-
return null;
81+
public PythonContext getContext() {
82+
return PythonContext.get(null);
8383
}
8484
};
8585

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ protected CallTarget parse(ParsingRequest request) {
386386
if (bytes.length == 0) {
387387
return createCachedCallTarget(l -> new BadOPCodeNode(l), BadOPCodeNode.class);
388388
}
389-
return PythonUtils.getOrCreateCallTarget(core.getSerializer().deserialize(bytes));
389+
return PythonUtils.getOrCreateCallTarget(core.getSerializer().deserialize(core, bytes));
390390
}
391391
for (int optimize = 0; optimize < MIME_TYPE_EVAL.length; optimize++) {
392392
if (MIME_TYPE_EVAL[optimize].equals(source.getMimeType())) {
@@ -608,10 +608,6 @@ public String getHome() {
608608
return getLanguageHome();
609609
}
610610

611-
public static Python3Core getCore() {
612-
return PythonContext.get(null).getCore();
613-
}
614-
615611
/**
616612
* If this object can be cached in the AST.
617613
*/

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,11 @@ public Python3Core(PythonParser parser, boolean isNativeSupportAllowed) {
608608
this.coreFiles = initializeCoreFiles();
609609
}
610610

611-
@Override
612611
public PythonLanguage getLanguage() {
613612
return singletonContext.getLanguage();
614613
}
615614

615+
@Override
616616
public PythonContext getContext() {
617617
return singletonContext;
618618
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ private static Object[] getTimeStruct(long seconds, boolean local) {
197197
}
198198

199199
@TruffleBoundary
200-
private static int[] getIntLocalTimeStruct(long seconds) {
200+
private static int[] getIntLocalTimeStruct(PythonContext context, long seconds) {
201201
int[] timeStruct = new int[9];
202202
Instant instant = Instant.ofEpochSecond(seconds);
203-
ZoneId zone = PythonContext.get(null).getEnv().getTimeZone();
203+
ZoneId zone = context.getEnv().getTimeZone();
204204
ZonedDateTime zonedDateTime = LocalDateTime.ofInstant(instant, zone).atZone(zone);
205205
timeStruct[TM_YEAR] = zonedDateTime.getYear();
206206
timeStruct[TM_MON] = zonedDateTime.getMonth().ordinal() + 1; /* Want January == 1 */
@@ -870,7 +870,7 @@ public String formatTime(String format, @SuppressWarnings("unused") PNone time)
870870
if (format.indexOf(0) > -1) {
871871
throw raise(PythonBuiltinClassType.ValueError, ErrorMessages.EMBEDDED_NULL_CHARACTER);
872872
}
873-
return format(format, getIntLocalTimeStruct((long) timeSeconds()));
873+
return format(format, getIntLocalTimeStruct(PythonContext.get(this), (long) timeSeconds()));
874874
}
875875

876876
@Specialization
@@ -932,7 +932,7 @@ public abstract static class CTimeNode extends PythonBuiltinNode {
932932
@Specialization
933933
public String localtime(VirtualFrame frame, Object seconds,
934934
@Cached ToLongTime toLongTime) {
935-
return format(getIntLocalTimeStruct(toLongTime.execute(frame, seconds)));
935+
return format(getIntLocalTimeStruct(PythonContext.get(this), toLongTime.execute(frame, seconds)));
936936
}
937937

938938
protected static String format(int[] tm) {
@@ -955,7 +955,7 @@ public abstract static class ASCTimeNode extends PythonBuiltinNode {
955955

956956
@Specialization
957957
public String localtime(@SuppressWarnings("unused") PNone time) {
958-
return format(getIntLocalTimeStruct((long) timeSeconds()));
958+
return format(getIntLocalTimeStruct(PythonContext.get(this), (long) timeSeconds()));
959959
}
960960

961961
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ private static void showWarning(Object filename, int lineno, Object text, Object
564564
} else {
565565
name = polib.lookupAttribute(category, null, SpecialAttributeNames.__NAME__);
566566
}
567-
Object stderr = PythonLanguage.getCore().getStderr();
567+
Object stderr = PythonContext.get(polib).getCore().getStderr();
568568

569569
// tfel: I've inlined PyFile_WriteObject, which just calls the "write" method and
570570
// decides if we should use "repr" or "str" - in this case its always "str" for objects

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import java.util.zip.Deflater;
7272
import java.util.zip.Inflater;
7373

74-
import com.oracle.graal.python.PythonLanguage;
7574
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
7675
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
7776
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
@@ -439,8 +438,8 @@ static void memError(Object zst, int function, int err, NFIZlibSupport zlibSuppo
439438

440439
@SuppressWarnings("unused")
441440
@Fallback
442-
static void fallback(Object zst, int function, int err, NFIZlibSupport zlibSupport, boolean deallocate) {
443-
throw PythonLanguage.getCore().raise(SystemError, "Unhandled Error!");
441+
void fallback(Object zst, int function, int err, NFIZlibSupport zlibSupport, boolean deallocate) {
442+
throw PythonContext.get(this).getCore().raise(SystemError, "Unhandled Error!");
444443
}
445444
}
446445

0 commit comments

Comments
 (0)