Skip to content

Commit c7ae820

Browse files
committed
[GR-40105][GR-38986] Fix numpy tests and remaining tagged tests
PullRequest: graalpython/2366
2 parents e938f0b + 3c1782d commit c7ae820

File tree

18 files changed

+94
-65
lines changed

18 files changed

+94
-65
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "2f16c4826b16c64e35f81862b2676a2ad596f0a7" }
1+
{ "overlay": "8d2f966d01c706c213c81a89d3ebff18f30f4e5a" }

graalpython/com.oracle.graal.python.frozen/freeze_modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def lower_camel_case(str):
533533

534534
def freeze_module(src):
535535
with open(src.pyfile, "r") as src_file, open(src.binaryfile, "wb") as binary_file:
536-
code_obj = compile(src_file.read(), src.id, "exec")
536+
code_obj = compile(src_file.read(), f"<frozen {src.id}>", "exec")
537537
marshal.dump(code_obj, binary_file)
538538

539539

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/StringLiteralUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public static int createTokens(ArrayList<Token> tokens, ErrorCallback errorCallb
543543
braceLevelInExpression--;
544544
char expected = ch == ')' ? '(' : '[';
545545
if (bracesInExpression[braceLevelInExpression] != expected) {
546-
errorCallback.onError(textSourceRange, ERROR_MESSAGE_CLOSING_PAR_DOES_NOT_MATCH, bracesInExpression[braceLevelInExpression], ch);
546+
errorCallback.onError(textSourceRange, ERROR_MESSAGE_CLOSING_PAR_DOES_NOT_MATCH, ch, bracesInExpression[braceLevelInExpression]);
547547
return -1;
548548
}
549549
break;
@@ -560,7 +560,7 @@ public static int createTokens(ArrayList<Token> tokens, ErrorCallback errorCallb
560560
} else {
561561
braceLevelInExpression--;
562562
if (bracesInExpression[braceLevelInExpression] != '{') {
563-
errorCallback.onError(textSourceRange, ERROR_MESSAGE_CLOSING_PAR_DOES_NOT_MATCH, bracesInExpression[braceLevelInExpression], '}');
563+
errorCallback.onError(textSourceRange, ERROR_MESSAGE_CLOSING_PAR_DOES_NOT_MATCH, '}', bracesInExpression[braceLevelInExpression]);
564564
return -1;
565565
}
566566
}
@@ -1202,7 +1202,7 @@ public static void warnInvalidEscapeSequence(ErrorCallback errorCallback, Source
12021202
errorCallback.warnDeprecation(sourceRange, "invalid escape sequence '\\%c'", nextChar);
12031203
}
12041204

1205-
private static final String UNICODE_ERROR = "'unicodeescape' codec can't decode bytes in position %d-%d:";
1205+
private static final String UNICODE_ERROR = "(unicode error) 'unicodeescape' codec can't decode bytes in position %d-%d:";
12061206
private static final String ILLEGAL_CHARACTER = "illegal Unicode character";
12071207
private static final String TRAILING_S_IN_STR = "Trailing %s in string";
12081208
private static final String MALFORMED_ERROR = " malformed \\N character escape";

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
# Copyright (c) 2013, Regents of the University of California
33
#
44
# All rights reserved.
@@ -195,6 +195,15 @@ def test_floor_div():
195195
assert_exception(lambda: 5.4 // 0.0, ZeroDivisionError)
196196

197197

198+
def test_true_div():
199+
assert 1 / 2 == 0.5
200+
assert 108086391056891904 / 30023997515803307 == 3.6
201+
assert 295147905179352825856 / 2 == 1.4757395258967641e+20
202+
assert_exception(lambda: 1 / 0, ZeroDivisionError)
203+
assert_exception(lambda: 108086391056891904 / 0, ZeroDivisionError)
204+
assert_exception(lambda: 295147905179352825856 / 0, ZeroDivisionError)
205+
206+
198207
def test_int_rfloor_div():
199208
assert int.__rfloordiv__(2, 5) == 2
200209
assert int.__rfloordiv__(2, 0x8000000000000001) == 0x4000000000000000

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.oracle.graal.python;
2727

28+
import static com.oracle.graal.python.nodes.StringLiterals.J_PY_EXTENSION;
2829
import static com.oracle.graal.python.nodes.StringLiterals.T_PY_EXTENSION;
2930
import static com.oracle.graal.python.nodes.truffle.TruffleStringMigrationPythonTypes.isJavaString;
3031
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
@@ -157,6 +158,8 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
157158
public static final int RELEASE_LEVEL_FINAL = 0xF;
158159
public static final int RELEASE_LEVEL = RELEASE_LEVEL_ALPHA;
159160
public static final TruffleString RELEASE_LEVEL_STRING;
161+
public static final String FROZEN_FILENAME_PREFIX = "<frozen ";
162+
public static final String FROZEN_FILENAME_SUFFIX = ">";
160163

161164
static {
162165
switch (RELEASE_LEVEL) {
@@ -466,14 +469,24 @@ private CallTarget parseForBytecodeInterpreter(ParsingRequest request) {
466469
if (MIME_TYPE_BYTECODE.equals(source.getMimeType())) {
467470
byte[] bytes = source.getBytes().toByteArray();
468471
CodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(bytes);
472+
boolean internal = shouldMarkSourceInternal(context);
469473
// The original file path should be passed as the name
470474
if (source.getName() != null && !source.getName().isEmpty()) {
475+
String path = source.getName();
476+
if (path.startsWith(FROZEN_FILENAME_PREFIX) && path.endsWith(FROZEN_FILENAME_SUFFIX)) {
477+
String id = path.substring(FROZEN_FILENAME_PREFIX.length(), path.length() - FROZEN_FILENAME_SUFFIX.length());
478+
String fs = context.getEnv().getFileNameSeparator();
479+
path = context.getStdlibHome() + fs + id.replace(".", fs) + J_PY_EXTENSION;
480+
}
471481
try {
472-
source = Source.newBuilder(PythonLanguage.ID, context.getEnv().getPublicTruffleFile(source.getName())).name(code.name.toJavaStringUncached()).build();
473-
} catch (IOException e) {
482+
source = Source.newBuilder(PythonLanguage.ID, context.getEnv().getPublicTruffleFile(path)).name(code.name.toJavaStringUncached()).internal(internal).build();
483+
} catch (IOException | SecurityException | UnsupportedOperationException e) {
474484
// Proceed with binary source
475485
}
476486
}
487+
if (internal && !source.isInternal()) {
488+
source = Source.newBuilder(source).internal(true).build();
489+
}
477490
PBytecodeRootNode rootNode = new PBytecodeRootNode(this, code, source, null);
478491
return PythonUtils.getOrCreateCallTarget(rootNode);
479492
}
@@ -834,15 +847,17 @@ public static Source newSource(PythonContext ctxt, TruffleFile src, String name)
834847
return newSource(ctxt, Source.newBuilder(ID, src).name(name));
835848
}
836849

837-
private static Source newSource(PythonContext ctxt, SourceBuilder srcBuilder) throws IOException {
838-
boolean coreIsInitialized = ctxt.isCoreInitialized();
839-
boolean internal = !coreIsInitialized && !ctxt.getLanguage().getEngineOption(PythonOptions.ExposeInternalSources);
840-
if (internal) {
850+
private static Source newSource(PythonContext context, SourceBuilder srcBuilder) throws IOException {
851+
if (shouldMarkSourceInternal(context)) {
841852
srcBuilder.internal(true);
842853
}
843854
return srcBuilder.build();
844855
}
845856

857+
private static boolean shouldMarkSourceInternal(PythonContext ctxt) {
858+
return !ctxt.isCoreInitialized() && !ctxt.getLanguage().getEngineOption(PythonOptions.ExposeInternalSources);
859+
}
860+
846861
@Override
847862
protected void initializeMultipleContexts() {
848863
super.initializeMultipleContexts();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMAModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575

7676
import java.util.List;
7777

78-
import com.oracle.truffle.api.strings.TruffleString;
7978
import org.tukaani.xz.FilterOptions;
8079
import org.tukaani.xz.LZMA2Options;
8180
import org.tukaani.xz.XZ;
8281
import org.tukaani.xz.XZOutputStream;
8382

8483
import com.oracle.graal.python.builtins.Builtin;
8584
import com.oracle.graal.python.builtins.CoreFunctions;
85+
import com.oracle.graal.python.builtins.Python3Core;
8686
import com.oracle.graal.python.builtins.PythonBuiltins;
8787
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
8888
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
@@ -97,14 +97,14 @@
9797
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
9898
import com.oracle.graal.python.runtime.NFILZMASupport;
9999
import com.oracle.graal.python.runtime.NativeLibrary;
100-
import com.oracle.graal.python.builtins.Python3Core;
101100
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
102101
import com.oracle.truffle.api.dsl.Cached;
103102
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
104103
import com.oracle.truffle.api.dsl.NodeFactory;
105104
import com.oracle.truffle.api.dsl.Specialization;
106105
import com.oracle.truffle.api.dsl.TypeSystemReference;
107106
import com.oracle.truffle.api.frame.VirtualFrame;
107+
import com.oracle.truffle.api.strings.TruffleString;
108108

109109
@CoreFunctions(defineModule = LZMAModuleBuiltins.J__LZMA)
110110
public class LZMAModuleBuiltins extends PythonBuiltins {
@@ -200,7 +200,7 @@ public void postInitialize(Python3Core c) {
200200
long[] preset = new long[2];
201201
if (lzmaSupport.isAvailable()) {
202202
try {
203-
lzmaSupport.getMarcos(as(c, formats),
203+
lzmaSupport.getMacros(as(c, formats),
204204
as(c, checks), as(c, FILTERS),
205205
as(c, mfs), as(c, modes), as(c, preset));
206206
FORMAT_AUTO = formats[FORMAT_AUTO_INDEX];

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,19 @@ public abstract static class TrueDivNode extends PythonBinaryBuiltinNode {
519519
return divDD(x, y);
520520
}
521521

522-
@Specialization
522+
@Specialization(guards = {"fitsIntoDouble(x)", "fitsIntoDouble(y)"})
523523
double divLL(long x, long y) {
524524
return divDD(x, y);
525525
}
526526

527+
@Specialization(guards = {"!fitsIntoDouble(x) || !fitsIntoDouble(y)"})
528+
double divLLLarge(long x, long y) {
529+
if (y == 0) {
530+
throw raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
531+
}
532+
return op(PInt.longToBigInteger(x), PInt.longToBigInteger(y), getRaiseNode());
533+
}
534+
527535
double divDD(double x, double y) {
528536
if (y == 0) {
529537
throw raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
@@ -577,6 +585,10 @@ private static double op(BigInteger a, BigInteger b, PRaiseNode raiseNode) {
577585
return d;
578586
}
579587

588+
protected static boolean fitsIntoDouble(long x) {
589+
return x < (1L << 52) && x > -(1L << 52);
590+
}
591+
580592
private static boolean fitsIntoDouble(BigInteger x) {
581593
return x.bitLength() < 53;
582594
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.compiler;
4242

43-
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
44-
4543
import java.util.ArrayList;
4644
import java.util.Arrays;
4745
import java.util.HashMap;
@@ -52,7 +50,6 @@
5250
import com.oracle.graal.python.builtins.objects.code.PCode;
5351
import com.oracle.graal.python.builtins.objects.str.StringNodes;
5452
import com.oracle.graal.python.compiler.OpCodes.CollectionBits;
55-
import com.oracle.graal.python.nodes.BuiltinNames;
5653
import com.oracle.graal.python.util.PythonUtils;
5754
import com.oracle.truffle.api.strings.TruffleString;
5855

@@ -100,8 +97,6 @@ public final class CodeUnit {
10097
public final int[][] generalizeInputsMap;
10198
public final int[][] generalizeVarsMap;
10299

103-
public final boolean lambda;
104-
105100
public CodeUnit(TruffleString name, TruffleString qualname,
106101
int argCount, int kwOnlyArgCount, int positionalOnlyArgCount, int stacksize,
107102
byte[] code, byte[] linetable, int flags,
@@ -146,7 +141,6 @@ public CodeUnit(TruffleString name, TruffleString qualname,
146141
this.variableShouldUnbox = variableShouldUnbox;
147142
this.generalizeInputsMap = generalizeInputsMap;
148143
this.generalizeVarsMap = generalizeVarsMap;
149-
this.lambda = name.equalsUncached(BuiltinNames.T_LAMBDA_NAME, TS_ENCODING);
150144
}
151145

152146
OpCodes codeForBC(int bc) {
@@ -187,26 +181,6 @@ public int bciToSrcOffset(int bci) {
187181
return currentOffset;
188182
}
189183

190-
public int findMaxOffset() {
191-
int currentOffset = startOffset;
192-
int maxOffset = startOffset;
193-
194-
for (int i = 0; i < srcOffsetTable.length; i++) {
195-
byte diff = srcOffsetTable[i];
196-
int overflow = 0;
197-
while (diff == (byte) 128) {
198-
overflow += 127;
199-
diff = srcOffsetTable[++i];
200-
}
201-
if (diff < 0) {
202-
overflow = -overflow;
203-
}
204-
currentOffset += overflow + diff;
205-
maxOffset = Math.max(maxOffset, currentOffset);
206-
}
207-
return maxOffset;
208-
}
209-
210184
public boolean takesVarKeywordArgs() {
211185
return (flags & PCode.CO_VARKEYWORDS) != 0;
212186
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@ public Void visit(ExprTy.Lambda node) {
13211321
checkForbiddenArgs(node.args);
13221322
int makeFunctionFlags = collectDefaults(node.args);
13231323
enterScope("<lambda>", CompilationScope.Lambda, node, node.args);
1324+
/* Make None the first constant, so the lambda can't have a docstring. */
1325+
addObject(unit.constants, PNone.NONE);
13241326
CodeUnit code;
13251327
try {
13261328
node.body.accept(this);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/NonMappingException.java

Lines changed: 8 additions & 5 deletions
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, 2022, 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
@@ -40,21 +40,24 @@
4040
*/
4141
package com.oracle.graal.python.nodes.argument.keywords;
4242

43-
import com.oracle.graal.python.runtime.exception.PythonControlFlowException;
44-
45-
public class NonMappingException extends PythonControlFlowException {
43+
public final class NonMappingException extends RuntimeException {
4644

4745
private static final long serialVersionUID = -5215981713505181732L;
4846

4947
private final Object object;
5048

5149
public NonMappingException(Object object) {
52-
super();
50+
super(null, null);
5351
this.object = object;
5452
}
5553

5654
public Object getObject() {
5755
return object;
5856
}
5957

58+
@SuppressWarnings("sync-override")
59+
@Override
60+
public Throwable fillInStackTrace() {
61+
return this;
62+
}
6063
}

0 commit comments

Comments
 (0)