Skip to content

Commit f8ac80a

Browse files
committed
[GR-44433] Resolve most of the DSL warnings in com.oracle.graal.python.builtins.modules.
PullRequest: graalpython/2642
2 parents b3270f6 + 2496082 commit f8ac80a

File tree

130 files changed

+2762
-2403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+2762
-2403
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/objects/ObjectHashMapTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
7171
import com.oracle.truffle.api.frame.Frame;
7272
import com.oracle.truffle.api.interop.TruffleObject;
73+
import com.oracle.truffle.api.nodes.Node;
7374
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
7475
import com.oracle.truffle.api.profiles.InlinedCountingConditionProfile;
7576

@@ -296,7 +297,7 @@ static <T> void assertEqual(String message, LinkedHashMap<T, Object> expected, O
296297
int[] size = new int[]{0};
297298
HashingStorageForEachNodeGen.getUncached().execute(null, storage, new HashingStorageForEachCallback<>() {
298299
@Override
299-
public Object execute(Frame frame, HashingStorage s, HashingStorageIterator cbIt, Object accumulator) {
300+
public Object execute(Frame frame, Node inliningTarget, HashingStorage s, HashingStorageIterator cbIt, Object accumulator) {
300301
Object key = HashingStorageIteratorKey.executeUncached(s, cbIt);
301302
assertTrue(key.toString(), expected.containsKey(key));
302303
size[0]++;

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

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import com.oracle.truffle.api.dsl.Bind;
8686
import com.oracle.truffle.api.dsl.Cached;
8787
import com.oracle.truffle.api.dsl.Cached.Exclusive;
88+
import com.oracle.truffle.api.dsl.Cached.Shared;
8889
import com.oracle.truffle.api.dsl.Fallback;
8990
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
9091
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -121,8 +122,8 @@ abstract static class ArrayNode extends PythonVarargsBuiltinNode {
121122
Object array2(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kwargs,
122123
@Bind("this") Node inliningTarget,
123124
@Exclusive @Cached InlineIsBuiltinClassProfile isNotSubtypeProfile,
124-
@Cached CastToTruffleStringCheckedNode cast,
125-
@Cached ArrayNodeInternal arrayNodeInternal) {
125+
@Shared @Cached CastToTruffleStringCheckedNode cast,
126+
@Shared @Cached ArrayNodeInternal arrayNodeInternal) {
126127
checkKwargs(cls, kwargs, inliningTarget, isNotSubtypeProfile);
127128
return arrayNodeInternal.execute(frame, cls, cast.cast(args[0], ErrorMessages.ARG_1_MUST_BE_UNICODE_NOT_P, args[0]), PNone.NO_VALUE);
128129
}
@@ -131,8 +132,8 @@ Object array2(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kwargs,
131132
Object array3(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kwargs,
132133
@Bind("this") Node inliningTarget,
133134
@Exclusive @Cached InlineIsBuiltinClassProfile isNotSubtypeProfile,
134-
@Cached CastToTruffleStringCheckedNode cast,
135-
@Cached ArrayNodeInternal arrayNodeInternal) {
135+
@Shared @Cached CastToTruffleStringCheckedNode cast,
136+
@Shared @Cached ArrayNodeInternal arrayNodeInternal) {
136137
checkKwargs(cls, kwargs, inliningTarget, isNotSubtypeProfile);
137138
return arrayNodeInternal.execute(frame, cls, cast.cast(args[0], ErrorMessages.ARG_1_MUST_BE_UNICODE_NOT_P, args[0]), args[1]);
138139
}
@@ -174,17 +175,17 @@ abstract static class ArrayNodeInternal extends Node {
174175

175176
@Specialization(guards = "isNoValue(initializer)")
176177
PArray array(Object cls, TruffleString typeCode, @SuppressWarnings("unused") PNone initializer,
177-
@Cached TruffleString.CodePointLengthNode lengthNode,
178-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
178+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
179+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
179180
BufferFormat format = getFormatChecked(typeCode, lengthNode, atIndexNode);
180181
return getFactory().createArray(cls, typeCode, format);
181182
}
182183

183184
@Specialization
184185
PArray arrayWithRangeInitializer(Object cls, TruffleString typeCode, PIntRange range,
185-
@Cached ArrayNodes.PutValueNode putValueNode,
186-
@Cached TruffleString.CodePointLengthNode lengthNode,
187-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
186+
@Shared @Cached ArrayNodes.PutValueNode putValueNode,
187+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
188+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
188189
BufferFormat format = getFormatChecked(typeCode, lengthNode, atIndexNode);
189190
PArray array;
190191
try {
@@ -208,8 +209,8 @@ PArray arrayWithRangeInitializer(Object cls, TruffleString typeCode, PIntRange r
208209
@Specialization
209210
PArray arrayWithBytesInitializer(VirtualFrame frame, Object cls, TruffleString typeCode, PBytesLike bytes,
210211
@Cached ArrayBuiltins.FromBytesNode fromBytesNode,
211-
@Cached TruffleString.CodePointLengthNode lengthNode,
212-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
212+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
213+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
213214
PArray array = getFactory().createArray(cls, typeCode, getFormatChecked(typeCode, lengthNode, atIndexNode));
214215
fromBytesNode.executeWithoutClinic(frame, array, bytes);
215216
return array;
@@ -218,8 +219,8 @@ PArray arrayWithBytesInitializer(VirtualFrame frame, Object cls, TruffleString t
218219
@Specialization(guards = "isString(initializer)")
219220
PArray arrayWithStringInitializer(VirtualFrame frame, Object cls, TruffleString typeCode, Object initializer,
220221
@Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
221-
@Cached TruffleString.CodePointLengthNode lengthNode,
222-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
222+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
223+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
223224
BufferFormat format = getFormatChecked(typeCode, lengthNode, atIndexNode);
224225
if (format != BufferFormat.UNICODE) {
225226
throw raise(TypeError, ErrorMessages.CANNOT_USE_STR_TO_INITIALIZE_ARRAY, typeCode);
@@ -231,9 +232,10 @@ PArray arrayWithStringInitializer(VirtualFrame frame, Object cls, TruffleString
231232

232233
@Specialization
233234
PArray arrayArrayInitializer(VirtualFrame frame, Object cls, TruffleString typeCode, PArray initializer,
234-
@Cached ArrayNodes.PutValueNode putValueNode,
235-
@Cached ArrayNodes.GetValueNode getValueNode, @Cached TruffleString.CodePointLengthNode lengthNode,
236-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
235+
@Shared @Cached ArrayNodes.PutValueNode putValueNode,
236+
@Cached ArrayNodes.GetValueNode getValueNode,
237+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
238+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
237239
BufferFormat format = getFormatChecked(typeCode, lengthNode, atIndexNode);
238240
try {
239241
PArray array = getFactory().createArray(cls, typeCode, format, initializer.getLength());
@@ -249,11 +251,11 @@ PArray arrayArrayInitializer(VirtualFrame frame, Object cls, TruffleString typeC
249251

250252
@Specialization(guards = "!isBytes(initializer)")
251253
PArray arraySequenceInitializer(VirtualFrame frame, Object cls, TruffleString typeCode, PSequence initializer,
252-
@Cached ArrayNodes.PutValueNode putValueNode,
254+
@Shared @Cached ArrayNodes.PutValueNode putValueNode,
253255
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
254256
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode,
255-
@Cached TruffleString.CodePointLengthNode lengthNode,
256-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
257+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
258+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
257259
BufferFormat format = getFormatChecked(typeCode, lengthNode, atIndexNode);
258260
SequenceStorage storage = getSequenceStorageNode.execute(initializer);
259261
int length = storage.length();
@@ -270,14 +272,15 @@ PArray arraySequenceInitializer(VirtualFrame frame, Object cls, TruffleString ty
270272
}
271273

272274
@Specialization(guards = {"!isBytes(initializer)", "!isString(initializer)", "!isPSequence(initializer)"})
275+
@SuppressWarnings("truffle-static-method")
273276
PArray arrayIteratorInitializer(VirtualFrame frame, Object cls, TruffleString typeCode, Object initializer,
274277
@Bind("this") Node inliningTarget,
275278
@Cached PyObjectGetIter getIter,
276-
@Cached ArrayNodes.PutValueNode putValueNode,
279+
@Shared @Cached ArrayNodes.PutValueNode putValueNode,
277280
@Cached GetNextNode nextNode,
278281
@Cached IsBuiltinObjectProfile errorProfile,
279-
@Cached TruffleString.CodePointLengthNode lengthNode,
280-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
282+
@Shared @Cached TruffleString.CodePointLengthNode lengthNode,
283+
@Shared @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
281284
Object iter = getIter.execute(frame, initializer);
282285

283286
BufferFormat format = getFormatChecked(typeCode, lengthNode, atIndexNode);
@@ -348,17 +351,17 @@ private PythonObjectFactory getFactory() {
348351
@ArgumentClinic(name = "mformatCode", conversion = ArgumentClinic.ClinicConversion.Index)
349352
@GenerateNodeFactory
350353
abstract static class ArrayReconstructorNode extends PythonClinicBuiltinNode {
351-
@Specialization(guards = "mformatCode == cachedCode")
354+
@Specialization(guards = "mformatCode == cachedCode", limit = "3")
352355
Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleString typeCode, @SuppressWarnings("unused") int mformatCode, PBytes bytes,
353356
@Cached("mformatCode") int cachedCode,
354357
@Cached("createIdentityProfile()") ValueProfile formatProfile,
355-
@Cached PyObjectCallMethodObjArgs callDecode,
356-
@Cached ArrayBuiltins.FromBytesNode fromBytesNode,
357-
@Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
358-
@Cached IsSubtypeNode isSubtypeNode,
359-
@Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
360-
@Cached TruffleString.CodePointLengthNode lengthNode,
361-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
358+
@Exclusive @Cached PyObjectCallMethodObjArgs callDecode,
359+
@Exclusive @Cached ArrayBuiltins.FromBytesNode fromBytesNode,
360+
@Exclusive @Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
361+
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
362+
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
363+
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
364+
@Exclusive @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
362365
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
363366
if (format == null) {
364367
throw raise(ValueError, ErrorMessages.BAD_TYPECODE);
@@ -368,13 +371,13 @@ Object reconstructCached(VirtualFrame frame, Object arrayType, TruffleString typ
368371

369372
@Specialization(replaces = "reconstructCached")
370373
Object reconstruct(VirtualFrame frame, Object arrayType, TruffleString typeCode, int mformatCode, PBytes bytes,
371-
@Cached PyObjectCallMethodObjArgs callDecode,
372-
@Cached ArrayBuiltins.FromBytesNode fromBytesNode,
373-
@Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
374-
@Cached IsSubtypeNode isSubtypeNode,
375-
@Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
376-
@Cached TruffleString.CodePointLengthNode lengthNode,
377-
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
374+
@Exclusive @Cached PyObjectCallMethodObjArgs callDecode,
375+
@Exclusive @Cached ArrayBuiltins.FromBytesNode fromBytesNode,
376+
@Exclusive @Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
377+
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
378+
@Exclusive @Cached ArrayBuiltins.ByteSwapNode byteSwapNode,
379+
@Exclusive @Cached TruffleString.CodePointLengthNode lengthNode,
380+
@Exclusive @Cached TruffleString.CodePointAtIndexNode atIndexNode) {
378381
BufferFormat format = BufferFormat.forArray(typeCode, lengthNode, atIndexNode);
379382
if (format == null) {
380383
throw raise(ValueError, ErrorMessages.BAD_TYPECODE);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -76,6 +76,7 @@
7676
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
7777
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
7878
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
79+
import com.oracle.truffle.api.dsl.Bind;
7980
import com.oracle.truffle.api.dsl.Cached;
8081
import com.oracle.truffle.api.dsl.Cached.Shared;
8182
import com.oracle.truffle.api.dsl.Fallback;
@@ -87,7 +88,8 @@
8788
import com.oracle.truffle.api.library.CachedLibrary;
8889
import com.oracle.truffle.api.library.ExportLibrary;
8990
import com.oracle.truffle.api.library.ExportMessage;
90-
import com.oracle.truffle.api.profiles.ConditionProfile;
91+
import com.oracle.truffle.api.nodes.Node;
92+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
9193
import com.oracle.truffle.api.strings.TruffleString;
9294
import com.oracle.truffle.api.strings.TruffleString.CodeRange;
9395

@@ -150,11 +152,12 @@ Object nonAsciiString(@SuppressWarnings("unused") TruffleString value,
150152

151153
@Specialization
152154
Object string(PString value,
155+
@Bind("this") Node inliningTarget,
153156
@Cached CastToTruffleStringNode cast,
154157
@Shared("getCodeRange") @Cached @SuppressWarnings("unused") TruffleString.GetCodeRangeNode getCodeRangeNode,
155-
@Cached ConditionProfile asciiProfile) {
158+
@Cached InlinedConditionProfile asciiProfile) {
156159
TruffleString ts = cast.execute(value);
157-
if (asciiProfile.profile(isAscii(ts, getCodeRangeNode))) {
160+
if (asciiProfile.profile(inliningTarget, isAscii(ts, getCodeRangeNode))) {
158161
return asciiString(ts, getCodeRangeNode);
159162
} else {
160163
return nonAsciiString(ts, getCodeRangeNode);

0 commit comments

Comments
 (0)