Skip to content

Commit 3b175aa

Browse files
committed
Merge branch 'master' into feature/GR-20901
# Conflicts: # graalpython/com.oracle.graal.python.test/testData/goldenFiles/BasicTests/elif01.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/collections__init__.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/enumt.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/functions.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/initCollectionsPart2.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/locale.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/site.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/sre_compile.tast # graalpython/com.oracle.graal.python.test/testData/testFiles/RuntimeFileTests/sre_parse.tast
2 parents 45f4575 + 9909b30 commit 3b175aa

File tree

482 files changed

+53763
-14235
lines changed

Some content is hidden

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

482 files changed

+53763
-14235
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -75,7 +75,7 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
7575
Object iter = getIter.executeWith(null, range);
7676
GetNextNode next = GetNextNode.create();
7777
testRoot.doInsert(next);
78-
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
78+
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.getUncached();
7979

8080
while (true) {
8181
try {
@@ -99,7 +99,7 @@ public void loopWithStep() throws UnexpectedResultException {
9999
Object iter = getIter.executeWith(null, range);
100100
GetNextNode next = GetNextNode.create();
101101
testRoot.doInsert(next);
102-
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
102+
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.getUncached();
103103

104104
while (true) {
105105
try {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class ParserTestBase {
7575
protected boolean printFormatStringLiteralValues = false;
7676
protected int printOnlyDiffIfLenIsBigger = 1000;
7777

78+
private static final boolean REGENERATE_TREE = false;
79+
7880
@Rule public TestName name = new TestName();
7981

8082
private ScopeInfo lastGlobalScope;
@@ -162,7 +164,7 @@ public void saveNewTreeResult(File testFile, boolean goldenFileNextToTestFile) t
162164
File newGoldenFile = goldenFileNextToTestFile
163165
? new File(testFile.getParentFile(), getFileName(testFile) + NEW_GOLDEN_FILE_EXT)
164166
: getGoldenFile(NEW_GOLDEN_FILE_EXT);
165-
if (!newGoldenFile.exists()) {
167+
if (REGENERATE_TREE || !newGoldenFile.exists()) {
166168
try (FileWriter fw = new FileWriter(newGoldenFile)) {
167169
fw.write(tree);
168170
}
@@ -179,7 +181,7 @@ public void checkTreeFromFile(File testFile, boolean goldenFileNextToTestFile) t
179181
File goldenFile = goldenFileNextToTestFile
180182
? new File(testFile.getParentFile(), getFileName(testFile) + GOLDEN_FILE_EXT)
181183
: getGoldenFile(GOLDEN_FILE_EXT);
182-
if (!goldenFile.exists()) {
184+
if (REGENERATE_TREE || !goldenFile.exists()) {
183185
try (FileWriter fw = new FileWriter(goldenFile)) {
184186
fw.write(tree);
185187
}
@@ -199,7 +201,7 @@ public void saveNewScope(File testFile, boolean goldenFileNextToTestFile) throws
199201
File newScopeFile = goldenFileNextToTestFile
200202
? new File(testFile.getParentFile(), getFileName(testFile) + NEW_SCOPE_FILE_EXT)
201203
: getGoldenFile(NEW_SCOPE_FILE_EXT);
202-
if (!newScopeFile.exists()) {
204+
if (REGENERATE_TREE || !newScopeFile.exists()) {
203205
try (FileWriter fw = new FileWriter(newScopeFile)) {
204206
fw.write(scopes.toString());
205207
}
@@ -217,7 +219,7 @@ public void checkScopeFromFile(File testFile, boolean goldenFileNextToTestFile)
217219
File goldenScopeFile = goldenFileNextToTestFile
218220
? new File(testFile.getParentFile(), getFileName(testFile) + SCOPE_FILE_EXT)
219221
: getGoldenFile(SCOPE_FILE_EXT);
220-
if (!goldenScopeFile.exists()) {
222+
if (REGENERATE_TREE || !goldenScopeFile.exists()) {
221223
try (FileWriter fw = new FileWriter(goldenScopeFile)) {
222224
fw.write(scopes.toString());
223225
}
@@ -230,7 +232,7 @@ public void checkTreeResult(String source, PythonParser.ParserMode mode, Frame f
230232
Node resultNew = parse(source, name.getMethodName(), mode, frame);
231233
String tree = printTreeToString(resultNew);
232234
File goldenFile = getGoldenFile(GOLDEN_FILE_EXT);
233-
if (!goldenFile.exists()) {
235+
if (REGENERATE_TREE || !goldenFile.exists()) {
234236
try (FileWriter fw = new FileWriter(goldenFile)) {
235237
fw.write(tree);
236238
}
@@ -249,7 +251,7 @@ public void checkScopeResult(String source, PythonParser.ParserMode mode) throws
249251
StringBuilder scopes = new StringBuilder();
250252
scopeNew.debugPrint(scopes, 0);
251253
File goldenScopeFile = getGoldenFile(SCOPE_FILE_EXT);
252-
if (!goldenScopeFile.exists()) {
254+
if (REGENERATE_TREE || !goldenScopeFile.exists()) {
253255
try (FileWriter fw = new FileWriter(goldenScopeFile)) {
254256
fw.write(scopes.toString());
255257
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import sys
41+
42+
43+
def test_pow():
44+
if sys.implementation.name == "graalpython":
45+
try:
46+
2 ** (2**128)
47+
except ArithmeticError:
48+
assert True
49+
else:
50+
assert False
51+
52+
assert 2 ** -(2**128) == 0.0
53+
54+
class X(float):
55+
def __rpow__(self, other):
56+
return 42
57+
58+
assert 2 ** X() == 42
59+
60+
try:
61+
2.0 .__pow__(2, 2)
62+
except TypeError as e:
63+
assert True
64+
else:
65+
assert False
66+
67+
try:
68+
2.0 .__pow__(2.0, 2.0)
69+
except TypeError as e:
70+
assert True
71+
else:
72+
assert False
73+
74+
assert 2 ** 2.0 == 4.0
75+
76+
assert 2 .__pow__("a") == NotImplemented
77+
assert 2 .__pow__("a", 2) == NotImplemented
78+
assert 2 .__pow__(2**30, 2**128) == 0
79+
80+
# crafted to try specializations
81+
def mypow(a, b, c):
82+
return a.__pow__(b, c)
83+
84+
values = [
85+
[1, 2, None, 1], # long
86+
[1, 128, None, 1], # BigInteger
87+
[1, -2, None, 1.0], # double result
88+
[1, 0xffffffffffffffffffffffffffffffff & 0x80, None, 1], # narrow to long
89+
[2, 0xffffffffffffffffffffffffffffffff & 0x80, None, 340282366920938463463374607431768211456], # cannot narrow
90+
[2, -(0xffffffffffffffffffffffffffffffff & 0x80), None, 2.938735877055719e-39], # double result
91+
[2**128, 0, None, 1], # narrow to long
92+
[2**128, 1, None, 340282366920938463463374607431768211456], # cannot narrow
93+
[2**128, -2, None, 8.636168555094445e-78], # double
94+
[2**128, 0xffffffffffffffffffffffffffffffff & 0x2, None, 115792089237316195423570985008687907853269984665640564039457584007913129639936], # large
95+
[2**128, -(0xffffffffffffffffffffffffffffffff & 0x8), None, 5.562684646268003e-309], # double result
96+
[1, 2, 3, 1], # fast path
97+
[2, 2**30, 2**128, 0], # generic
98+
] + []
99+
100+
if sys.version_info.minor >= 8:
101+
values += [
102+
[1, -2, 3, 1], # fast path double
103+
[1, 2, -3, -2], # negative mod
104+
[1, -2, -3, -2], # negative mod and negative right
105+
[1, -2**128, 3, 1], # mod and large negative right
106+
[1, -2**128, -3, -2], # negative mod and large negative right
107+
[1, -2**128, -2**64, -18446744073709551615], # large negative mod and large negative right
108+
]
109+
110+
for args in values:
111+
assert mypow(*args[:-1]) == args[-1], "%r -> %r == %r" % (args, mypow(*args[:-1]), args[-1])
112+
113+
def mypow_rev(a, b, c):
114+
return a.__pow__(b, c)
115+
116+
for args in reversed(values):
117+
assert mypow_rev(*args[:-1]) == args[-1], "%r -> %r == %r" % (args, mypow(*args[:-1]), args[-1])
118+
119+
assert 2**1.0 == 2.0
120+
121+
try:
122+
pow(12,-2,100)
123+
except ValueError as e:
124+
assert "base is not invertible for the given modulus" in str(e)
125+
else:
126+
assert False
127+
128+
assert pow(1234567, -2, 100) == 9

graalpython/com.oracle.graal.python.test/src/tests/test_binary_arithmetic.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2222
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2323
# OF THE POSSIBILITY OF SUCH DAMAGE.
24+
25+
import sys
26+
2427
def test_add_long_overflow():
2528
# max long value is written as long primitive
2629
val = 0x7fffffffffffffff
@@ -295,3 +298,8 @@ def test_lshift():
295298
def test_pow():
296299
# (0xffffffffffffffff >> 63) is used to produce a non-narrowed int
297300
assert 2**(0xffffffffffffffff >> 63) == 2
301+
302+
if sys.version_info.minor >= 8:
303+
# for some reason this hangs CPython on the CI even if it's just parsed
304+
from pow_tests import test_pow
305+
test_pow()

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/annotationType01.tast

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ ModuleRootNode Name: <module 'annotationType01'> SourceSection: [0,6]`j: int`
1212
SetItemNodeGen SourceSection: [0,0]Empty
1313
ReadNameNodeGen SourceSection: None
1414
Identifier: __annotations__
15+
IsBuiltinClassProfile SourceSection: None
16+
CachedDispatchFirst SourceSection: None
1517
StringLiteralNode SourceSection: [0,0]Empty
1618
ReadNameNodeGen SourceSection: [3,6]`int`
1719
Identifier: int
20+
IsBuiltinClassProfile SourceSection: None
21+
CachedDispatchFirst SourceSection: None
1822
EmptyNode SourceSection: None

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/annotationType02.tast

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ ModuleRootNode Name: <module 'annotationType02'> SourceSection: [0,28]`def fn():
3838
Identifier: index
3939
WriteLocalFrameSlotNodeGen SourceSection: None
4040
Frame: [0,index,Illegal]
41+
IsBuiltinClassProfile SourceSection: None
42+
CachedDispatchFirst SourceSection: None
4143
IntegerLiteralNode SourceSection: [26,27]`0`
4244
Value: 0
4345
Return Expresssion: ReadLocalVariableNode SourceSection: None
4446
Frame: [1,<return_val>,Illegal]
47+
IsBuiltinClassProfile SourceSection: None
48+
CachedDispatchFirst SourceSection: None
4549
ReadVariableFromFrameNodeGen SourceSection: None

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/annotationType03.tast

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ ModuleRootNode Name: <module 'annotationType03'> SourceSection: [0,39]`j = 1↵a
1717
Key: __annotations__
1818
LookupAndCallBinaryNodeGen SourceSection: None
1919
Op: __getattribute__
20+
IsBuiltinClassProfile SourceSection: None
21+
CachedDispatchFirst SourceSection: None
2022
ReadNameNodeGen SourceSection: [6,10]`ahoj`
2123
Identifier: ahoj
24+
IsBuiltinClassProfile SourceSection: None
25+
CachedDispatchFirst SourceSection: None
2226
StringLiteralNode SourceSection: [27,30]`'j'`
2327
ReadNameNodeGen SourceSection: [34,39]`float`
2428
Identifier: float
29+
IsBuiltinClassProfile SourceSection: None
30+
CachedDispatchFirst SourceSection: None
2531
SideEffect:
2632
WriteNameNodeGen SourceSection: [0,5]`j = 1`
2733
Identifier: j

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/assignment02.tast

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ ModuleRootNode Name: <module 'assignment02'> SourceSection: [0,9]`a = b = 1`
1010
Identifier: <>temp0
1111
WriteLocalFrameSlotNodeGen SourceSection: None
1212
Frame: [0,<>temp0,Illegal]
13+
IsBuiltinClassProfile SourceSection: None
14+
CachedDispatchFirst SourceSection: None
1315
IntegerLiteralNode SourceSection: [8,9]`1`
1416
Value: 1
1517
WriteNameNodeGen SourceSection: None
1618
Identifier: a
1719
ReadLocalVariableNode SourceSection: None
1820
Frame: [0,<>temp0,Illegal]
21+
IsBuiltinClassProfile SourceSection: None
22+
CachedDispatchFirst SourceSection: None
1923
ReadVariableFromFrameNodeGen SourceSection: None
2024
WriteNameNodeGen SourceSection: None
2125
Identifier: b
2226
ReadLocalVariableNode SourceSection: None
2327
Frame: [0,<>temp0,Illegal]
28+
IsBuiltinClassProfile SourceSection: None
29+
CachedDispatchFirst SourceSection: None
2430
ReadVariableFromFrameNodeGen SourceSection: None
2531
EmptyNode SourceSection: None

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/assignment03.tast

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ModuleRootNode Name: <module 'assignment03'> SourceSection: [0,25]`a = 0↵b = a
1414
Identifier: b
1515
ReadNameNodeGen SourceSection: [10,11]`a`
1616
Identifier: a
17+
IsBuiltinClassProfile SourceSection: None
18+
CachedDispatchFirst SourceSection: None
1719
ExpressionWithSideEffect SourceSection: None
1820
Expression:
1921
EmptyNode SourceSection: None
@@ -28,7 +30,13 @@ ModuleRootNode Name: <module 'assignment03'> SourceSection: [0,25]`a = 0↵b = a
2830
Op: __add__
2931
ReadNameNodeGen SourceSection: [16,17]`a`
3032
Identifier: a
33+
IsBuiltinClassProfile SourceSection: None
34+
CachedDispatchFirst SourceSection: None
3135
ReadNameNodeGen SourceSection: [20,21]`a`
3236
Identifier: a
37+
IsBuiltinClassProfile SourceSection: None
38+
CachedDispatchFirst SourceSection: None
3339
ReadNameNodeGen SourceSection: [24,25]`b`
3440
Identifier: b
41+
IsBuiltinClassProfile SourceSection: None
42+
CachedDispatchFirst SourceSection: None

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/assignment04.tast

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,38 @@ ModuleRootNode Name: <module 'assignment04'> SourceSection: [0,17]`a = b = c = d
1010
Identifier: <>temp0
1111
WriteLocalFrameSlotNodeGen SourceSection: None
1212
Frame: [0,<>temp0,Illegal]
13+
IsBuiltinClassProfile SourceSection: None
14+
CachedDispatchFirst SourceSection: None
1315
ReadNameNodeGen SourceSection: [16,17]`e`
1416
Identifier: e
17+
IsBuiltinClassProfile SourceSection: None
18+
CachedDispatchFirst SourceSection: None
1519
WriteNameNodeGen SourceSection: None
1620
Identifier: a
1721
ReadLocalVariableNode SourceSection: None
1822
Frame: [0,<>temp0,Illegal]
23+
IsBuiltinClassProfile SourceSection: None
24+
CachedDispatchFirst SourceSection: None
1925
ReadVariableFromFrameNodeGen SourceSection: None
2026
WriteNameNodeGen SourceSection: None
2127
Identifier: b
2228
ReadLocalVariableNode SourceSection: None
2329
Frame: [0,<>temp0,Illegal]
30+
IsBuiltinClassProfile SourceSection: None
31+
CachedDispatchFirst SourceSection: None
2432
ReadVariableFromFrameNodeGen SourceSection: None
2533
WriteNameNodeGen SourceSection: None
2634
Identifier: c
2735
ReadLocalVariableNode SourceSection: None
2836
Frame: [0,<>temp0,Illegal]
37+
IsBuiltinClassProfile SourceSection: None
38+
CachedDispatchFirst SourceSection: None
2939
ReadVariableFromFrameNodeGen SourceSection: None
3040
WriteNameNodeGen SourceSection: None
3141
Identifier: d
3242
ReadLocalVariableNode SourceSection: None
3343
Frame: [0,<>temp0,Illegal]
44+
IsBuiltinClassProfile SourceSection: None
45+
CachedDispatchFirst SourceSection: None
3446
ReadVariableFromFrameNodeGen SourceSection: None
3547
EmptyNode SourceSection: None

0 commit comments

Comments
 (0)