Skip to content

Commit 305eff3

Browse files
committed
Inline nodes
1 parent c3db7c6 commit 305eff3

File tree

7 files changed

+32
-25
lines changed

7 files changed

+32
-25
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int doIt(VirtualFrame frame, Node inliningTarget, ErrorHandlerCache cache
243243
@Cached CharmapEncodeLookupNode charmapEncodeLookupNode,
244244
@Cached GetErrorHandlerNode getErrorHandlerNode,
245245
@Cached CallEncodingErrorHandlerNode callEncodingErrorHandlerNode,
246-
@Cached(inline = false) ByteArrayBuilder.AppendBytesNode appendBytesNode,
246+
@Cached ByteArrayBuilder.AppendBytesNode appendBytesNode,
247247
@Cached CharmapEncodeOutputNode charmapEncodeOutputNode,
248248
@Cached RaiseEncodeException raiseEncodeException) {
249249
int errEnd = pos;
@@ -266,7 +266,7 @@ static int doIt(VirtualFrame frame, Node inliningTarget, ErrorHandlerCache cache
266266
// TODO switch (cache.errorHandlerEnum)
267267
EncodingErrorHandlerResult result = callEncodingErrorHandlerNode.execute(frame, inliningTarget, cache, errors, T_CHARMAP, src, pos, errEnd, CHARACTER_MAPS_TO_UNDEFINED);
268268
if (!result.isUnicode) {
269-
appendBytesNode.execute(frame, builder, result.replacement);
269+
appendBytesNode.execute(frame, inliningTarget, builder, result.replacement);
270270
return result.newPos;
271271
}
272272
TruffleString replacement = castToTruffleStringNode.execute(inliningTarget, result.replacement);
@@ -301,7 +301,7 @@ static boolean doEncodingMap(int cp, PEncodingMap mapping, ByteArrayBuilder buil
301301
@Fallback
302302
static boolean doGenericMapping(VirtualFrame frame, Node inliningTarget, int cp, Object mapping, ByteArrayBuilder builder,
303303
@Cached CharmapEncodeLookupNode charmapEncodeLookupNode,
304-
@Cached(inline = false) ByteArrayBuilder.AppendBytesNode appendBytesNode) {
304+
@Cached ByteArrayBuilder.AppendBytesNode appendBytesNode) {
305305
Object rep = charmapEncodeLookupNode.execute(frame, inliningTarget, cp, mapping);
306306
if (rep == PNone.NONE) {
307307
return false;
@@ -310,7 +310,7 @@ static boolean doGenericMapping(VirtualFrame frame, Node inliningTarget, int cp,
310310
assert value >= 0 && value <= 255;
311311
builder.add(value.byteValue());
312312
} else {
313-
appendBytesNode.execute(frame, builder, rep);
313+
appendBytesNode.execute(frame, inliningTarget, builder, rep);
314314
}
315315
return true;
316316
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static TruffleString read(VirtualFrame frame, PTextIO self, int n,
492492
TruffleStringBuilder chunks = null;
493493
/* Keep reading chunks until we have n characters to return */
494494
while (remaining > 0) {
495-
boolean res = readChunkNode.execute(frame, self, remaining);
495+
boolean res = readChunkNode.execute(frame, inliningTarget, self, remaining);
496496
// TODO: _PyIO_trap_eintr()
497497
if (!res) /* EOF */ {
498498
break;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static TruffleString readline(VirtualFrame frame, PTextIO self, int limit,
386386
/* First, get some data if necessary */
387387
boolean res = true;
388388
while (!self.hasDecodedCharsAvailable()) {
389-
res = readChunkNode.execute(frame, self, 0);
389+
res = readChunkNode.execute(frame, inliningTarget, self, 0);
390390
/*
391391
* if (res < 0) { / * NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() when
392392
* EINTR occurs so we needn't do it ourselves. / // TODO:_PyIO_trap_eintr() }
@@ -488,21 +488,21 @@ static TruffleString readline(VirtualFrame frame, PTextIO self, int limit,
488488
/*
489489
* cpython/Modules/_io/textio.c:textiowrapper_read_chunk
490490
*/
491-
@GenerateInline(false) // needs indirect call data
491+
@GenerateInline
492+
@GenerateCached(false)
492493
protected abstract static class ReadChunkNode extends Node {
493494

494-
public abstract boolean execute(VirtualFrame frame, PTextIO self, int size_hint);
495+
public abstract boolean execute(VirtualFrame frame, Node inliningTarget, PTextIO self, int size_hint);
495496

496497
@Specialization(guards = "self.hasDecoder()")
497-
static boolean readChunk(VirtualFrame frame, PTextIO self, int hint,
498-
@Bind("this") Node inliningTarget,
498+
static boolean readChunk(VirtualFrame frame, Node inliningTarget, PTextIO self, int hint,
499499
@Cached("createFor(this)") IndirectCallData indirectCallData,
500500
@Cached SequenceNodes.GetObjectArrayNode getArray,
501-
@Cached DecodeNode decodeNode,
501+
@Cached(inline = false) DecodeNode decodeNode,
502502
@Cached PyObjectCallMethodObjArgs callMethodGetState,
503503
@Cached PyObjectCallMethodObjArgs callMethodRead,
504504
@Cached PyNumberAsSizeNode asSizeNode,
505-
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
505+
@Cached(inline = false) TruffleString.CodePointLengthNode codePointLengthNode,
506506
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
507507
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
508508
@Cached PRaiseNode.Lazy raiseNode) {
@@ -598,8 +598,8 @@ static boolean readChunk(VirtualFrame frame, PTextIO self, int hint,
598598
}
599599

600600
@Specialization(guards = "!self.hasDecoder()")
601-
boolean error(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") int size_hint,
602-
@Cached PRaiseNode raiseNode) {
601+
static boolean error(@SuppressWarnings("unused") PTextIO self, @SuppressWarnings("unused") int size_hint,
602+
@Cached(inline = false) PRaiseNode raiseNode) {
603603
throw raiseNode.raise(IOUnsupportedOperation, NOT_READABLE);
604604
}
605605
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAcquireLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, 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

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeErrorBuiltins.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.oracle.truffle.api.dsl.Bind;
6666
import com.oracle.truffle.api.dsl.Cached;
6767
import com.oracle.truffle.api.dsl.Cached.Shared;
68+
import com.oracle.truffle.api.dsl.GenerateCached;
6869
import com.oracle.truffle.api.dsl.GenerateInline;
6970
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7071
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -106,14 +107,15 @@ public static int getArgAsInt(Node inliningTarget, Object[] args, int index, PRa
106107
}
107108
}
108109

109-
@GenerateInline(false) // needs indirect call data
110+
@GenerateInline
111+
@GenerateCached(false)
110112
public abstract static class GetArgAsBytesNode extends PNodeWithContext {
111-
abstract PBytes execute(VirtualFrame frame, Object val);
113+
abstract PBytes execute(VirtualFrame frame, Node inliningTarget, Object val);
112114

113115
@Specialization
114116
@TruffleBoundary
115117
static PBytes doString(TruffleString value,
116-
@Shared @Cached PythonObjectFactory factory) {
118+
@Shared @Cached(inline = false) PythonObjectFactory factory) {
117119
// TODO GR-37601: cbasca cPython works directly with bytes while we have Java strings
118120
// which are encoded, here we decode using the system encoding but this might not be the
119121
// correct / ideal case
@@ -129,7 +131,7 @@ static PBytes doBytes(PBytes value) {
129131
static PBytes doOther(VirtualFrame frame, Object value,
130132
@Cached("createFor(this)") IndirectCallData indirectCallData,
131133
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonBufferAccessLibrary bufferLib,
132-
@Shared @Cached PythonObjectFactory factory) {
134+
@Shared @Cached(inline = false) PythonObjectFactory factory) {
133135
try {
134136
final byte[] buffer = bufferLib.getInternalOrCopiedByteArray(value);
135137
final int bufferLength = bufferLib.getBufferLength(value);
@@ -144,7 +146,7 @@ public static Object getArgAsBytes(VirtualFrame frame, Node inliningTarget, Obje
144146
if (args.length < index + 1) {
145147
throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError);
146148
} else {
147-
return getArgAsBytesNode.execute(frame, args[index]);
149+
return getArgAsBytesNode.execute(frame, inliningTarget, args[index]);
148150
}
149151
}
150152

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/ObjectConversionBaseNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, 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

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/ByteArrayBuilder.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,21 @@
4040
*/
4141
package com.oracle.graal.python.util;
4242

43+
import com.oracle.graal.python.PythonLanguage;
4344
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
4445
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
4546
import com.oracle.graal.python.nodes.PNodeWithContext;
4647
import com.oracle.graal.python.runtime.IndirectCallData;
48+
import com.oracle.graal.python.runtime.PythonContext;
4749
import com.oracle.truffle.api.CompilerDirectives;
4850
import com.oracle.truffle.api.dsl.Cached;
4951
import com.oracle.truffle.api.dsl.Cached.Shared;
52+
import com.oracle.truffle.api.dsl.GenerateCached;
5053
import com.oracle.truffle.api.dsl.GenerateInline;
5154
import com.oracle.truffle.api.dsl.Specialization;
5255
import com.oracle.truffle.api.frame.VirtualFrame;
5356
import com.oracle.truffle.api.library.CachedLibrary;
57+
import com.oracle.truffle.api.nodes.Node;
5458

5559
/**
5660
* @see ArrayBuilder
@@ -113,16 +117,17 @@ private void ensureCanAppend(int bytesToAdd) {
113117
}
114118
}
115119

116-
@GenerateInline(false) // needs indirect call data
120+
@GenerateInline
121+
@GenerateCached(false)
117122
public abstract static class AppendBytesNode extends PNodeWithContext {
118-
public abstract void execute(VirtualFrame frame, ByteArrayBuilder builder, Object bytes);
123+
public abstract void execute(VirtualFrame frame, Node inliningTarget, ByteArrayBuilder builder, Object bytes);
119124

120125
@Specialization(limit = "3")
121-
void appendBytes(VirtualFrame frame, ByteArrayBuilder builder, Object data,
126+
static void appendBytes(VirtualFrame frame, Node inliningTarget, ByteArrayBuilder builder, Object data,
122127
@Cached("createFor(this)") IndirectCallData indirectCallData,
123128
@CachedLibrary("data") PythonBufferAcquireLibrary bufferAcquireLib,
124129
@CachedLibrary(limit = "3") @Shared PythonBufferAccessLibrary bufferLib) {
125-
Object dataBuffer = bufferAcquireLib.acquireReadonly(data, frame, getContext(), getLanguage(), indirectCallData);
130+
Object dataBuffer = bufferAcquireLib.acquireReadonly(data, frame, PythonContext.get(inliningTarget), PythonLanguage.get(inliningTarget), indirectCallData);
126131
try {
127132
int len = bufferLib.getBufferLength(dataBuffer);
128133
byte[] src = bufferLib.getInternalOrCopiedByteArray(dataBuffer);

0 commit comments

Comments
 (0)